Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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


Any ideas?

share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
Yes! v.size() was the culprit. Thanks. – Rahil627 May 31 '12 at 21:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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