# Pixel accuracy

This topic is 4063 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello, I'm having problems with pixel accuracy in glOrtho view (rendering isometric levels). I've heard that I should render my quads vertices in the pixels center. Where is that? :S The corners are not even in this example:
I've tried added +0.25f and +0.5f to my locations but it just shifts my problem. Help much appreciated.

##### Share on other sites
Well that really depends on how your view and projection matrices are set up. What world coordinates corresponds exactly to pixel centers is almost impossible to find out, because of precision errors and so on. If GL has a way of letting you specify coordinates directly in screen coordinates, or if you create a special matrix to allow you to do that, you could always use that instead.
But well... does it really look like what you show, or have you magnified it?

##### Share on other sites
It isnt impossible :) I do it all the time. At least i cant see any artefacts in my apps.

Heres a good article on the subject.

The article uses DirectX and pretransformed vertices, but the concept is (should be) the same for OpenGl. Basically you offset your transformed vertices by (-0.5, 0.5). What this represents in model space coordinates depends on your implementation. Also, if your panning, remember to only pan to integer pixel locations.

Hope it helps.

Emil Jonsson

##### Share on other sites
Quote:
 Original post by cannonicusThe article uses DirectX and pretransformed vertices

Exactly, pretransformed vertices, or a matrix that allows you to input coordinates in screen-coordinates is what is needed. To use a regular view-matrix along with a perspective or ortho projection matrix, and using the inverse of those to figure it out is a different matter though, and unlikely to succeed when you want exact pixel centers. Which is why i mentioned pretransformed vertices or a modified matrix :)

##### Share on other sites
Thanks for the replies. The picture is enlarged 300% just to show the problem more clearly. My ortho view is set up like this:

glMatrixMode(GL_PROJECTION);glLoadIdentity();	glOrtho(-width/2, width/2, -height/2, height/2, -1000, 1000);glRotated(-60, 1, 0, 0);glRotated(45, 0, 0, 1);glMatrixMode(GL_MODELVIEW);glLoadIdentity();

I'm going to try to set up the polygon using two triangles instead. Then I might be able to get the corners I want.

##### Share on other sites
Nope triangles didn't help :(

cannonicus: I have padded the coords with 0.5 in previous projects but that has always been in gluOrtho2D (no near and far clip plane). I tried that now also, but it didn't help :(

There must be something that can be done to get better accuracy. [crying] Advice appreciated...

[Edited by - O-san on May 4, 2007 11:35:12 AM]

##### Share on other sites
Do you need to use 3D coordinates? In that case it will be tricky. Does this issue really do something bad, like give glitches or cracks? Or have you just become obsessed with having 1 pixel corners? What if you raise the resolution? Is there some way of raising rendering resolution in GL, to have it properly perform sub-pixel rasterization? Could turn turn on MSAA to make it look more correct?
Adjusting by 0.5 in world-space won't work, that is for mapping texels correctly. What you could do is modify the coordinates in the vertex-shader, possibly, but you have to keep in mind that you'll have the screen coordinates in the range of 0..1 (or is it -1..1 in GL?).

##### Share on other sites
Unfourtunatly I'm not obsessed about pixel accuracy ;) I'm rendering 2D pre-rendred images onto 3D cubes to take advantage of the Z-buffer (no need to sort my 2d-objects anymore). I've placed the texture-coords and aligned them to the camera so it matches my isometric view I used when I created the 2D image. Did that make sense?

Anyway.. if the vertex coords are badly aligned the 2d graphics becomes distorted and a bit uglier. Maybe I have to live with that, but I rather don't.

##### Share on other sites
Well you shouldn't have to live with that, I've done the same thing a number of times. Look into supplying the coordinates in screen-space instead, you should be able to create matrices that allows you to do that and still end up with the correct data in the depthbuffer.

• 18
• 11
• 16
• 9
• 50
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999783
×