Trouble with Ortho

Started by
7 comments, last by EvilProgrammer 20 years, 2 months ago
I''m trying to make a two dimensional image appear over my 3d scene. I successfully load the bitmap, then I switch to ortho mode, bind the texture, and draw a quad on the screen. Then I switch back to perspective. The problem is the quad appears all white when it goes on the screen. I have tried messing around with different things for a long time but nothing works. I checked my bitmap loading routine at several points to make sure it was successful, and it seemed to work. Anyone know what could be wrong, or anything else I should check?
Advertisement
The usual culprit in cases like this is forgetting to enable texturing.

Enigma
You mean like glEnable(GL_TEXTURE_2D) ? I''ve got that, so it must be something else.
What happens if you draw something using that texture while in perspective mode?

Enigma
Got it! I had to build mipmaps for the texture! Didn''t know I had to do that, but now it works. Thanks for the suggestion!
I''m having the same problem except I can''t get the image move at all using Ortho.

All I want to do is move the image around at the location of the mouse.

I have everything working except ortho. Did I do something wrong?


glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, abmp.W, abmp.H, 0, -1, 1);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glTranslatef(0, 0, -20);
glBegin (GL_QUADS);
glTexCoord2f (0.0f,0.0f); /* lower left corner of image */
glVertex3f (-10.0f, -10.0f, 0.0f);
glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */
glVertex3f (10.0f, -10.0f, 0.0f);
glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */
glVertex3f (10.0f, 10.0f, 0.0f);
glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */
glVertex3f (-10.0f, 10.0f, 0.0f);
glEnd ();
SwapBuffers(this->DrawDC);
To the AP:

You''re calling glOrtho with the near and far clipping planes at -1 and 1, respectively, but before you draw your quad you are calling glTranslatef with a z value of -20. This moves the coordinate system down the negative z axis (basically moving your camera away from the quad). Since you''re translating by -20 on the z axis and your far clipping plane is 1, your quad is being clipped (not drawn). Try making your far clipping plane farther away from the "camera", like 100 for example. That way you won''t be clipping your quad and you''ll be able to see it.

-noix-

In this world gone mad, we won''t spank the monkey; the monkey will spank us.
In this world gone mad, we won't spank the monkey; the monkey will spank us.
I must be doing something wrong elsewhere probably the perspective. Here is more of the code:

glViewport(0,0, 892, 672);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluPerspective(100, (GLfloat)892/(GLfloat)672, .1f, 100);	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D(-1, -1, 0, 0);	glOrtho(0, abmp.W, abmp.H, 0, -1, 100);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glTranslatef(0, 0, -1);	//glRotatef(180, 0, 0, 0);	//glRotatef(glv,glv,0,0);	glBegin(GL_QUADS);        glTexCoord2f (0.0f,0.0f); /* lower left corner of image */glVertex3f (-1.0f, -1.0f, glv);        glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */glVertex3f (1.0f, -1.0f, glv);        glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */glVertex3f (1.0f, 1.0f, glv);        glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */glVertex3f (-1.0f, 1.0f, glv);    glEnd ();	SwapBuffers(this->DrawDC); 
*C++*->
Got it working but how am I supposed to put in mouse move coordinates to move the image according to pixels on the screen?

glMatrixMode(GL_PROJECTION);	glLoadIdentity();	gluOrtho2D(2, -2, -2, 2);	//glOrtho(0, abmp.W, abmp.H, 0, -1, 100);	glMatrixMode(GL_MODELVIEW);	glLoadIdentity();	glTranslatef(0, 0, -1);	glRotatef(180, 180, 0, 0);	//glRotatef(glv,glv,0,0);	glBegin(GL_QUADS);        glTexCoord2f (0.0f,0.0f); /* lower left corner of image */glVertex3f (-1.0f, -1.0f, 0);        glTexCoord2f (1.0f, 0.0f); /* lower right corner of image */glVertex3f (1.0f, -1.0f, 0);        glTexCoord2f (1.0f, 1.0f); /* upper right corner of image */glVertex3f (1.0f, 1.0f, 0);        glTexCoord2f (0.0f, 1.0f); /* upper left corner of image */glVertex3f (-1.0f, 1.0f, 0);    glEnd ();	SwapBuffers(this->DrawDC); 
*C++*->

This topic is closed to new replies.

Advertisement