PDA

View Full Version : shifting graphics



bdub
02-26-2004, 05:25 PM
i suspect that someone else has had a similar problem, but i couldn't find it, so...

i have an image viewer that draws a cursor and graphics.
when i move the cross-hair (by floating point increments) the end-points are drawn differently with respect to eachother - if there is a 1 pixel break between vertical and horizontal lines, the horizontal lines may touch the vertical lines or may not (shifts back and forth).
i understand that each point must be rounded to a pixel on the screen, but why can't they be rounded to the same relative pixels (so the cross-hair looks accurate to one pixel).
i've tried using anti-aliasing (GL_LINE_SMOOTH with GL_NICEST as the hint), but it just makes the lines thicker and they STILL shift at end points and now in thickness too!

another related problem i am having, is that when i move the imagery and graphics instead of the cursor, the graphics shift back and forth between pixels with respect to the movement of the imagery. The imagery has sub-pixel movement and looks great because the textures are using bilinear resampling.
i would really like the graphics to be tied down to the imagery -- is this possible?

i suspect that i may have an error in the values i use for gluOrtho2D for the GL_PROJECTION... i've tried a few offsets, but haven't had success.

arekkusu
02-26-2004, 05:45 PM
With regards to your first problem, if you are drawing your crosshair (or anything else, really) using GL_LINES, you should be aware that the appearance is highly dependent on your video card/driver. It might be offset 1 pixel for you and look fine on somebody else's machine.

Especially with regards to the floating point width of the line, and the floating point _length_ of the line, the implementations can be very different in how they handle the alignment and subpixel precision. Same with the antialiasing and the appearance of the endcap of the line.

You probably don't want to hear this but if you require 100% reproducible results, don't use GL_LINES. Draw a thin rectangle with GL_TRIANGLES or GL_QUAD instead.