If I have an OpenGL texture, and I need to perform HSL modifications on it before rendering the texture, from what I’ve heard I need a shader. Problem is, I know nothing about shaders. Does anyone know where I would need to look?
I want to write a function where I can pass in a texture and three values, a hue shift in degrees, and saturation and lightness multipliers between 0 and 2, and then have it call a shader that will apply these transformations to the texture before it renders. The interface would look something like this:
procedure HSLTransform(texture: GLuint; hShift: integer; sMult, lMult: GLfloat);
I have no idea what’s supposed to go inside the routine, though. I understand the basic math involved in HSL/RGB conversions, but I don’t know how to write a shader or how to apply it. Can someone point me in the right direction? Delphi examples preferred, but I can also read C if I have to.
This is quite involved, and if you’re new to shaders and FBO’s it will take some time to understand it. So here is some minimal, untested OpenGL code that implements Danvil’s answer. Error checking has been left out; it’s complicated enough as it is. If you call this function many times, you should hold on to any or all of the objects created in this code.
If you don’t care about speed, VilleK’s answer that runs on the CPU is a lot easier…
Hope that helps. For pre-2.0 OpenGL, you need to load the proper extensions first, and slap on some
EXTs and/orARBs here and there.If you’re willing to go down this road, and it doesn’t work out, don’t hesitate to post a comment describing the problems you encounter. I’ll be happy to help!