# 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 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);

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 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();

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

glMatrixMode(GL_MODELVIEW);
glPushMatrix();

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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628368
• Total Posts
2982293

• 10
• 9
• 13
• 24
• 11