Jump to content
  • Advertisement
Sign in to follow this  
ProblemBaby

2D Problem

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

Hi Ive set up the view like this: glViewport(0, 0, ClientRect.right, ClientRect.bottom); glOrtho(0, ClientRect.right, ClientRect.bottom, 0, -1, 1); When I draw everything (Note, except quads) Ive to translate it like this glTranslatef(0, 1.0f/(scaleY), 0); else the first line isnt displayed, because everything is translated up one unit. I can't understand why it is like that. The fact that this isnt the case for QUADS is very strange I think. Any ideas? Thanks in advance

Share this post


Link to post
Share on other sites
Advertisement

Quote:

glViewport(0, 0, ClientRect.right, ClientRect.bottom);
glOrtho(0, ClientRect.right, ClientRect.bottom, 0, -1, 1);


It looks to me that you may have your viewport sizes and your desired viewing volume dimentions mixed up.

I assume that you use CLientRect.bottom as the height of your viewport because these coordinates are stored in the ClientRect struct/class with the top-left as 0,0.

You then use ClientRect.bottom to specify the bottom value for glOrtho. Remember though that the default opengl coordinates system has the y-axis pointing up. Normally the bottom value would be less than the top value and since you have ClientRect.bottom as positive maybe you wanted:

glOrtho(0.0, ClientRect.right, 0.0, ClientRect.bottom, -1.0, 1.0);


Additional things to check for:

1. Have you remembered to make a call to glMatrixMode(GL_PROJECTION) before glOrtho(...)?
2. Have you remembered to make a call to glMatrixMode (GL_MODELVIEW) before drawing?

Post more code (drawing + viewing) if this hasn't helped.

Share this post


Link to post
Share on other sites
this is the whole setup code:

RECT ClientRect;
GetClientRect(hWnd, &ClientRect);

wglMakeCurrent(hDC, hRC);

glViewport(0, 0, ClientRect.right, ClientRect.bottom);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();

glOrtho(0, ClientRect.right, ClientRect.bottom, 0, -1, 1);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

If I do like this:
glOrtho(0, ClientRect.right, 0, ClientRect.bottom, -1, 1);
everything wents upside down but the problem is solved.
But is there another way to flip it back. so 0,0 is upper-left
and not lower-left.



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!