Archived

This topic is now archived and is closed to further replies.

Trouble with Ortho

This topic is 5370 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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?

Share on other sites
The usual culprit in cases like this is forgetting to enable texturing.

Enigma

Share on other sites
You mean like glEnable(GL_TEXTURE_2D) ? I''ve got that, so it must be something else.

Share on other sites
What happens if you draw something using that texture while in perspective mode?

Enigma

Share on other sites
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!

Share on other sites
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);
glOrtho(0, abmp.W, abmp.H, 0, -1, 1);

glMatrixMode(GL_MODELVIEW);

glTranslatef(0, 0, -20);
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);

Share on other sites
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.

Share on other sites
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);

Share on other sites
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);

1. 1
Rutin
44
2. 2
3. 3
4. 4
5. 5

• 11
• 9
• 12
• 10
• 13
• Forum Statistics

• Total Topics
632984
• Total Posts
3009715
• Who's Online (See full list)

There are no registered users currently online

×