Triangles in a C++ STL Vector as an Objective-C member sometimes draws incorrectly in OpenGL ES

Posted by Rahil627 on Game Development See other posts from Game Development or by Rahil627
Published on 2012-05-31T10:34:12Z Indexed on 2012/05/31 10:51 UTC
Read the original article Hit count: 163

Filed under:
|

The polygons draw correctly 80% of the time. When it fails, a vertex is dislocated. The polygon is consistently drawn with the wrong vertex. I checked that the vector is correct during initialization, even when it's wrongly drawn.

I'm using Cocos2d.

The class member:

@interface Polygon : CCSprite {
  std::vector<float> triangleVertices;
}

The draw function called in [Polygon draw]:

+ (void)drawTrianglesWithVertices:(const std::vector<float> &)v
{   
    //glEnableClientState(GL_VERTEX_ARRAY);
    glDisable(GL_TEXTURE_2D);
    glDisableClientState(GL_TEXTURE_COORD_ARRAY);
    glDisableClientState(GL_COLOR_ARRAY);

    glVertexPointer(2, GL_FLOAT, 0, &v[0]);
    glDrawArrays(GL_TRIANGLES, 0, v.size());

    //glDisableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_COLOR_ARRAY);
    glEnableClientState(GL_TEXTURE_COORD_ARRAY);
    glEnable(GL_TEXTURE_2D);
}

Any ideas?

© Game Development or respective owner

Related posts about opengl-es

Related posts about cocos2d