Pixel Perfect Images - How?
BlitzMax Forums/OpenGL Module/Pixel Perfect Images - How?
| ||
| Hello, Is it possible to create pixel perfect images in OpenGL? What I mean: - one sets a graphic mode eg: 320,200 - one creates a quad the same size as an image - one applies a texture [from this image] to the quad Somehow, I'm unable to create one. There is always some fuzzyness at the end in my image.. Some code:
Strict
Local c_width:Int = 320
Local c_height:Int = 200
GLGraphics c_width, c_height ', 16
glviewport (0,0, c_width, c_height) ' origin of avbl screen + width & height
glmatrixmode (gl_projection) ' modelview, projection or texture matrix
glloadidentity () ' set 4x4 identity matrix
gluortho2d (0, c_width, c_height, 0) ' creates a matrix for projecting 2d coordinates
glclear(gl_color_buffer_bit)
glmatrixmode (gl_modelview)
glLoadidentity ()
Local pmap:TPixmap = LoadPixmap ("mapkansas.bmp")
Local texInt:Int = GLTexFromPixmap (pmap, False)
glBindTexture (gl_texture_2d, texInt )
glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST
glTexParameteri GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST
Local w:Float = PixmapWidth (pmap) - 1
Local h:Float = PixmapHeight (pmap) - 1
glEnable (gl_texture_2d)
' glTranslatef(0.375, 0.375, 0.0)
glBegin (gl_quads)
' TL
glTexCoord2f 0.0, 0.0
glvertex2f 0.0, 0.0
' TR
glTexCoord2f 1.0, 0.0
glVertex2f w, 0.0
' BR
glTexCoord2f 1.0, 1.0
glVertex2f w, h
' BL
glTexCoord2f 0.0, 1.0
glVertex2f 0.0, h
glEnd
Flip
WaitKey()
End
It must be possible - Max2d creates them.. But how? Ghislain |
| ||
| It's something to do with mipmapping and filtering, I think. |
| ||
| Not sure but maybe making a quad from 0,0 to 320,240 is slightly too big. Should be from 0,0 to 319,239 (.. converted to float 0..1 range), it'll be 0.9 something ??? |
| ||
| I think i solved the problem.. The image size wasn't a power of 2. It seems GLTexFromPixmap creates a texture from the image which is being stretched to the correct texture-size. I expect the artefacts are created during this stretching.. The solution seems to be: - use images with a correct size, or - create a texture and copy the pixmap but don't stretch it. instead calculate new texcoords.. ghislain |