PDA

View Full Version : texture as a background



kcsin
04-07-2011, 08:19 AM
I'm trying to display a texture as a background that I can then draw on top of. I'm not sure if I should do my rendering first then put texture the background or the other way around. Regardless, I can not get my texture background to appear. This is my code :
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

gluPerspective(camfovy, aspectr, nearD, farD);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();


glClearColor(0.1, 0.1, 0.1, 0.0);
glClearDepth(1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();

eye = p;
lookat = dpoint;
updir = u;
gluLookAt(eye.x, eye.y, eye.z, lookat.x, lookat.y,lookat.z, updir.x, updir.y, updir.z);


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, imageID[0]);

// Draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f( -aspectr, -1.0f,10.f);
glTexCoord2f(0.0f, 1.0f); glVertex3f( -aspectr, 1.0f,10.f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( aspectr, 1.0f,10.f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( aspectr, -1.0f,10.f);
glEnd();

glDisable(GL_TEXTURE_2D);

Can anyone give me some insight to this?

Thanks in advance.

carsten neumann
04-07-2011, 12:45 PM
Draw the textured quad for the background first, using an orthographic projection and disable depth writes so that all your geometry is on top of the background.

kcsin
04-07-2011, 06:40 PM
Right, I can do that, but how do I keep the background in place once I call gluLookAt with a different eye, lookat and updir vectors?
I'm trying to have the texture background regardless of the changes to the modelview.

Actually I should have mentioned that if I change my eye location I can see the texture, but I don't see it as a background. Only a textured GL_QUAD off in the distance.


thanks again.

Alfonse Reinheart
04-07-2011, 07:26 PM
I'm trying to have the texture background regardless of the changes to the modelview.

Then draw it before calling gluLookAt.

kcsin
04-07-2011, 07:42 PM
Okay, thanks guys - that worked. I appreciate the help. I'm still struggling to get the hang of the switching matrix modes. I think I'm starting to get the hang of it. :)

enjoycrf
04-08-2011, 12:50 PM
hey i actually wanted to do something similar
and was asking how to do this
but today i tried something and its actually the same as rendering text
so i just copied all my code from text and just replaced the draw font with the textured quad and it worked
with this method you can have it below glulookat()
basically anywhere you want but its best to draw things like this last before you swap which is what i heard


void DrawImage(void) {

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, glutGet(GLUT_WINDOW_WIDTH), 0.0, glutGet(GLUT_WINDOW_HEIGHT), -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();


glLoadIdentity();
glDisable(GL_LIGHTING);


glColor3f(1,1,1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mark_textures[0].id);


// Draw a textured quad
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
glTexCoord2f(0, 1); glVertex3f(0, 100, 0);
glTexCoord2f(1, 1); glVertex3f(100, 100, 0);
glTexCoord2f(1, 0); glVertex3f(100, 0, 0);
glEnd();


glDisable(GL_TEXTURE_2D);
glPopMatrix();


glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);

}