You have a problem with vertex coordinates vs pixel coordinates.
You use the projection matrix to setup an orthographic projection, with lower left corner at (0,0), and upper left corner at (640, 480). But take a look at this picture. The coordinate (0,0) does not correspond to the center of the lower left pixel, but the corner of that pixel
| | | | |4 ------------------- | | | | |3 ------------------- | | | | |2 ------------------- | x | x | | |1 ------------------- | x | x | | |0 ------------------- 0 1 2 3 4x = center of pixel
As you can see, with cooridnate (1, 1), you don''t hit the pixel with coordinate (1, 1), but the corner between the four pixels marked as ''x''. Which one of these pixels are chosen?
The problem you have, is that you think you hit the pixel with coordinate (19, 19), but infact you hit the corner of the four pixels (18, 18), (18, 19), (19, 18) and (19, 19). In this case, OpenGL happen to choose the wrong pixel. That is, the wrong pixels in your eyes.
To solve the problem with pixel coordinates, you need to offset the coordinates by one half. Well, if you offset the cooridnates by one half, other pixel operations will hit corners instead of the center, so you should offset by 0.375.
I sugegst you use the following for direct vertex coordinate to pixel coordinate mapping.
glViewport( 0, 0, 640, 480 );glMatrixMode( GL_PROJECTION );glLoadIdentity();gluOrtho2D(0.0, 640.0, 0.0, 480.0);glMatrixMode( GL_MODELVIEW );glTranslatef(0.375, 0.375, 0);