Jump to content
  • Advertisement
Sign in to follow this  
BlueMonk

OpenGL Color Modulation

This topic is 3887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm converting an application from DirectX to OpenGL and I was using a color modulation feature in DirectX that allowed me, for example, to scale down the red channel of an image to 50% by specifying a color modulation value like 0xFF80FFFF. Is there a similar feature which I could use as I convert this to OpenGL? The image is being drawn as a textured quad in the new environment. D3DSprite was the old method.

Share this post


Link to post
Share on other sites
Advertisement
If you are not using lighting
glColor4ub(color, color, color, color)

For the tex environment mode :
glTexEnvi(..., ...., GL_MODULATE)

Share this post


Link to post
Share on other sites
And if you want to store the modified image permanently in GL (instead of drawing it blended with another colour) you can use glPixelTransfer (http://www.opengl.org/sdk/docs/man/xhtml/glPixelTransfer.xml).

Share this post


Link to post
Share on other sites
I'm using OpenTK, so I tried adding the following code before GL.Begin in my test program:

GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Modulate);
GL.Color4(255, 255, 128, 255);

And now none of the textured quads seem to be drawing. I expected output with half the green. This occurs even when I use GL.Color4(255,255,255,255) which I expected to have no effect on the output. And if I merely comment out the Color4 line, everything works again. Would any of these statements be interfering?

GL.PushAttrib(AttribMask.DepthBufferBit | AttribMask.LightingBit);
GL.Disable(EnableCap.DepthTest);
GL.Disable(EnableCap.Lighting);
GL.Disable(EnableCap.Dither);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
GL.TexParameter(TextureTarget.TextureRectangleNv, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
GL.TexParameter(TextureTarget.TextureRectangleNv, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);

Share this post


Link to post
Share on other sites
GL.Color4 takes ubyte?

And don't call GL.TexParameter randomly. You only need to call it when you create the texture. It becomes part of the texture object and there is no need to change it again. GL is not like D3D.

Share this post


Link to post
Share on other sites
Quote:
Original post by V-man
GL.Color4 takes ubyte?


Yes, there are 26 overloads of this function in OpenTK, and one of them takes 4 bytes (which, in C#, are unsigned).

Quote:

And don't call GL.TexParameter randomly. You only need to call it when you create the texture. It becomes part of the texture object and there is no need to change it again. GL is not like D3D.


It's only being called when creating the texture before the image is loaded into the texture.

Any ideas why the textures would be failing completely when I call GL.Color4? I've used Color4 to set the color for other things in the same way (drawing colored triangles works).

Oh, but it appears that when I called Color4 elsewhere, I was using floats instead of bytes. When I switch to using floats (between 0 and 1) everything works fine. I also see now that it works fine if explicitly cast the parameters that I'm passing to bytes so that the correct overload gets called.

Share this post


Link to post
Share on other sites
DirectX has a function to modulate two colors with respect to each other:
color = Microsoft.DirectX.Direct3D.ColorOperator.Modulate(frame.Color, color)

Does OpenGL have anything like this, or is there a way to efficiently calculate the result?

The reason: I have a design environment in which the user is allowed to specify a color modulation value in an individual frame within a sprite, as well as an overall color modulation on the whole sprite, and if they specify both, I need to combine the values.

Share this post


Link to post
Share on other sites
According to Microsoft.DirectX.Direct3D.ColorOperator.Modulate

it does

result.red = frame.Color.red * color.red
result.green = frame.Color.green * color.green
etc.

That's kind of weird. I would expect such a function to be in D3DX, not D3D.

To answer your question, no GL doesn't offer such a function.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!