The way game programmers draw figures

Started by
38 comments, last by wiseman303 19 years ago
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?
*C++*->
Advertisement
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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
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.
*C++*->
Is there any way to contact the creators of opengl and ask them?
*C++*->
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.
*C++*->
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.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
I don't see how that would help.
*C++*->
Do you think any of the texture combiner functions would fix this problem? Many of the are undeclared identifiers for me so I can't test things like:
GL_COMBINE_RGB and GL_COMBINE_ALPHA.
*C++*->

This topic is closed to new replies.

Advertisement