04-28-2002, 07:27 AM
I'm trying to port a 2D-gfx engine of a game from Direct3D to OpenGL. One of the core features used is modulation of the loaded textures (containing an alpha channel) with a constant color while drawing them. This is done by modulating the RGB and adding the alpha values.
Modulating the colors can easily be done with GL_TEXTURE_ENV_MODE set to GL_MODULATE and setting a completely transparent color (glColor4ub(r,g,b, 255)). But how can I add a constant value to the alpha channel?
I can't modify the texture itself on the fly for performance reasons, and it should run in OpenGL1.1, if possible.
04-28-2002, 10:19 AM
I don't have the specific answer off the top of my head, but look at glBlendFunc and try setting the alpha in the glColor call to your value rather than 255 (which is fully opaque BTW).
04-28-2002, 01:46 PM
255 is 1.0f is fully transparent, at least it happened to be that way in this case :-). Setting lower values for the alpha component didn't work, because the alpha channel in GL_MODULATE is calculated as the product, so lower values would in fact decrease transparency. Values higher than 1.0 aren't even possible, of course.
What I need is an OpenGL1.1-compliant version of this (strange enough, it works with my driver, which says to be (OpenGL1.1.3)):
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_ADD);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PRIMARY_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
The glBlendFunc is the regular GL_ONE_MINUS_SRC_ALPHA, GL_SRC_ALPHA - but I can't control the way texture and color are merged through glBlendFunc, can I?
Adding a constant value to the alpha channel is quite a common thing, e.g. if you want to let something fade out. I think there must be something in the OpenGL1.1-library to do it.
[This message has been edited by Sven2 (edited 04-28-2002).]
04-28-2002, 02:18 PM
1.0f means fully opaque in the sense of "transparency". Of course, you can usually map it to go whichever way you want with the right BlendFunc (like ONE_MINUS_SRC_ALPHA). However, people will be very confused when you say 1.0 means "transparent" because that's not what it usually means when taken in isolation (alpha value == opacity value).
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.