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.
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.
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.
I got it!
The trick is using glMatrixMode(GL_TEXTURE)
Thanks a lot!
So you want to scale the texture, and not scale the geometry.
Scaling the texture matrix is one way to do it, as you mentioned, but if you did it the 1D stipple way, then you would probably have to generate a new 1D texture that is wider (e.g. 1x16 -> 1x64), but still has the same pattern as before.
You can also generate a 1D texture with an alpha channel, so you can create dashed lines with transparent gaps when alpha blending is enabled. And you can also color them using glColor.