I need OpenGL ES 1.1 to render objects with texturing and others with just vertex paints and colors simple

359 views Asked by At

I'm running on XCode and using OpenGL ES 1.1 and I have two classes one that is textured and the other one is just triangles with color data and they render fine until I render my textured triangles that work but then the others also become textured with odd parts of my sprite atlas and they dont have any texture coord's at all

-(void) renderWithUpdate {

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Translate
glTranslatef(tranlation.x, tranlation.y, tranlation.z);

//Scale
glScalef(scale.x, scale.y, scale.z);

//Rotate
glRotatef( angleGeo, 1.0, 1.0, 0.0);


angleGeo = angleGeo + 0.5;
//NSLog(@"Rotation Angle:%F", (float)angleGeo );

glVertexPointer(vertexSize, GL_FLOAT, 0, self.vertexes );
glEnableClientState(GL_VERTEX_ARRAY);
glColorPointer(4, GL_FLOAT, 0, self.colors);
glEnableClientState(GL_COLOR_ARRAY);                


//Render with Texturing 
if (materialKey != nil) {

    [[MaterialController  sharedMaterialController] bindMaterial:materialKey];

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glTexCoordPointer(2, GL_FLOAT, 0, uvCoordinates);

}


//Render
glDrawArrays( renderStyle, 0, self.vertexCount);
}

and if I disable texture corded arrays in their rendering method they vanish completly all wile my textured objets work fine

is it something to do with glEnable(GL_TEXTURE_2D)?

1

There are 1 answers

1
Christian Rau On BEST ANSWER

After rendering the textured objects you have to disable texturing by calling glDisable(GL_TEXTURE_2D) (I guess your MaterialController's bindMaterial method calls glEnable(GL_TEXTURE_2D)). Just disabling the texture coordinate array (with glDisableClientState(GL_TEXTURE_COORD_ARRAY)) is not enough (though you should do this, too, after rendering the textured geometry):

...
glDrawArrays( renderStyle, 0, self.vertexCount);

if(materialKey != nil)
{
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisable(GL_TEXTURE_2D);
}

Always keep in mind, that OpenGL is a state machine and every state you change (like enabling texturing) keeps its value until you change it again. So you should always be aware what parts of your application change what OpenGL states (like the bindMaterial method) and set every state you need immediately before rendering.