View Full Version : The meaning of the 0.375 pixel translation

11-17-2008, 05:07 AM
The opengl red book refers to a "magic number" 0.375

(Quote from: )
or http://msdn.microsoft.com/en-us/library/ms537007(VS.85).aspx

An optimum compromise that allows all primitives to be specified at integer positions, while still ensuring predictable rasterization, is to translate x and y by 0.375, as shown in the following code sample. Such a translation keeps polygon and pixel image edges safely away from the centers of pixels, while moving line vertices close enough to the pixel centers.

glViewport(0, 0, width, height);
glLoadIdentity( );
gluOrtho2D(0, width, 0, height);
glLoadIdentity( );
glTranslatef(0.375, 0.375, 0.0);
/* render all primitives at integer positions */

I have had a look to find out what the magic number "0.375" actually is.

After a lot of searching, the only suggestion that I can think of is that it has something to do with floating point to integer rounding errors.

Does anyone know why it is 0.375? (and not 0.374 or 0.376 etc)

11-17-2008, 06:50 AM
0.250 + 0.125

11-17-2008, 10:36 AM
It's explained right there in the first sentence-- it's a compromise, not a correct solution.

A correct solution is to specify points and lines on pixel centers, so you should bias by 0.5, 0.5. Filled primitives like triangles should not be biased at all. This means you need to shift your geometry or a matrix around, depending on the primitive type you're drawing. The compromise avoids that, at the cost of slightly offset rendering (which is more visible if you use any form of antialiasing.)

11-18-2008, 12:08 AM
Thank you very much, that makes sense.