modifying pixels

Hello,
How can I change the values of the pixels, after all transformations, tests and other operations?
What I mean is, how can I (in example) change the value of all pixels(in example +0.5 on red) before they’re drawn to the screen.
So that I can change the brightness of my program.
Any idea how I can do that?
Thanx Hylke

The more generic way to do that is with using shaders.
But for brightness, I guess the best thing is to use the window manager API (ie WIN32 API or X11) so that you won’t need to change color values. Also, changing color and so isn’t the best way to change brightness because you’ll have to change light values too, and if a light already cast bright white light, then you won’t be able to enbright it more.

Hope that helps.

Originally posted by jide:
[b]The more generic way to do that is with using shaders.
But for brightness, I guess the best thing is to use the window manager API (ie WIN32 API or X11) so that you won’t need to change color values.

[quote] Also, changing color and so isn’t the best way to change brightness because you’ll have to change light values too, and if a light already cast bright white light, then you won’t be able to enbright it more.

Hope that helps.[/b]
I don’t think that really matters.
Because you can’t make a thing whiter than fully white.
But how do I do that with shaders?
And what exactly are they?

This can matter. If your window manager has a very low brightness, full white could look like dark grey. But I’m not an expert with that (never tried that in fact).

As for shaders, I’ve never used them. But I start knowing them a bit :slight_smile:

Shaders are programmable pipelines on recent graphic boards (since geforce 3 I guess). They replace the default fixed pipeline all cards have before.
So for each vertex or each fragment you can program new ways to compute them. You can then apply a shader to change each color that enter it with a new formula (let’s say: output_color = input_color + .5) so that all your colors will be added to 0.5. As you can see, this is not a real good model for brightness, as colors that were already more than 0.5 will be truncated to 1.0 so you will loose the color harmony.

You can also use shaders for making per pixel lighting that looks somewhat best for brightness even if, as colors, full white light won’t light more.

But I’m sure shaders won’t apply well for brightness. You really need a windowing API.

Hope that helps.

Shaders are (generally) small programs that run on the vertex or fragment processor.

Google GLSL, glslang, or OpenGL shading language for more info. There are many shader languages, but since this is an OpenGL forum I’ve mentioned gl-slang.

In your example above, if you wanted to modify the red channel of each fragment (a fragment can be thought of as a pixel but isn’t exacly that) by +0.5 you would have something like:

void main()
{
gl_FragColor.r += 0.5;
}

Would it be a good idea to buy the:
OpenGL Shading Language
?
I already understand most of my OpenGL red book.

The Book?
Absolutely; it’s a handy reference if you’re interested in getting into shader programs.

Ok, thanx for your information.
Now I’ve just gotta wait untill I have enough money to buy the book and ship it to the netherlands :slight_smile:
Hylke