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

Using 2x color modulation in FFP

Started by Plerion Jan 26, 2015 at 9:03 PM 0 replies 2.2k views
Original Post
Plerion
Plerion

Hello guys

Im asking this question for a friend of mine. He has an old program thats still using the FFP for rendering in OpenGL. Right now it still all works but there is a new feature hed like to implement. Every vertex has a color value. But its modulated in a different way. In GLSL in the fragment shader it would be like:


gl_FragColor = input_color.rgb * 2 * texture_color;

So essentially a color value of 0x7F7F7F7F would just return the texture color whereas 0xFFFFFFFF would double all channels of the texture.

The color values are bound to a buffer and sent to the FFP using glColorPointer. In DirectX i remember there was some kind of texture sampler state that allowed to specify MODULATE_2X as color operation. Is there something similar in OpenGL?

Greetings

Plerion

21st Century Moose
21st Century Moose

The good news is yes, there is.

It's part of the GL_ARB_texture_env_combine extension, or is core in IIRC GL1.4, so if one's hardware meets those requirements then one can do it.

The basic setup is:

glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
glTexEnvi (GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
glTexEnvi (GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PRIMARY_COLOR);
glTexEnvf (GL_TEXTURE_ENV, GL_RGB_SCALE, 2.0f);

Note that though the API appears otherwise, by specification the only legal values for GL_RGB_SCALE are 1, 2 or 4. If you come across hardware or drivers that accept other values, be aware that it's non-standard behaviour.

Also be aware that the GL_RGB_SCALE value seems to "stick" for other GL_TEXTURE_ENV_MODEs on some (most?/all?) drivers, so you should also reset it to 1.0f when done.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls. 

Topic Locked

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

Sign in to reply to this topic.