Drawing a dotted/dashed line with ccDrawPoly

Drawing a dotted/dashed line with ccDrawPoly
0.0 0



I’m trying to draw a dotted/dashed line with ccDrawPoly between 2 or more points, but all I get is a difference in color of the line. Does anyone know if there is something wrong with the code below?

pointsArray.push_back( ccp(0,0) );
pointsArray.push_back( ccp(200,200) );

int numberOfPoints = 5;

glDrawArrays(GL_LINES, 0,numperOfPoints);

ccDrawPoly(&pointsArray.at(0),pointsArray.size() , false);@


What you are trying to draw is called “strippled” lines.
Here is an article talking about it for OpenGL ES.

Unless OpenGL ES has introduced new features, the comments suggest that it isn’t trivial.


Thanks for your answer :slight_smile:

I was reading at http://www.cocos2d-iphone.org/forum/topic/4853/page/2 where someone managed to draw dotted lines. But according to your link one should use textures, so I’ll take another look in the CCRibbon class which uses a texture and glDrawArrays. Mayby I can use glDrawArrays to draw polygons without textures.

I’m quite new to OpgenGl so I was wondering why some OpenGl code is recognized by Cocos2d and some is not if I may ask :slight_smile:

For instance this statement gives errors:

@ glBegin(GL_POLYGON); glVertex3f (0.25, 0.25, 0.0); glVertex3f (0.75, 0.25, 0.0); glVertex3f (0.75, 0.75, 0.0); glVertex3f (0.25, 0.75, 0.0); glEnd(); glFlush();@


OpenGL and OpenGL ES are two different animals.


Thanks, forgot about that…

You put me in the right direction and now I think I know how to handle proper draws with glDrawArrays and pointers :slight_smile: