PDA

View Full Version : Changes in OpenGL 1 to OpenGL 2



marciokoko
07-17-2013, 01:32 PM
I have this old code which gives me some warnings on cocos2d v2, iOS:



//Replace the current matrix with the identity matrix
glLoadIdentity();

//Translate and rotate
glTranslatef(translation3D.x, translation3D.y, translation3D.z);
glRotatef(rotation3DAngle, rotation3DAxis.x, rotation3DAxis.y, rotation3DAxis.z);

//Bind our texture if neccessary
if(drawTextured){
glBindTexture(GL_TEXTURE_2D, texture_.name);
}

//Here we define our vertices, set our textures or colors and finally draw the cube sides
glVertexPointer(3, GL_FLOAT, 0, frontVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }
else{ ccDrawColor4B(1.0f, 0.0f, 0.0f, 1.0f); }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glVertexPointer(3, GL_FLOAT, 0, backVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }
else{ ccDrawColor4B(1.0f, 1.0f, 0.0f, 1.0f); }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glVertexPointer(3, GL_FLOAT, 0, leftVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }
else{ ccDrawColor4B(1.0f, 0.0f, 1.0f, 1.0f); }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glVertexPointer(3, GL_FLOAT, 0, rightVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }
else{ ccDrawColor4B(0.0f, 1.0f, 1.0f, 1.0f); }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glVertexPointer(3, GL_FLOAT, 0, topVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }
else{ ccDrawColor4B(0.0f, 1.0f, 0.0f, 1.0f); }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glVertexPointer(3, GL_FLOAT, 0, bottomVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }
else{ ccDrawColor4B(0.0f, 0.0f, 1.0f, 1.0f); }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

//We re-enable the default render state
//glEnableClientState(GL_COLOR_ARRAY);
//glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisable(GL_CULL_FACE);
ccDrawColor4B(1.0f, 1.0f, 1.0f, 1.0f);

The lines I get warnings on are:



glLoadIdentity();
glTranslatef(translation3D.x, translation3D.y, translation3D.z);
glRotatef(rotation3DAngle, rotation3DAxis.x, rotation3DAxis.y, rotation3DAxis.z);
glVertexPointer(3, GL_FLOAT, 0, frontVertices);
if(drawTextured){ glTexCoordPointer(2, GL_FLOAT, 0, textureCoordinates); }

where glLoadIdentity, glTranslatef, glRotatef, glVertexPointer and glTexCoordPointer are all implicit declaration functions invalid in c99.

From a previous post and my very limited openGL knowledge, this means these have been basically deprecated since and are replaced with new ones. Where could I find the new ones?

carsten neumann
07-17-2013, 01:44 PM
They haven't been removed in OpenGL 2, that only happened in OpenGL 3.3 core profile - oh, wait you are talking about iOS, do you mean OpenGL ES vs. OpenGL ES2? In that case, similarly fixed function pipeline functionality has been removed, including the built in matrix stacks; you'll have to do matrix math yourself (or use a library). You may have some success comparing cocos2d v1 against v2 sources and see how the implementation changes, but for a larger codebase you'll probably have to learn some OpenGL ES2 to get an understanding how things are done there.

marciokoko
07-17-2013, 02:02 PM
Yeah I kinda figured that from the code Ive been looking at. I was all excited cause i sorta figured out the other issue.

Thx for the help :)