简体   繁体   English

OpenGL获取背景像素信息

[英]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. 我有一个具有完全透明窗口的OpenGL应用程序,我需要根据背景以像素透明度将其绘制到其中。 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. useShader只是调用glUseProgram过程,而drawTriangle只是绘制一个测试三角形。

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. 因此,如果我用(1.0,0,0,1.0)清除窗口,则会得到预期的黄色三角形,但是当我切换到(0,0,0,0)时,它将变为绿色。 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? 仅使用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. 您必须使用特定于操作的功能来将窗口下方的屏幕内容作为图像检索,加载到纹理中并将其传递给渲染。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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