写入渲染缓冲区并使用单个渲染调用使用 OpenGL 显示
Writing to renderbuffer AND display with OpenGL with single rendercall
有没有办法同时渲染到渲染缓冲区和显示器,而不必多次调用绘制函数?我想要这样的东西:
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE2D, tbo, 0);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
GLenum* attachments[2] = {GL_COLOR_ATTACHMENT0, ...} //with the second I want to render to screen which would have the same value like the first
glDrawBuffer(2, attachments);
glDrawElements(GL_TRIANGLES, 12*3, GL_UNSIGNED_INT, 0);
因此,我可以将绘制的内容与另一个渲染调用的纹理同时使用。我可以写
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDrawElements(GL_TRIANGLES, 12*3, GL_UNSIGNED_INT, 0);
但这需要再次绘制场景,这会很慢。另一种解决方案是绘制帧缓冲,但我认为会有一个更智能的解决方案。
您可以使用glBlitFramebuffer()
将帧缓冲区复制到另一个帧缓冲区。
像这样:
glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
glBlitFramebuffer(
0, 0, fboWidth, fboHeight,
0, 0, screenWidth, screenHeight,
GL_COLOR_BUFFER_BIT, GL_NEAREST);
应该做这个伎俩。
相关文章:
- 比较并显示使用最小值(a,b)和最大值(a、b)升序排列的4个数字
- C++,OpenCV,尝试显示图像时"OpenCV(4.3.0) Error: Assertion failed (size.width>0 && size.height>0)"此错误
- 字符串-C++后显示的随机字符
- 继承期间显示未知行为的子类
- 仅使用绝对值对数组进行排序,并在C++中显示实际值
- 程序崩溃并显示"std::out_of_range"错误
- 如何将一个ostringstream十六进制字符串字符对转换为单个unit8t等价的二进制值
- 多个If语句与使用逻辑运算符计算条件的单个语句的比较
- 如何在C++中用std::cout正确显示带十六进制的字符串文本
- 为什么在C的循环中使用printf的Rust代码不显示输出,而在C++的循环中显示std::cout
- 从数据库实时显示QT c++中的数据
- 尝试从列表中随机选取单个元素并将其显示为C++
- 写入渲染缓冲区并使用单个渲染调用使用 OpenGL 显示
- 单个模板功能,用于显示不同容器的内容
- C++:读入文件并显示单个项目
- 如何在单个块中显示十六进制值
- 使用 OpenCV 3.0 和 MSVS 12 在单个窗口上显示多个图像
- Opengl:使用单个通道纹理作为alpha通道来显示文本
- 在单个字符串中显示Unicode QString的QLatin1String连接
- 对于单个输出显示相同的数字,但当输出超过1个时,输出是预期的