Skip to main content
GameDev.net gamedev.net
🔒 Locked

glTexEnv

Started by Gumgo Jun 19, 2007 at 11:04 PM 3 replies 2.6k views
Original Post
Gumgo
Gumgo
I'm trying to use glTexEnv along with ARB_multitexture to make lightmaps but I need some help with blending. I've tried out all four modes using glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, ... ): GL_MODULATE, GL_BLEND, GL_REPLACE, and GL_DECAL and all but GL_BLEND seem to have no visible effect different from the default multitexture blending. GL_BLEND just seems to invert the colors of the lightmap. What happens right now (it seems) is that the lightmap texture's black areas make the object completely black and the lightmap's white areas make the object's original texture show through 100% (like normal). What I want is for the black areas on the lightmap to make the object completely black in that spot and the white areas to make the object white... Basically, rather than have the lightmap as a "mask" for the texture, have it affect the brightness of the object (and tint the color too). What settings for glTexEnvf should I use, or some other function? Also, what's the difference between glTexEnvf and glTexEnvi?
MARS_999
MARS_999
Well first of glTexEnvi takes a int value and glTexEnvf takes floats. There isn't any reason that I know of to use the float version.


As for the texture issue, its doing what it is told to do. Black mean 0 so it multiplies the incoming fragment by 0 which equals 0. Now with the white values those are 1 so your old value times 1 = old value.

You will need to use GL_REPLACE IIRC to do what you want. You must be missing something if it's not working. Post your code.
Gumgo
Gumgo
		glActiveTextureARB( GL_TEXTURE0_ARB );		tex->SetTexture();		glActiveTextureARB( GL_TEXTURE1_ARB );		light->SetTexture();		glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE ??? );		...		glBegin( GL_TRIANGLES );		for (unsigned int ii = 0; ii < model->triNum; ii++)		{			for (unsigned int jj = 0; jj < 3; jj++)			{				glNormal3d( model->triangle[ii]->normal[jj]->vector.x,					model->triangle[ii]->normal[jj]->vector.y,					model->triangle[ii]->normal[jj]->vector.z );				glMultiTexCoord2dARB( GL_TEXTURE0_ARB, model->triangle[ii]->vertex[jj]->tex.x,								model->triangle[ii]->vertex[jj]->tex.y );				glMultiTexCoord2dARB( GL_TEXTURE1_ARB, model->triangle[ii]->vertex[jj]->light.x,								model->triangle[ii]->vertex[jj]->light.y );				glVertex3d( model->triangle[ii]->vertex[jj]->point.x,					model->triangle[ii]->vertex[jj]->point.y,					model->triangle[ii]->vertex[jj]->point.z );			}		}		glEnd();        		glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );

There's my code.
V-man
V-man
For each texture unit, you need to set the tex environment state.

glActiveTexture(GL_TEXTURE0);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
tex->SetTexture();
glActiveTexture(GL_TEXTURE1);
light->SetTexture();
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

so this means tex0 * tex1
Gumgo
Gumgo
I've found an example of the effect I want... In adobe photoshop, I'd like the lightmap to blend with the object like the blend mode "Overlay" (or "Soft Light" would work).

It looks like this is a combination of "multiply" and "lighten"... basically, it appears that the way to get this effect is if the lightmap pixels are from 0-50% gray, multiply them with the texture, from 50-100% would be to... lighten the texture (not really sure).

Basically, I'm trying to find a way to merge both "multiply" and "lighten" so that I can get both complete black and complete white, not just multiply, which ranges from black to the original texture color.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.