Pixel Perfect 2D rendering?

BlitzMax Forums/OpenGL Module/Pixel Perfect 2D rendering?

EOF(Posted 2010) [#1]
Hi GLCoders,

How do I render pxiel-perfect 2D images?
Here is the original image:



This is what I am getting with my sample code (below). The pair of circles on the left are scaled to their natural size (1.0 , 1.0)
The circles over to the right are scaled at 1.5,1.5



I want to avoid all filtering and maintain a raw pixel perfect look

The code I am using is a modified version of slenkar's (credit due!)


EXAMPLE


IMPORT




_JIM(Posted 2010) [#2]
The first step in pixel-perfect rendering is to have the image be pixel-perfect in the graphics card's memory. Graphics cards always operate with power-of-two textures. If your texture is not pow2, it will scale it UP (using filtering) to the nearest pow2 texture.

I bet if your texture was 256x256 it would look sharp.

As for the second image, scaled to 150%, you will need to disable filtering. And for that, you will have to replace the GLTexFromPixmap function with a few lines of code:

Local texid:Int
glGenTextures(1, VarPtr(texid))
glBindTexture(GL_TEXTURE_2D, texid)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, pix.Width, pix.Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix.Pixels)
glBindTexture(GL_TEXTURE_2D, 0)


By default, I think GLTexFromPixmap uses GL_LINEAR as GL_TEXTURE_MIN_FILTER and GL_TEXTURE_MAX_FILTER. Using GL_NEAREST should disable filtering.

Good luck ;)


Kryzon(Posted 2010) [#3]
That's the good thing of having the module's source for tampering...

I agree with the GL_NEAREST flag - although, that won't do much difference if you don't position the quads properly in the first place.


EOF(Posted 2010) [#4]
Many thanks _JIM
Your replacement code worked straight off the bat


_JIM(Posted 2010) [#5]
Always a pleasure to help :o)