PDA

View Full Version : how to make a non smooth zoom



Sarina
05-21-2009, 11:48 AM
Hello!

I've been trying to make a zoom on openGL without smoothing the pixels, cause I need to see each pixel when I zoom in the imagem. But I still didn't have any success on this. I'm loading the image using SDL, then loading it like texture to openGL, and zooming with glTranslate(); I tried using glScale, but it still smooth the pixels. Is there any flag or function to disable the smooth on openGL?

Thx.

zed
05-21-2009, 05:18 PM
pixels?
are u talking about a texture? if so use GL_NEAREST instead of GL_LINEAR when u specify the texture_filtering

Sanctus
05-22-2009, 03:10 AM
Yes indeed that's the way to do this :)

Sarina
05-25-2009, 10:23 AM
yeah, I'm talking about texture. I'm using this:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

and it still smooth when I zoom in, is anything wrong in that?

tionxtion
05-25-2009, 11:34 AM
hi, i might be wrong cause im a noob as well.

but i did some similar non-smoothing zoom feature for my openGL videoplayer, by using LINEAR for the texture, not NEAREST (isnt it? cause linear take the pixel as it is, while nearest smooths it?), and modify the z axis of the glTranslatef, with keyboard input :)

Sarina
05-25-2009, 11:54 AM
I just tried using GL_LINEAR and it still smooth the image when I zoom in.

tionxtion
05-25-2009, 12:24 PM
im sorry i was wrong, i dont think linear is the right solution for you.
in my app, if i use nearest, then the picture is jagged, so i use linear to load the real pixel value.
btw, i found nice sample to test texture filtering parameters:
http://www.xmission.com/~nate/tutors.html
the texture tutorial program.

ZbuffeR
05-25-2009, 12:41 PM
For zoom, it is MAGnification filter you have to change :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

thekend
05-25-2009, 12:49 PM
When you sampling a texture with GL_NEAREST, it will search the nearest texel in the texture for the given texture coordinates. So, this won't be smooth. The center of the sampled pixel is represented as a red point on the image.

Using GL_LINEAR will make a linear interpolation using the four nearest texels. Each texel's weight is proportional with the area of the rectangle formed with the center of the catercorner texel and the uv point. So, this will be "smooth".

http://people.inf.elte.hu/kend/temp/filtering.png

If it's still smooth with GL_LINEAR, maybe there's some option in the nvidia or ati control center that could force linear filtering of textures.

ZbuffeR
05-25-2009, 02:37 PM
thekend, your last sentence does not makes any sense.

And the OP wants "zoom on openGL without smoothing the pixels", and that means GL_TEXTURE_MAG_FILTER, GL_NEAREST.

thekend
05-25-2009, 11:06 PM
Sorry, in the last sentence I mistyped, meant GL_NEAREST instead of GL_LINEAR.
On my NV control panel there's a Force mipmaps setting, which could be set to none, bilinear and trilinear. Of course for magnification there's no any mean of mipmaps, but I thought it could alter the filtering mode anyway. Now I tried it, and realized that it's not forced mipmaps for minification and any filtering mode for both minification and magnification. Maybe this switch is for DX applications only.

Sarina
05-26-2009, 05:11 AM
For zoom, it is MAGnification filter you have to change :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

I tried this, but it shows nothing, the image doesn't appear O.o

tionxtion
05-26-2009, 05:55 AM
texture too close to eye?

Sarina
05-26-2009, 06:05 AM
I tried zoom out and zoom in and nothing happens. I don't understand why this is happening, when I use GL_TEXTURE_MIN_FILTER, the texture appear, but when I use GL_TEXTURE_MAG_FILTER nothing appears.

Sarina
05-26-2009, 06:14 AM
Finally I got it. This worked for me:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

Thx for the help! :)