Search code examples
c#openglrenderingpixelopentk

OpenGL rendering off by one pixel


(I realize this question is also asked here, but there were no answers that worked for me so I'm asking again in hopes that I get a working solution)

I'm using OpenGL to render a sort of data-viewing interface, and I need pixel-perfect rendering otherwise it just looks plain ugly.

The problem is on some graphics drivers OpenGL renders off by 1 pixel, in my case one to the left. Doing a translation of (0.375, 0.375) fixes it for primitives but it really badly blurs textures, and unfortunately that's unacceptable. How can I detect and/or fix the offsetted pixels without blurring textures?


Solution

  • Lines/points shade a fragment when the mathematical equation intersect a diamond inside that pixel. Polygons shade a fragment when the entire pixel is inside the polygon. Your fix is ok because no line/point falls exactly on the boundary of 2 pixels and offsets just enough so the polygons don't oscillate on a pixel boundary.

    For your texture blurriness, you can either use the NEAREST filter or negatively offset your polygons with the same value.