Sign in to follow this  
ProblemBaby

2D Problem

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this