PDA

View Full Version : about polygon stipple pattern



release
11-17-2002, 10:43 PM
i have some problem:
can i create polygon stipple pattern using *.bmp?
in polygon stipple pattern
how can i fill the polygon with only ONE 32*32 bitmap?

Tom Nuydens
11-18-2002, 02:59 AM
Originally posted by release:
how can i fill the polygon with only ONE 32*32 bitmap?

You can't. Stippling is defined in screen space, so a pixel in your stipple pattern correspond exactly to a pixel on your screen.

If you want to match the pattern to polygon dimensions, create your stipple pattern as a grayscale image (8 bpp instead of 1 bpp), and upload it as a GL_ALPHA texture. Then use alpha testing to discard the black texels.

-- Tom

[This message has been edited by Tom Nuydens (edited 11-18-2002).]

Ysaneya
11-18-2002, 04:39 AM
Actually you can, but it's a bit tricky (read: only to implement if a pattern is really that needed).

Put your bitmap into a 32x32 texture, bind it before displaying your scene. Then, transform your vertices to screen space by loading the modelview matrix to the texture matrix, scale and translate the result, and use that to sample your pattern.

The advantage is, you're not restricted to grayscale patterns :)

Y.

GeLeTo
11-18-2002, 08:09 AM
You can use an eye space texgen function. Don't use any filtering on the texture. Here's some code:




GLfloat s_plane[] = { 1.0f/hsize, 0.0, 0.0, 0.0 };
GLfloat t_plane[] = {0.0, 1.0f/vsize, 0.0, 0.0 };
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glPushMatrix();
glLoadIdentity();//glTexGen plane is modified by the current matrix
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, s_plane);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, t_plane);
glPopMatrix();