how to do modulation to simulate lighting effects ???

Started by
14 comments, last by stormrunner 19 years, 8 months ago
hi, im working on a 2D RPG w / C++ , SDL, and OpenGL. anyway, i was talking to a friend of mine whos making an RPG w / d3d. in it, he has some really cool lighting effects. basically, each tile, sprite, etc, has a darkness value. there is no real "light", he just blends everything with a dark color to make things that arent as dark appear lit. basically, he makes his character / tile quad blended with a dark color to make it appear darker then it really is. i dont think this will work by just using glColor4f(), since once i bind a texture to a quad, the color no longer matters (except the alpha). i was thinking i could draw a black quad over everything and blend it, but this seems very expensive and too much work to do. surely there must be a way to blend a color with a textured quad? thanks for any help!!
FTA, my 2D futuristic action MMORPG
Advertisement
Have you actually tried using it? I see no reason why it shouldn't work. I may be missing your point, but it seems simple enough.

glBindTexture (GL_TEXTURE_2D, textureId);
glBegin (GL_QUADS);
glColor3f (0.5f, 0.5f, 0.5f);
glTexCoord2f (...
glVertex3f (...
>>i dont think this will work by just using glColor4f(), since once i bind a texture to a quad, the color no longer matters (except the alpha).<<

yes it does, if lighting is disabled and texenv is set to get MODULATE
well, everytime i draw a quad with a texture, the texture seems to over-write the color.

what exactly is "texenv is set to get MODULATE".

what is texenv and how do i set it? thanks for any further help!
FTA, my 2D futuristic action MMORPG
i think he means -
void glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )
glTexEnvi specifies how your textures are combined with colors in the frame buffer. GL_MODULATE allows your texture colors to be multiplied by the existing pixel color, and not replace them.
hope that helps.

<edit> the other two modes are
GL_BLEND - the texture color is multiplied by the pixel color and is combined with a constant color
GL_DECAL - the texture color replaces the pixel color
- stormrunner
thanks stormrunner.

the one thing is, i couldnt find in google how to disable it once i set it to MODULATE. do i just set it to DECAL to go back to normal? im assuming DECAL is the defualt, since ive never called this function before.

thanks again!
FTA, my 2D futuristic action MMORPG
*sheepish grin* i would be more help if i read the next sentence -
Quote:
taken from Opengl Game Programming
The default value for glTexEnvi() is GL_MODULATE

i'm pretty sure you have to call the function in order for that to be true, though. someone correct me if i'm wrong.
- stormrunner
Quote:Original post by stormrunner
i think he means -
void glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )
glTexEnvi specifies how your textures are combined with colors in the frame buffer. GL_MODULATE allows your texture colors to be multiplied by the existing pixel color, and not replace them.
hope that helps.

<edit> the other two modes are
GL_BLEND - the texture color is multiplied by the pixel color and is combined with a constant color
GL_DECAL - the texture color replaces the pixel color


It's not true that glTexEnvi specifies how your textures are combined with colors in the frame buffer - it would be blending and glBlendFunc and glEnable/Disable(GL_BLEND). Tex env specifies how during particular pass color's from different sources(textures,diffuse,specular etc) are mixed withing texture units - that's all. Only the output value is blended into frame buffer
www.tmreality.com
Quote:It's not true that glTexEnvi specifies how your textures are combined with colors in the frame buffer

my only defense is that that is specifically what "the book" said - word for word.
Quote:
taken from Opengl Game Programming - pg. 242 section Texture Functions
The target parameter must be equal to GL_TEXTURE_ENV. You must also set the pname parameter equal to GL_TEXTURE_ENV_MODE, which tells OpenGL that you will be specifying how textures are going to be combined with colors in the frame buffer.
- stormrunner
Quote:Original post by stormrunner
Quote:It's not true that glTexEnvi specifies how your textures are combined with colors in the frame buffer

my only defense is that that is specifically what "the book" said - word for word.
Quote:
taken from Opengl Game Programming - pg. 242 section Texture Functions
The target parameter must be equal to GL_TEXTURE_ENV. You must also set the pname parameter equal to GL_TEXTURE_ENV_MODE, which tells OpenGL that you will be specifying how textures are going to be combined with colors in the frame buffer.


Quote:from MSDN
glTexEnvf, glTexEnvi, glTexEnvfv, glTexEnviv
These functions set texture environment parameters.

void glTexEnvf(
GLenum target,
GLenum pname,
GLfloat param
);

void glTexEnvi(
GLenum target,
GLenum pname,
GLint param
);
Parameters
target
A texture environment. Must be GL_TEXTURE_ENV.
pname
The symbolic name of a single valued–texture environment parameter. Must be GL_TEXTURE_ENV_MODE.
param
A single symbolic constant, one of GL_MODULATE, GL_DECAL, GL_BLEND, or GL_REPLACE.
void glTexEnvfv(
GLenum target,
GLenum pname,
const GLfloat *params
);

void glTexEnviv(
GLenum target,
GLenum pname,
const GLint *params
);
Parameters
target
A texture environment. Must be GL_TEXTURE_ENV.
pname
The symbolic name of a texture environment parameter. Accepted values are GL_TEXTURE_ENV_MODE and GL_TEXTURE_ENV_COLOR.
params
A pointer to an array of parameters: either a single symbolic constant or an RGBA color.
Remarks
A texture environment specifies how texture values are interpreted when a fragment is textured. The target parameter must be GL_TEXTURE_ENV. The pname parameter can be either GL_TEXTURE_ENV_MODE or GL_TEXTURE_ENV_COLOR.

If pname is GL_TEXTURE_ENV_MODE, then params is (or points to) the symbolic name of a texture function. Three texture functions are defined: GL_MODULATE, GL_DECAL, and GL_BLEND.

A texture function acts on the fragment to be textured using the texture image value that applies to the fragment (see glTexParameter) and produces an RGBA color for that fragment. The following table shows how the RGBA color is produced for each of the three texture functions that can be chosen. C is a triple of color values (RGB) and A is the associated alpha value. RGBA values extracted from a texture image are in the range [0,1]. The subscript f refers to the incoming fragment, the subscript t to the texture image, the subscript c to the texture environment color, and subscript v indicates a value produced by the texture function.

A texture image can have up to four components per texture element (see glTexImage1D and glTexImage2D). In a one-component image, Lt indicates that single component. A two-component image uses Lt and At. A three-component image has only a color value, Ct. A four-component image has both a color value Ct and an alpha value At.


Besides, I'm using it;)
www.tmreality.com

This topic is closed to new replies.

Advertisement