Color mapping texture pixel values

I am looking to alter the way my images are displayed by putting a clamp on the color values. By that I mean cause all pixel values below the lower clamp to display as 0.0, all pixel values above the upper clamp to display as 1.0, and all values between the clamps be linearly mapped from 0.0 to 1.0.

Previously I was displaying my image using glDrawPixels and solving the clamping problem by using glPixelMap and creating a color map that specified the desired values. However, I am now using textures to display my image and glPixelMap doesn’t work.

How can I solve this problem?

Oh, and I can’t alter the image data.

Fragment shaders. As simple as that.

How hard is it to write a fragment shader, I’ve never written one before?

Not really hard. :slight_smile: You have to keep in mind you need GL >= 1.4-compliant hardware for GLSL support, though. A very good tutorial can be found at Lighthouse3D. You don’t really need to read through the Pipeline section, but it’s better if you do as it gives you the big picture of fragment and vertex processing.

look at lighthouse3D GLSL tutorial. This one is perfect to start with shaders. It would not be difficult for your purpose.

Ok so I’ve been attempting the fragment shader. I got to the point where, after much time spent just figuring out this whole shader thing, I had code that I would try to run. However, I am getting a NullReferenceException on Gl.glCreateShaderObjectARB(Gl.GL_FRAGMENT_SHADER_ARB).

So I checked Gl.glGetString(Gl.GL_EXTENSIONS) for GL_ARB_fragment_shader and it isn’t there. I do have GL_ARB_fragment_program though.

My graphics hardware has ogl 1.4.

Does this mean I can’t use fragment shaders? If so, then I’m still lost as to how to solve my problem.