PDA

View Full Version : Texture Mapping



c0d3Junk3Y
07-30-2003, 05:06 AM
I am making a screensaver, and I want to use texture mapping. I have all my basecode done, it compiles without error. The problem is that there is a blank screen displayed.

void SetupAnimation(int Width, int Height)
{
glViewport(0,0,(GLsizei)Width,(GLsizei)Height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-300, 300, -240, 240, 25, 75);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 50.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

// background
glClearColor(0.0, 0.0, 0.0, 0.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glShadeModel(GL_SMOOTH);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
}


That is my code and setup for GL. Any thoughts?

c0d3Junk3Y
07-30-2003, 07:52 AM
Is there an OpenGL forum on Irc?

starman
07-30-2003, 08:04 AM
Can you post your drawing code as well?

c0d3Junk3Y
07-30-2003, 08:15 AM
void OnTimer(HDC hDC)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
spin = spin + 1;
glPushMatrix();
glRotatef(spin, 0.0, 0.0, 1.0);
glPushMatrix();
glTranslatef(150, 0, 0);


if(bTumble)
glRotatef(spin * -3.0, 0.0, 0.0, 1.0);
else
glRotatef(spin * -1.0, 0.0, 0.0, 1.0);


float xvals[] = {-30.0, 0.0, 30.0, 0.0};
float yvals[] = {0.0, -30.0, 0.0, 30.0};
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);
for(int i=0; i < 4; i++)
glVertex2f(xvals[i],yvals[i]);


// Front

glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 1.0f); // Top right ( front )
glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 1.0f); // top left ( front )
glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f);
glEnd();

glPopMatrix();
glFinish();
SwapBuffers(hDC);
glPopMatrix();
}

c0d3Junk3Y
07-30-2003, 08:17 AM
Sorry in my cut n paste haste I nopped out the last line of my quad.

starman
07-30-2003, 08:31 AM
I don't think this will matter, but you should probably call glPopMatrix() before swapping buffers. I don't see why you should get a blank screen at first blush, but chapter 3 of the Red Book has a section at the very end called Troubleshooting Transformations, which describes several reasons why someone can get a blank screen:

http://tassadar.physics.auth.gr/~chameleon/OpenGL/The%20Red%20Book/chapter03.htm

c0d3Junk3Y
07-30-2003, 08:36 AM
Thank you starman. I greatly appreciate the help.