Overlay

Hi!

I would need some help. In the following piece of code, I am drawing a meadow with a house (both drawn in OpenGL) with a mill, trees, bushes and a car (3DS models, some animated). The whole scene should have an “old-movie”-effect drawn over it. It has to be done with a GL_QUAD which gets the texture that is randomly translated so it appears that the “streaks” of the texture are moving.

Now I need the GL_ALPHA_TEST for the OpenGL house (I need to see through the windows) and I used the GL_BLEND function for the overlay (so the color of the overlay-texture can be added to the color of the obejcts lying underneath).

However, now I can see the background through the overlay (when glClearColor is set to black, the overlay is dark with the streaks, when it’s grey (0.5, 0.5, 0.5) the overlay is also grey). But I simply don’t see all my modelled object through the overlay.

What I don’t understand is why I don’t see them, when in another project I could see a simple cube through the overlay and in this project I can see the background but nothing of the modelled stuff (I can’t see the OpenGL house or meadow as well as none of the 3DS modells).

Now here are the important parts of the code - if anybody has any idea what could be the problem but needs the whole code, feel free to e-mail me (marco1475@hotmail.com) and I will send them the whole project (it has 600+ lines of code).


static void init(int argc, char **argv)
{
glClearColor(0.0, 0.0, 0.0, 1.0);

glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glEnable(GL_NORMALIZE);

glAlphaFunc(GL_GEQUAL, 0.95);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

ilInit();
iluInit();
ilutInit();
ilutRenderer(ILUT_OPENGL);

}

The drawQuad()-function:


static void drawQuad(GLuint texture, GLdouble brightness, GLdouble alpha, GLdouble depth, GLdouble tiling)
{
glPushAttrib(GL_ALL_ATTRIB_BITS);
glBindTexture(GL_TEXTURE_2D, texture);
glColor4d(brightness, brightness, brightness, alpha);
glBegin(GL_QUADS);
glTexCoord2d(0.0, 0.0); glVertex3d(-1.0, -1.0, depth);
glTexCoord2d(0.0, tiling); glVertex3d(-1.0, 1.0, depth);
glTexCoord2d(tiling, tiling); glVertex3d(1.0, 1.0, depth);
glTexCoord2d(tiling, 0.0); glVertex3d(1.0, -1.0, depth);
glEnd();
glPopAttrib();
}

And last but not least the drawOverlay()-function:


static void drawOverlay(GLint texture, GLdouble depth)
{
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_NORMALIZE);

glMatrixMode(GL_TEXTURE);
glPushMatrix();
	glTranslated(GLdouble(rand()) / GLdouble(RAND_MAX), GLdouble(rand()) / GLdouble(RAND_MAX), 0.0);
	drawQuad(texture, 1.0, 1.0, depth, 1.0);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

}

Now here’s how it’s drawn (part of the display()-function:


glPushMatrix();
glScalef(2.5, 2.5, 1.0);
glDisable(GL_ALPHA_TEST);
drawOverlay(overlay_texture, 1.0);
glEnable(GL_ALPHA_TEST);
glPopMatrix();

Ok, if anyone has any idea what the problem could be, please reply or if you need the whole code, feel free to e-mail me. Thx!

[This message has been edited by marco1475 (edited 11-11-2003).]

In your drawOverlay function you call drawQuad with an alpha value of 1.0, I think this would draw the overlay completely opaque, so you should set alpha to something lower (at least with this blend function).