PDA

View Full Version : creating static background



08-13-2001, 05:01 AM
I'd like to create rotating and moving 3D shape on top of some static background image/texture. I'd also like to specify position and size of that background image in screen coordinates and I don't want this position to be affected by further transformations like glRotate or glTranslate. (I hope you understand what I mean http://www.opengl.org/discussion_boards/ubb/smile.gif What is the most elegant way of doing this? Setting up glOrtho2D, then doing glDrawPixels and then setting up proper gluPerspective for my 3D shape? Or calculating proper position of background in 3D world when there are given screen X, Y, depth and video resolution? I will be thankful for help. My next question is: let's say that I want to generate that background image by program and update it each frame. What method would be faster? Doing glDrawPixels each time, or drawing a textured QUAD whose texture is being modified by glTexSubImage2D? Thank you again.

Dodger
08-13-2001, 05:22 AM
Drawing a textured quad will most likely be faster than glDrawPixels. You don't necessarily need to set up an orthographic projection to do this, you could draw your quad like this in your perspective projection:

glBegin(GL_QUADS);
glVertex3f(left, top, -near-0.0001);
glVertex3f(left, bottom, -near-0.0001);
glVertex3f(right, bottom, -near-0.0001);
glVertex3f(right, top, -near-0.0001);
glEnd();

So, draw it right about where your near clipping plane is, with the extents of your viewing volume. -near, because the 'camera' always looks down the negative z-axis, and -0.0001 to make sure it's not clipped by the near clipping plane. I haven't tested this code, but it should work.

For having it static, do this:


while(...){
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
drawQuad();
glPopMatrix();

glRotatef(...);
glTranslatef(...);
draw3DObject();

SwapBuffers();
}

In other words, make sure that the rotation for the 3d object doesn't apply to the same matrix you use for the quad.

Hope that helped http://www.opengl.org/discussion_boards/ubb/wink.gif

Platinum
08-14-2001, 07:13 PM
Originally posted by Dodger:

glBegin(GL_QUADS);
glVertex3f(left, top, -near-0.0001);
glVertex3f(left, bottom, -near-0.0001);
glVertex3f(right, bottom, -near-0.0001);
glVertex3f(right, top, -near-0.0001);
glEnd();

I think in C the '-' operator is evaluated from left to right, so '-near-0.0001' will put it just behind the clipping plane. Try '-(near-0.0001)'

08-14-2001, 10:02 PM
Thanks guys, suddenly this solution looks so obvious (haven't tried though) http://www.opengl.org/discussion_boards/ubb/smile.gif I think the first version is correct, as we want our texture BEHIND the clipping plane, not in front of it.