glTexParameter()

Started by
2 comments, last by glDino 22 years, 9 months ago
Hi guys. Guess what? I need help again (as usual)! I've got a new TGA texture loading class almost up and running. I want to be able to pass an argument or two to the image loader, so that I can load textures with different filtering. I can do mipmaps (I think) with gluBuild2DMipmaps(). Question #1) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); Is the above code linear filtering, or bilinear filtering? If it is linear, how do I do bilinear? And trilinear? What is it if I replace one of them with a GL_NEAREST? Question #2) How do I filter mipmaps with some sort of linear filtering? Question #3) Please, anyone know of any good resources/example code??? I already read the texture tuts on nate.scuzzy.net and gamasutra, but they didn't answer my questions. Doing an internet search is a nightmare b/c all I get is definitions of different filerting modes, and no examples of how to do them (Makes me very angry when I'm constantly teased with screenshots showing how nice things look with various filtering, but am denied info on how to do it!!!) I would also appreciate it if no one replies with 'try www.google.com'! Again, thanks a million! Edited by - glDino on June 28, 2001 3:10:36 AM Edited by - glDino on June 28, 2001 3:12:54 AM
Advertisement
hi. I''m not 100% sure but...

1) GL_LINEAR is bilinear filtering. difference between linear filtering and bilinear filtering is bilinear filtering is a subset of linear filtering. "bi" = 2, which stands for performing the linear filtering in 2 dimensions(x and y of image coordinates)

So if you want trilinear filtering you need another dimension, which comes from mipmaps(I think). So(im not sure again) you need GL_LINEAR_MIPMAP_LINEAR for trilinear interpolation.

2) Filtering MIPMAPs? I think OpenGL already filters them. But if you want to generate your own MIPMAPs, simply lowpass filter first and then decimate. In theory your lowpass filters should be from -PI/2 to PI/2, but... simply averaging the texel with its eight neighbours(total of nine) also works fine

Also you can use some sort of weighted averaging:

to find the filtered value at i,j:

double a = 0.5; //Or a value you wish less than 1.0
double b = (1.0-a)/8.0; //dont change this

...

NewData(i, j) = a*D(i,j) + b*D(i-1, j-1) + b*D(i-1, j) + b*D(i-1, j+1) + b*D(i, j-1) + b*D(i, j+1) + b*D(i+1, j-1) + b*D(i+1, j) + b*D(i+1, j+1);

...

So there is a slight problem at the edges. You may think choosing zero for points that fall outside is a solution but it is not. You need to "average"(or weighted average) that texel value with neighbours. So above changes as:

double a = 0.5; //Or a value you wish less than 1.0
double b = (1.0-a)/Neighbours;

I hope this is what you asked for...

3) I think "red book" is the best source. Also try the man pages on the opengl website:

http://www.sun.com/software/graphics/OpenGL/manpages/index.html

Oztan.
Thanks Oztan!
In order to use mipmaps you need to set GL_TEXTURE_MIN_FILTER to one of this values:

GL_NEAREST_MIPMAP_NEAREST - nearest with mipmaping,
GL_NEAREST_MIPMAP_LINEAR - nearest & linear between mipmaps (strange beast, nobody use it(?)),
GL_LINEAR_MIPMAP_NEAREST - bilinear with mipmaping,
GL_LINEAR_MIPMAP_LINEAR - trilinear.

glTexParameter

This topic is closed to new replies.

Advertisement