how to make a non smooth zoom

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.

pixels?
are u talking about a texture? if so use GL_NEAREST instead of GL_LINEAR when u specify the texture_filtering

Yes indeed that’s the way to do this :slight_smile:

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?

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 :slight_smile:

I just tried using GL_LINEAR and it still smooth the image when I zoom in.

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.

For zoom, it is MAGnification filter you have to change :
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

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”.

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.

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.

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.

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

texture too close to eye?

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.

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! :slight_smile: