简体   繁体   中英

OpenGL getting background pixels info

I have an OpenGL application with fully transparent window and I need to draw a picture into it with pixels transparency depending on background. Is there any way of getting background pixel data that are BELOW my transparent window (like wallpaper, desktop, another windows etc) so I can dynamically change pixels in shaders?

For now I have code like this

 glEnable(GL_BLEND);
 glBlendFunc(GL_SRC_COLOR, GL_DST_COLOR);
 glClearColor(1.0, 0, 0, 1.0);
 glClear(GL_COLOR_BUFFER_BIT);
 [self.shader useShader];
 [self drawTriangle];

useShader just calls the glUseProgram procedure and drawTriangle just draws a test triangle.

The shader is:

#version 120

void main()
{
    gl_FragColor = gl_SecondaryColor + vec4(0.0, 1.0, 0.0, 0.0);
}

So if I clear the window with (1.0, 0, 0, 1.0) I get the yellow triangle as expected, but when i switch to (0, 0, 0, 0) it gets green. Is there any way of getting undercolor data?

Is there any way of getting background pixel data that are BELOW my transparent window

With just OpenGL? No. In fact you can't even read back destination framebuffer pixels in a shader.

You'll have to use operating specific functions to retrieve the screen contents below the window as an image, load it into a texture and pass this to rendering.

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