Jump to content
  • Advertisement
Sign in to follow this  
Popolon

OpenGL render in black and white

This topic is 4813 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
... 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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!