0
\$\begingroup\$

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?

\$\endgroup\$
2
\$\begingroup\$

If your vector is a vector of floats, where each consecutive pair of floats represents a single vertex, as suggested by your glVertexPointer call, then it should surely be v.size()/2 in glDrawArrays, but I'm not that sure this would cause your error, otherwise some more information and code would be required.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.