Why must I use glTexEnvf

Started by
2 comments, last by Pemaden 16 years ago
Hey guys, I'm not sure I entirely understand what the command 'glTexEnvf' is doing. My book does not mention using it, and most texturing tutorials also don't mention it. I don't remember why I finally ended up putting it into my code, but now that I'm trying to load multiple textures, I realize that when i remove that function, my textures don't show up. So my question is, why is this one command making or breaking my program when no one else seems to use it much. Here is my code, I don't know if it would help.

	glGenTextures(1, &texture_tgatitle);
	glBindTexture(GL_TEXTURE_2D, texture_tgatitle);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, tgatitle->width, tgatitle->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, tgatitle->pixelData);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
Advertisement
It sets up the texture environment mode on the texture unit.
Sadly, there are many people that seem to think it is bound to the texture object itself so every time they create a texture, they shuve a glTexEnv call after the glTexParameter calls.

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
basically means ignore the primary color source and just send the texels down the pipe. Read the specification on opengl at opengl.org

I think the default mode is GL_MODULATE, which means multiply texels with the primary color.
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);
Of course, all this is merely of historical interest, since those nice little things called shaders came into existance...

So yeah, glTexEnvf was used to configure the fixed function pixel pipeline. It was inflexible, unintuitive and limited. Fortunately, it's not needed anymore nowadays. Good riddance.
Thanks V-man, that default setting appears to be the exact problem. I had the primary color is as black, so I guess any texels multiplied with black would always give me black. I changed the primary color, and sure enough the texture shows without that command.

Thanks!

This topic is closed to new replies.

Advertisement