Jump to content
  • Advertisement

Archived

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

Subotron

What's the coord for top-left in the screen with glTranslatef(x.xf, x.xf, x.xf)

This topic is 5931 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

Ok, I figured out if I make the third parameter of glTranslatef 10 times bigger, the first and second parameter will also need to increase 10 times to get the same starting position on the screen I guessed the first parameter would be -500.0f when the third parameter is 1000.0f to let the shape be drawn at the most left point on the screen, but this is not true. If I draw a quad on glTranslatef(-500.0f, 500.0f, 1000.0f); it doesn''t show up in the upper left corner. Does anyone know the exact coords to get to the top and left of the screen? I need these values so I can calculate how to center items, etc. Thanx in advance
''Qui habet aures audiendi audiat'' - Me A link to the website of my 3D engine will follow as soon as I have something concrete to show... Which will be soon.

Share this post


Link to post
Share on other sites
Advertisement
You need to set up an orthographic projection matrix to draw 2d stuff. It isn''t _completely_ necessary, but that way you can avoid these z-axis calculations you mention, where you also have to tkae account for the fact that objects get "squished" as you approach the border of the screen.

So if you want to render a 3d scene with a hud for example, you could do it like this:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw 3d stuff here

// you can disable depth testing here as it usually isn''t needed for drawing 2d stuff
glDisable(GL_DEPTH_TEST);

glMatrixMode(GL_PROJECTION);
glPushMatrix();

glLoadIdentity();
glOrtho(0.0, 640.0, 0.0, 480.0, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// draw 2d stuff here (the bottom-left corner of the screen is (0,0), the upper right corner is (640,480))

glMatrixMode(GL_PROJECTION);
glPopMatrix();

// enable depth testing again if you''ve turned it off
glEnable(GL_DEPTH_TEST);

Share this post


Link to post
Share on other sites
I see. I never knew about the squishing... I had seen ortho views before in a NeHe tutorial but never really used them...

Only problem is it might give problems when I change the resolution... text may be placed wrong that way... oh well I guess I can calculate the good points using the current screenwidth and height... so I should be able to overcome that problem



''Qui habet aures audiendi audiat'' - Me

A link to the website of my 3D engine will follow as soon as I have something concrete to show... Which will be soon.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!