Search code examples
opengltexturing

How do I apply a colour transformation matrix to a texture in OpenGL


Basically, I've got a colour matrix defined as such:

struct ColourXForm
{
   float4 mul;
   float4 add;

   float4 Transform(float4 colour)
   {
      return float4(
         colour.x * mul.x + add.x,
         colour.y * mul.y + add.y,
         colour.z * mul.z + add.z,
         colour.w * mul.w + add.w);
   }
}

What I want to do is to apply the function 'Transform' to each pixel in the texture as it is rendered onto the screen. I can't actually modify the texture as different colour transform matrices can be applied to the same image multiple times in a frame (and I don't know what will be applied until it is time to render the texture), and I can't use shaders either.

Is there a way this could be done given these requirements? (my only idea so far is multi-texturing, but can't figure out how to apply it)

Also, I'm new to OpenGL, so it would be helpful to post some code as well, or point me to a tutorial or even the required functions/parameters.

Thanks

Edit: One more thing I should mention, is that the texture contains pre-multiplied alpha, so blending is setup as glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);


Solution

  • If not shaders (crazy demand that, homework or non-PC platform?) then you could probably set this up using texture stages or something. Your function is pretty simple (tex * a + b) so it ought to be doable, althogh not very fun. :-P