The way game programmers draw figures
When a game programmer uses opengl, do they draw figures using GL_NEAREST interpolation instead of GL_LINEAR when the have to have part of the image transparent (masking).
I know speed is obvious but the other not so obvious reason is the reason for this post.
OpenGL does not seem to interpolate with the background when one of the 4 pixels it interpolates with is on the image. It uses the pixels that are supposed to be transparent instead, causing a ring around the figure that should not be there.
If you have no idea what I'm talking about just give it a try and you will see. Remember you must uses GL_LINEAR interpolation not GL_NEAREST. And you must use a 32bpp texture. You also must not use a mask (maybe I should, maybe it's the solution) but instead use the alpha channel as the "mask". Use
glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_NOTEQUAL, 0);
before you draw the texture.
Is there a workaround for this annoying ring problem?
The alpha channel gets interpolated, so that gives a extra region around the model. Are you rendering billboards?
The solution is a compromise like
glAlphaFunc(GL_GREATER, 0.75);
which may give visually decent results.
The solution is a compromise like
glAlphaFunc(GL_GREATER, 0.75);
which may give visually decent results.
Linear filtering is really only useful when the destination render size is differently sized than the source texture, so if you are not doing any scaling of the sprite on-screen then using Nearest filtering might be best. It can look ugly if you have to scale, though.
GL_GREATER causes blockiness around the edges but I guess that's better than the whole image being blocky. Yes I am scaling the images on screen. I have a couple of scaling routines myself one of which is linear. I edited it so that it keeps none of the transparency color but retains the shape of the image (non-blocky). It was not hard to do. I don't know why opengl didn't do it.
Quote:GL_GREATER causes blockiness around the edges
using alphatest will only give u two results ie pass + fail.
thus u will get a staircase effect, if u want a smoother edge transition u will need to enable blending as well
use
glAlphaFunc( GL_GREATER, 0.0 );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glColor4f(1,1,1,1);
Quote:I know speed is obvious but the other not so obvious reason is the reason for this post
edit - in 3d apps the fastest method is not nearest nearest but with mipmapping enabled (with nvidia cards u can even set this in the driver settings that mipmapping is always enabled)
Blending with it does almost nothing. I looked at both images close up, there is very very very little difference.
Quote:Original post by aewarnick
Is there any way to contact the creators of opengl and ask them?
ROTFL!
I'm sure their is a better solution to your problem, like increasing the texture resolution.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement