简体   繁体   中英

Grayscale blending with OpenGL?

Is there a way to set the blending parameters so the whole scene renders in grayscale? (without using GLSL, only pipeline functions)

Thanks

No, all colors are separated. You need a pixel shader for that

Hm, maybe if it was rendered to a luminoscity+alpha FBO, and then that drawn?

Well, either that or copied onto such a texture, then the texture back onto the FBO - that said, FBO's would be a better solution (if available) in most cases.

Please note that I haven't tested this.

Actually, for completeness sake, I'll mention that there is one possible solution if the GL_ARB_imaging extension is supported: the GL_COLOR_MATRIX, which transforms incoming RGBA values. You could set the upper 3x3 matrix to all 1/3.0 like so:

GLFloat graymat[] = {.33,.33,.33,0,.33,.33,.33,0,.33,.33,.33,0,0,0,0,1};
glMatrixMode(GL_COLOR_MATRIX)
glLoadIdentity()
glMultMatrixf(graymat)

However great this may sound, though, not all drivers support this in hardware, which means that depending on your opengl implementation, your driver might: A) ignore the color matrix totally, B) fall back to software rendering, or C) (if the extension is not supported) raise a GLError.

If you are writing your code for a limited set of platforms, and they support this extension, then it would be the easiest way. Otherwise, you'll need another approach.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM