Question on pattern-fill drawing for polygons.

I’m wanting to rewrite an old game called PowerMonger in OpenGL. Just for nostalgia, really,

Anyway, I don’t want to use regular texture mapping. I want to fill each polygon with a particular pattern, just like in the original game.

I’ve looked into the documentation and found glPolygonStipple, but this isn’t really suitable as it only supports 1-bit masking patterns.

Is the only alternative to use shaders? Or is there some way I can keep it compatible with regular OpenGL functionality?

Perhaps use environment mapping with a projection from the camera viewpoint?

You should do a texgen in eye space linear to produce texture effects like this.

You’ll probably also need to load a glFrustum on the texture matrix to project from the eye if it’s truly a screenspace texture operation.

dorbie: Thanks, using GL_EYE_LINEAR in glTexGeni() certainly seems to do the trick!

I found an example called texgen in the OpenGL Guidebook which does this to the glutSolidTeaPot object.

Cheers. :slight_smile:

Oh, I’ve just realised that the effect only works when using an Orthogonal camera. :frowning:

Is this what you were meaning by the glFrustum call?

// in the main draw function
glMatrixMode(GL_TEXTURE); 
glLoadIdentity();
glOrtho(-10, 10, -10, 10, 0, 100); 

glMatrixMode(GL_PROJECTION);  
glLoadIdentity();
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 1000.0f);   

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// and then draw the actual geometry.

The texture is correctly projected in screenspace (e.g., remains static as the landscape rotates) but is still distorted by perspective depth. :confused:

This is why I suggested putting a projective glFrustum call (gluProjection) on the texture matrix.

You need to texgen r along eye z and make the texture frustum match the one on your projection matrix.

That should do the trick.