Jump to content
  • Advertisement

Archived

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

EvilProgrammer

Trouble with Ortho

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
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);

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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);

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!