View Full Version : Setting Alpha to 1.0 in a Texture

07-17-2003, 10:50 PM
I'm trying to write a Sprite Engine using OpenGL. One major feature I've been working on is being able to "blit" a portion of the "screen" (i.e. Frame Buffer) to a stored "Image" (i.e. Texture Region). This is perfectly fine, except for the fact that when copying pixels from the screen using glCopyTexSubImage2D, It also copies the Alpha pixels of the screen. This is especially annoying when I've drawn alpha blended polys on the screen, since the alphas of those pixels are equal to the alpha values of the polygon (since I'm using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)).

I've tried the obvious solution, which is wrapping the glCopyTexSubImage2D class with glPixelTransferf(GL_ALPHA_BIAS, 1.0)/glPixelTransferf(GL_ALPHA_BIAS, 0.0) calls. This works fine, but significantly slows down the execution (aparently not hw accelerated on NVidia's drivers).

I've also tried to change the Texture pixel format from GL_RGBA to GL_RGB. This works fine, and fast, but since I reuse textures for Images (Images are allowed to have non-power-of-two dimensions, and there can be many on one texture), this is not a good solution, since there may be more images on the texture I change.

Is there any quick way to set all the alpha components of a texture region to 1.0?

07-18-2003, 05:48 PM
Clear the alpha component to one when clearing the screen using glClearColor and writemask the alpha when drawing using glColorMask to keep it at one.