glLineStipple problem

Hi,

I am having trouble with glLineStipple. The red book section on it is very brief. When I try to stipple a line, it is not drawn at all. If it is solid then it is fine.

this is what I have…

if (m_style == STIPPLED)
{
glLineStipple(1,0x1C47);
glEnable(GL_LINE_STIPPLE);
}

glBegin(GL_LINE_STRIP);

glEnd();

glDisable(GL_LINE_STIPPLE);

can anyone point me in the right direction?

Thanks

matthew

Is m_style ever equal to STIPPLED?

of course!!! I should have mentioned that everything is being called as it should be, just that when m_style is set to STIPPLED, the glLineStipple() command seems to cause the line to to be drawn at all (or the resulting line is invisible)

Matthew

Oh well, just a wild guess

Joke aside, with the code you gave, that was the only “problem” I saw. If the entire code isn’t too large (~200 lines or less), post it here. Otherwise, you can send it to me, and I have a look at it. You find my address in my profile. Might be a driver problem. What card do you have?

the graphics adapter is a GForce 2 nVidia thingy. How important is the hardware? Are you saying that dependent on the hardware I may or may not be able to stipple lines?

In that case, I’ve noted that it’s possible to render a line as a 1D texture. I think I’m ok with clamping the texture to a line, but how do I generate the texture of a dashed line?

Matthew

I just thoguth that if you had an old/bad graphics board or something, you might have some buggy drivers that can’t handle line stipple correct. I have a GF2 myself, and I can ensure you that there’s nothing wrong with line stipple on that one.

To generate a 1D dashes texture, you can do something like this. It will be a “16-bit pattern”.

unsigned char *tex = new unsigned char[16];

for(int i = 0; i < 16; ++i)
{
if(pixel i should be set)
tex[0] = 0xFF;
else
tex[0] = 0x00;
}
glTexImage1D(GL_TEXTURE_1D, 0, GL_ALPHA, 16, 0, GL_UNSIGNED BYTE, tex);

All you have to do is to decide whethe the pixel should be set or not. To get every four pixel to be set, try

if(i & (1 << 3))

That should create a 1D texture you can use for line stipple. Bind the texture and set texture coordinates for the line. Alpha test can be used to reject the “invisible” parts of the line.

glAlphaTest(GL_EQUAL, 1);
glEnable(GL_ALPHA_TEST);

[This message has been edited by Bob (edited 12-21-2001).]

Wow, thanks for that. It’ll have to wait until new year now when I’m back at work.

Thanks for that

Matthew