PDA

View Full Version : texture filtering



Peter Maarssen
02-06-2008, 08:34 AM
I have a single (1024*1024) texture (fbo) I want to display in a orthogonal setup after rotating it a bit in the z and x direction. After which it looks ugly :D

I tried AF, but I didn't see any difference.
glBindTexture(GL_TEXTURE_2D, fboTex);
glRotatef( 45f,1f,0f,0f);
glRotatef( 20f,0f,0f,1f);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 2.0f);

How do I make the texture look better?

Zengar
02-06-2008, 08:46 AM
Try trilinear filtering (GL_LINEAR_MIPMAP_LINEAR), don't forget to build mipmaps first. Also, 2.0 is the minimal value you can specify according to the extension spec, try a higher value.

Peter Maarssen
02-06-2008, 11:35 AM
Will building mipmaps help? It is only one texture rendered on a single quad.
16.0f still looks exactly the same. How do I test if everything is going as expected?

Zengar
02-06-2008, 11:48 AM
Is it this problem? http://www.r3.nu/~cass/qcoord/

Peter Maarssen
02-06-2008, 12:05 PM
Not as far as I understand it :)

Its just that the font(thin lines) rendered on the fbo look really bad AAed after the rotations. It looks nice if it isn't rotated.

Zengar
02-06-2008, 12:32 PM
Ok, then anotehr question: what is the size of the rasterized quad? I mean, if you map the texture to a image with a smaller size, say, 500x500 pixels, you can't expect good filtering quality (this is where the mipmaps kick in -- or use a smaller FBO). There is nothign else that comes to my mind right now :)

Maybe a screenshot will help?

Peter Maarssen
02-06-2008, 01:09 PM
I map it to a quad of the same size. but the rotations make it a bit smaller in the framebuffer.

glRotatef( 45f,1f,0f,0f);
glRotatef( 20f,0f,0f,1f);
glClearColor(0.33f,0.13f,0.12f,0.0f);
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8.0f);
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2d(1f,1f); glVertex3f(1024f ,1024f ,0f);
glTexCoord2d(0f,1f); glVertex3f(0f ,1024f ,0f);
glTexCoord2d(1f,0f); glVertex3f(1024f ,0f ,0f);
glTexCoord2d(0f,0f); glVertex3f(0f ,0f ,0f);
glEnd();

should I use a mipmap for this? (any mipmap setting suggestions)

zed
02-06-2008, 01:26 PM
as others have sad try mipmapping

glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

+ if that doesnt help
post a screenshot

Peter Maarssen
02-06-2008, 01:54 PM
I'm looking into mipmapping now and here a screenshot ;)

http://img112.imageshack.us/img112/6488/fontgv1.png
(before and after rotation)

Peter Maarssen
02-06-2008, 02:16 PM
Mipmapping didn't change anything.
Maybe I got it wrong but if the size of the texture is about the size of the object (in pixels) mipmapping will not be used, or am I wrong here?

Zengar
02-06-2008, 02:51 PM
Looks like nearest filtering to me?

Peter Maarssen
02-06-2008, 03:27 PM
Did I do anything wrong here?

glGenFramebuffersEXT(1, &fbo);
glGenTextures (1, &tex);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
glTexParameteri( GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 8.0f);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);
checkFboStatus();
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

Or do you maybe know a good test program?

Peter Maarssen
02-06-2008, 04:06 PM
Yes, might be nearest as doing the same rotations on a normal texture to the framebuffer looks way better.

Should I attach anything else than the color to the fbo to make linear filtering work or something?

-NiCo-
02-07-2008, 12:50 AM
I don't think there's much you can do for such fine line textures.

e.g. suppose you have a black texture with a one pixel vertical white line. If you draw that texture to a viewport of the same size, half a pixel offset in the horizontal direction, you get a 2 pixel-wide gray line. 8 pixel height is also rather low for text don't you agree?

N.

Peter Maarssen
02-07-2008, 02:21 AM
Except for what I said: Using a normal texture iso the fbo makes the font look a lot better.
So I'm looking into the difference or maybe GL_LINEAR is not supported on fbo's :p

-NiCo-
02-07-2008, 02:41 AM
The texture you created is a normal texture. The fact that you bind it to an FBO doesn't make it less of a texture. It should behave in the same way as any normal texture as long as you don't read from and write to it in one pass.

Did you try repeating the

glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

calls right before you draw the fbotex to your screen?


N.

Peter Maarssen
02-07-2008, 03:15 AM
I found the problem ! :D

using:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1024, 1024, 0,GL_RGB, GL_INT, NULL);
iso:
//glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1024, 1024, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

This makes it look like it should (or how I expected it :)).
But also makes the fbo one big black quad as expected.
thus, the problem lies in displaying/filtering of the rgba fbo texture.

Peter Maarssen
02-07-2008, 03:51 AM
anybody know how to fix it ? :o

I expect it to have something to do with my blending or color management.

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(0.0f);
glColor4f(1.0f,1.0f,1.0f,1.0f);
glEnable(GL_TEXTURE_2D);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glAlphaFunc(GL_GREATER,0.1);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);

-NiCo-
02-07-2008, 05:10 AM
I think you would want to enable blending when drawing your text to the fbo and then disable blending when drawing the fbo to the framebuffer, no?

N.

Peter Maarssen
02-07-2008, 05:19 AM
No, if I do that then the fbo will look like one big black quad (with text on it). The background (already on the framebuffer) should be seen through.

-NiCo-
02-07-2008, 07:26 AM
Okay. If I understand correctly you're use blending to draw antialiased fonts to the FBO and then use blending again to draw the text over some background. Then you would be using the alpha values of the antialiased fonts twice? So maybe you can disable blending when drawing the text to the fbo (passthrough of font alpha values) and enable blending when merging with a background on the framebuffer (use of font alpha values)?

N.

Peter Maarssen
02-07-2008, 07:51 AM
.. must be sure... think this is it :D
Thanks.
I always thought I had to use the blend function to get the alpha values to be copied, but as I understand it now; disabling blending will still copy the alpha values?

-NiCo-
02-07-2008, 08:33 AM
disabling blending will still copy the alpha values?


Indeed :)

N.

Peter Maarssen
02-07-2008, 08:35 AM
Thanks, I knew it was something basic :D