PDA

View Full Version : Imaged background



drumdummy
05-21-2001, 11:31 AM
I've been trying to find sample code on displaying an image to the background.

Havent had any luck, so pls provide either info or source code on how to do this... would be greatly appreciated.


I've been considering creating a rectangle and throughing it back in the -z axis, but then the image would be too small...hence textures req a smaller size. I need to display this background image in a 1152 x 900 resolution. After this is done I'l be able to display additional images over this background and allow animation of these objects.

Thanks in advance

zed
05-21-2001, 12:22 PM
check the faq http://www.frii.com/~martz/oglfaq/ question 9.09

bsimser
05-21-2001, 12:31 PM
Basically this is how I do it and it works well.

variables needed:

// Window size (GLdouble)
w = width
h = height

// Texture ID of the texture you want to draw
nTextureID

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(0, w, 0, h);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);

glDisable(GL_DITHER);
glShadeModel(GL_FLAT);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, m_nTextureID);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

glBegin(GL_QUADS);
GLfloat fw = (GLfloat) w;
GLfloat fh = (GLfloat) h;
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( fw, fh, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(0, fh, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(0, 0, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( fw, 0, 0.0f);
glEnd();
glDisable(GL_TEXTURE_2D);

glMatrixMode(GL_PROJECTION);
glPopMatrix();

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

glPopAttrib();

Hope that helps.

liB

drumdummy
05-22-2001, 05:03 AM
Using the above code, I only receive a white screen.

Here's a snippet of what I have, perhaps you could tell me what I've done wrong.

Perhaps I should change the size of the bitmap into mulitples of 2??

*disregard. Shrunk the image down to 256x256 and it now displays in the background. Now I just need to tweak it a bit because it has become distorted.

Thanks for the code. Now I need to analize it to understand the functionality.

[This message has been edited by drumdummy (edited 05-22-2001).]