PDA

View Full Version : Blurred textures - need it sharp



SenSej
12-20-2008, 01:06 PM
Hi,

With my c++ app you are allowed to load images as a texture of arbitrary size. The quad I want to texture is a lot bigger than the texture or is shown a lot bigger, but has same xsize/ysize ratio.
While mapping the texture to the quad, it getīs blurred, but i need the image shown really sharp.

These are no real images. Just some bitmaps holding area information represented by different colors - like a chessboard, with exact edges between different colors.

My way:
-load image (eg 50x05px)
-get its ratio
-draw a quad with same ratio (1,1)(-1,1)(-1,-1)(1,-1)
-texture it
-render it in adjustable display window e.g. 500x500
-> blurred

Any ideas?
Thanx a lot in advance

Zengar
12-20-2008, 02:13 PM
The easiest way to avoid the blur wuld be rescalng the texture to match the display size. If the edges are clearly detectible, it won't be difficult to write a function that does it.

If your image is really like chesboard, that is, it can be subdivided in uniformly-coloured rectangles of the same size, then you can also encode the image with every texel representing such rectangle and then use a shader to reproduce the final image.

ZbuffeR
12-20-2008, 03:15 PM
Just disable bilinear filtering :
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

Zengar
12-20-2008, 03:26 PM
True, I haven't thought of that :D

SenSej
12-29-2008, 07:00 AM
Thanks a lot again, ZbuffeR and Zenga - again, what iīve searched. - Problem solved by disabling bilinear filtering.

SenSej
01-10-2009, 05:35 AM
Hello Again,
I found the problem as solved, but with very tiny pictures it wontīt work.

In bmp format i made a 1x5 pixel image, 24bit color depth, and 96dpi hoizintal and vetical resolution. Index 0..4 as usual I set manually the
1)
pixelcolor at (0,2) to yellow:
white-white-yello-white-white

My app is parsing this image befor it get loaded as texture. Each white pixel get alpha = 0.

When showing it nor any color, neither yellow is displayed.

2) picer i set up with
blue-blue-blue-blue-red
parse ist again
It gets blue, at one corner blurred red where it should be, BUT also on opposit side but just the edge?!

Here my init-stuff:
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glEnable(GL_TEXTURE_2D);
glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); // Thought this shout enable the interpolation??
glEnable(GL_COLOR_MATERIAL);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

What can i do?? I have no clue. do you need some more Infos?
BTW: The tiny images are just for testing reason and iīm still using Qt with QtGlWidget - Iīm still checkt this out, if ther comes the interpolation. Nothing found jet.

Thanx

ZbuffeR
01-10-2009, 02:01 PM
Add also this :
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

There are separate setting for enlarged and reduced textures, look up the documentation :
http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml