Dashed lines in Openframeworks

Is it possible to draw dashed lines or dotted lines in Visual Studio 2015 using Openframeworks?!
Thanks in advance!

Yes, it is possible!

ofDrawLine(float x1, float y1, float x2, float y2) can be used to draw a line from (x1,y1) to (x2,y2). Drawing many lines with separations between them will render a dashed line

First of all thanks for your reply. I thought about your suggestion already, but its a lot of work. I have to draw 5-6 very long dotted lines to indicate them as centre lines, so i was looking for a direct command.

Maybe check out this then! http://stackoverflow.com/a/5321262/1890362

Dotted or dashed line in OpenGL is called stippled.

glPushAttrib(GL_ENABLE_BIT); 
# glPushAttrib is done to return everything to normal after drawing
glLineStipple(1, 0xAAAA);  # [1]
glEnable(GL_LINE_STIPPLE);
glBegin(GL_LINES);
glVertex3f(-.5,.5,-.5);
glVertex3f(.5,.5,-.5);
glEnd();
glPopAttrib();

0xAAAA is the parameter you want to experiment with.

2 Likes

Thanks for the link. It resolved my issue. I can draw dashed lines with the following code snippet:

ofPushMatrix();
ofTranslate(300, 300);

/* select white for all lines  */
glColor3f (1.0, 1.0, 1.0);

glEnable (GL_LINE_STIPPLE);

glLineStipple (4, 0xAAAA);  /*  first parameter set the dash length in px  */
glBegin(GL_LINES);
glVertex2f (0.0, 0.); /* starting points */
glVertex2f (250.0, 0.); /* end points */
glEnd();
glDisable (GL_LINE_STIPPLE);
glFlush ();

ofPopMatrix();
3 Likes