cela lee Drawing a dotted/dashed line with ccDrawPoly
Posts 6
Added by cela lee about 1 year ago

Hello,

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);@

Kevin H RE: Drawing a dotted/dashed line with ccDrawPoly
Posts 70
Added by Kevin H about 1 year ago

What you are trying to draw is called "strippled" lines.
Here is an article talking about it for OpenGL ES.
http://stackoverflow.com/questions/1937444/drawing-stippled-lines-using-opengl-es
Unless OpenGL ES has introduced new features, the comments suggest that it isn't trivial.

cela lee RE: Drawing a dotted/dashed line with ccDrawPoly
Posts 6
Added by cela lee about 1 year ago

Thanks for your answer :)

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 :)

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();
@

Kevin H RE: Drawing a dotted/dashed line with ccDrawPoly
Posts 70
Added by Kevin H about 1 year ago

OpenGL and OpenGL ES are two different animals.

cela lee RE: Drawing a dotted/dashed line with ccDrawPoly
Posts 6
Added by cela lee about 1 year ago

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 :)


(1-4/4)