render in black and white

Started by
19 comments, last by Optus 18 years, 7 months ago
Hi, is there a fast way to render a scene in black and white in OpenGL? In a game I'm developing I want the whole scene to be displayed in black and white when you hit the pause key. I've thought on capturing the content of the screen to a texture, then manually convert pixel by pixel the texture to black and white and then draw this texture over the screen. But isn't there a fastest way? since if I could do that in real time (I mean some game sequences to be rendered in black and white) I could achieve very nice effects! thanks in advance
Advertisement
A simple solution would be to have two textures for each object; a black-and-white and a colored one. Use GL_NEAREST filtering on the b&w texture if you don't want grey values in your textures.
You could do it in a shader as well.

Just for clarity: do you mean black/white, greytones or black/white w/filtering or antialiasing?
my-eulogy - A blog about coding and gfxsdgi - Semi-Daily Game IdeaChunkyHacker - Viewer for Relic chunky formats (used in DOW)
... or you could just use the color matrix to rescale the rgb values.

glMatrix( GL_COLOR_MATRIX );
glLoadMatrix(
{ .3, .3, .3, .0,
.3, .3, .3, .0,
.3, .3, .3, .0,
.0, .0, .0, 1.0,
};

or something like that ... i think
I just wanna get this done.
Quote:Original post by Malchivus
... or you could just use the color matrix to rescale the rgb values.

The color matrix is applied to pixel transfers, like glDrawPixels and glTexImage2D, not "normal" rendering. To use it in this case you'd have to render the scene, copy to a texture and render again.

A shader should work fine, though.
first of all, thank you for your replies...

answering e-u-l-o-g-y: I want to have greytones

I've tried the solution you proposed Malchivus, like this:

float mat[]={0.3F,0.3F,0.3F,0,             0.3F,0.3F,0.3F,0,             0.3F,0.3F,0.3F,0,             0,0,0,1};glMatrixMode(GL_COLOR);glPushMatrix();glLoadMatrixf(mat);glMatrixMode(GL_MODELVIEW);// draw the scene// ...glMatrixMode(GL_COLOR);glPopMatrix();glMatrixMode(GL_MODELVIEW);


But it does nothing at all, it renders the scene in normal color.

In fact I didn't knew that a GL_COLOR matrix existed!! it opens me a whole new world of possibilities!! However, if readen in a manual page that the color matrix only works if the GL_ARB_imaging extension is supported. How can I know that?

to ace_lovegrove:
just in case that the solution using the color matrix doesn't work. Where can I find information on how to make a shader? I've made a quick search on google, but haven't found any simple example...
You can perform a grayscale conversion on your final scene without a shader if your target card supports a dot3 texture environment, though it requires a little trickery to get working.

Described here
....[size="1"]Brent Gunning
You can find a lot of tutorials (I suggest you to download the official GL specification that is fundamental).
To begin I found these tutotrials very simple and easy
Lighthouse 3D
Without the shaders, and texture combiners, and so forth, wouldn't it be easier to just copy the scene into a texture using GL_LUMINANCE (or GL_LUMINANCE_ALPHA), then render that texture? It'd be like using a texture to do motion blurring, only not. Or did I misinterpret what the whole 'luminance' thing does?

This topic is closed to new replies.

Advertisement