PDA

View Full Version : Opengl Fundamental alignment problem



glBomb
02-13-2007, 05:59 AM
http://img184.imageshack.us/img184/9649/upld2cm4.png (http://imageshack.us)

Hi people
I tried to draw a simple quad from (-3,-4) to (0,0) using the commands below:

glBegin();
glVertex2i(-3,-4);//Top left
glVertex2i(0,-4);//Top right
glVertex2i(0,0);//Bottom right
glVertex2i(-3,0);//Bottom left
glEnd();

and i got the output in the left picture.The blue pixel is the origin.The yellow pixels are the pixels where i expected the quad boundary to be.And the red pixels are the actual output.What i cant get is if i want the upper left corner of the quad at(-3,-4) why is it ending up at (-3,-3)?
Also the bottom is not at the origin.there is a problem with the y-direction here

Then i tried positive numbers as:

glBegin();
glVertex2i(0,0);//Top left
glVertex2i(0,3);//Top right
glVertex2i(3,4);//Bottom right
glVertex2i(0,4);//Bottom left
glEnd();

Now i get the output at the right.Now there is a problem with the x-direction !!
Is there some convention regarding the drawing of quads in opengl ? That the boundary pixels will not be drawn?

Thanks...

arekkusu
02-13-2007, 07:45 AM
Google rasterization fill convention.

Bruce Merry
02-14-2007, 04:20 AM
Don't confuse pixels with points. A pixel is a little rectangle, so claiming that the blue rectangle is the origin is meaningless (the origin is the bottom-left corner of the blue rectangle).

In OpenGL, integer window coordinates correspond to the corners of pixels; (0, 0) is the bottom-left corner of your screen (DirectX is weird and so (-0.5, -0.5) is the bottom-left corner).

Bob
02-14-2007, 06:36 AM
As other mentioned, you need to get familliar with OpenGL's rasterization rules.

The result looks correct to me though. Assuming those grid white lines are on integer coordinates (that is, spacing is 1 unit), it looks like it should.

The quad is 3x4 units large (from (0,0) to (3,4)) and it covers 3x4 pixels. Just as it should, since each pixel corresponds to 1 unit. It also connects the yellow pixels correct and in a consistent way. The quad is rasterized such that is touches the lower left corner of each desired yellow pixel.