I’m trying to draw a 1-pixel wide wireframe rectangle in Ortho projection,
but I am always missing a corner pixel.
I’ve tried using different methods, like GL_LINES, GL_LINE_STRIP, and
GL_LINE_LOOP, but they always miss a corner pixel.
Is there something I have to enable to get this?
I believe you use the common way to setup the projection matrix to match the size of the viewport. That is, if the window is X pixels wide, you make the view volume X units wide. This method has a problem. The coordinate (0,0) represents the lower left corner of the view volume (or upper left if you prefer, but that is irrelevant). But, the corner of the view volume is located at the corner of a pixel, not the center of the pixel. Pixel centers are located on integer plus one half cooridnates, corners betwen four pixels are located on integer coordinates. Because you hit the corner between four pixels, and one pixel have to be choosen, I believe wrong pixels is choosen which leaves you with, as you see it, a missing pixel.
To deal with this problem, offset the coordinates you pass to glOrtho/gluOrtho2D by -0.5, either by placing a glTranslate after or manually subtracting 0.5.
Thanks for the tip! That did the job.
[This message has been edited by gator (edited 02-08-2003).]