View Full Version : Thick dashed lines

06-04-2013, 04:57 AM

I'm writing a function that draws thick dashed lines with OpenGL. After great efforts I have ensured that the geometry of the texture suits well to the line (drawn with triangle strips).

However, I find no way to change how often the texture is repeated. The texture (see the attached image) is 4 pixels wide by 8 high. I want each pixel to be displayed wider so that the line look better.

Any idea?
Thank you!

06-04-2013, 09:41 AM
I'm not sure what you specifically want, but the repeat factor would probably be the line length divided by the stipple length.

If you want to emulate OpenGL's glLineStipple for thick lines, then they use a 16-bit pattern.
You can generate a 1D texture for your stipple texture, and map it onto your line geometry using the repeat factor as texture coordinates.

I'm sure if you Google for "1D texture" and "stipple" you'll find a better explanation of it.

06-04-2013, 12:13 PM
Thanks, sevenfold, for your answer. I'll explain myself better: I need very thick lines, so I cannot use glLineWidth nor stippling. Therefore, I build the tri-strip geometry and I render it mapping a texture onto it. I also need dashed lines (as you can see in the attached picture to my 1st post). My approach is to use a 2D texture with "holes" (one of two colors has alpha zero).

The first problem is calculating the texture mapping that is to be applied using glTexCoord2f(). This problem is solved, as you can see in the picture.

The second problem: take a look to the picture attached to this post: I'm getting the four colour texture as in the right segment; I'd like to stretch it as in the left one. So it seems I should instruct OpenGL to "widen" (excuse my poor english) or stretch the texture along the tri-strip.

Thanks again!


06-04-2013, 01:52 PM
I got it!

The trick is using glMatrixMode(GL_TEXTURE)

Thanks a lot!