开发者

Help to draw a dashed line in OpenGl

I am trying to draw a dashed line in OpenGl using a texture equally spaced along the path开发者_开发百科 as the dashes. I can get a solid line, but that wont work for this project. Could someone help point me in the right direction?


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.

(Sourced from here)


The best way would be to use glBegin(GL_POINTS); and spread out the points in a linear fashion.


A dashed line is just a series of colinear line segments with gaps in between. If you want texturing, you can emit a bunch of quads. You can control the texture coordinates so that each dash is a piece of the texture, or each dash encompasses the whole texture, or any other repetition pattern you like.

What have you tried so far? Show the code that's not working and the output graphic it creates. Then explain what you want to be different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜