Offset for 2D-paintings

Hello all,

I created a window which is 600x400 pixels. I checked the size with another tool, the size is correct.
I use OpenGL and minGW on Windows XP

Now I want to paint a red frame around this window with this code

glViewport(0, 0, 600, 400); // x, y, w, h

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 599, // left/right
0, 399, // bottom/top
1, -1); // near/far

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_LOOP);
glVertex2d(0, 0);
glVertex2d(599, 0);
glVertex2d(599, 399);
glVertex2d(0, 399);
glEnd();

Unfortunately the frame has a y-offset by 1 pixel, that mean the upper line is outside the window and the bottom line is 1 pixel above the lower window bottom.
Where does this offset come from?
Did I a mistake and what must I that the coordinates of the win32-window matches the OpenGL-coordinates (of course the top of OpenGL is the bottom of the Win32-window)

Thanks again for your help :slight_smile:

You should draw lines from/to pixel centers, eg. glVertex2d(0.5, 0.5) instead of 0, 0. Have a look at figure 3.4:

http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html

A diamond shaped region of height 1 is placed around each fragment center; those regions that the line segment exits cause rasterization to produce corresponding fragments.