views:

475

answers:

2

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);

+1  A: 

If you're using a recent-enough version of OpenGl, you could of course user shader programming to do this.

If you don't want to use that, but are using OpenGL 2.0 or higher, you can use the glMatrixMode() function to set OpenGL's color matrix to something matching your desired transform.

unwind
I'm not allowed to use shaders (external demand, can't negotiate), and although that OpenGL color matrix thing looked like exactly what i needed, it doesn't seem to be supported by my target platform. Thanks anyway. Any other ideas?
Grant Peters
+1 here as well :) glMatrixMode() is a very good solution.glMatrixMode(GL_TEXTURE);glLoadMatrix( .. );The loaded matrix is a 4x4, which is exactly what you need and you already have all the information for the matrix.
Magnus Skog
+2  A: 

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

Marcus Lindblom
Do you know of any tutorials for implementing texture stages, or at least a few of the functions required that i could search for?
Grant Peters
No, it's been ages since I did multitexturing the old way. I think glTexEnv is the correct function to use.
Marcus Lindblom
Magnus Skog