I’m trying to draw a simple box in my iPhone game.
Here is the code that renders the box:
- (void)render {
const SHAPE_TYPE * shape = dynamic_cast<SHAPE_TYPE *>(fixture->GetShape());
if (!shape)
return;
GLfloat vertices[shape->m_vertexCount][2];
for (int i = 0; i < shape->m_vertexCount; ++i) {
vertices[i][0] = shape->m_vertices[i].x;
vertices[i][1] = shape->m_vertices[i].y;
}
glPushMatrix();
glLoadIdentity();
CHECK_GL_ERROR();
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
CHECK_GL_ERROR();
glDisableClientState(GL_COLOR_ARRAY);
CHECK_GL_ERROR();
glEnableClientState(GL_VERTEX_ARRAY);
CHECK_GL_ERROR();
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_LINE_LOOP, 0, (GLsizei)shape->m_vertexCount);
glDisableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glPopMatrix();
CHECK_GL_ERROR();
}
I get an error on the second CHECK_GL_ERROR
The error is OpenGL error 0x0502 in -[MyApp render] 97
I have no opengl setup besides what you see.
I think it has something to do with some state that cocos2d enables, no idea which one though.
Try using ccDrawPoly:
Also, just in case you’re on cocos2d 2.0 keep in mind that you’d have to write OpenGL ES 2.0 code. The code you posted will not work without OpenGL errors in cocos2d 2.0.