简体   繁体   English

仅将 window 的一部分渲染到 opengl 中的帧缓冲区

[英]Rendering only a part of the window onto a framebuffer in opengl

I have been wanting to make edit menu using framebuffers in opengl(with c++).我一直想在 opengl(使用 C++)中使用帧缓冲区制作编辑菜单。 I then render some buttons in the menu space and then render the framebuffer.然后我在菜单空间中渲染一些按钮,然后渲染帧缓冲区。 So while creating the framebuffer I just want it to be able to read and draw only a part of the screen (say coordinates between X1 and X2 and Y1 and Y2) which will then be converted into a texture attachment.因此,在创建帧缓冲区时,我只希望它能够读取和绘制屏幕的一部分(比如 X1 和 X2 以及 Y1 和 Y2 之间的坐标),然后将其转换为纹理附件。 The problem is I don't how to render a framebuffer which has a different size other than the window dimension.问题是我不知道如何渲染尺寸不同于 window 尺寸的帧缓冲区。 So I need to how to achieve this.所以我需要如何实现这一点。

I think the code that needs to be changed is these 3 lines:我认为需要更改的代码是这 3 行:

  1. glRenderBufferStorageMultiSample(GL_FRAMEBUFFER, 4, GL_RGB, SCREEN_WIDTH, SCREEN_HEIGHT);
  2. glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, SCREEN_WIDTH, SCREEN_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
  3. glBlitFrameBuffer(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0,0,SCREEN_WIDTH, SCREEN_HEIGHT, GL_COLOR_BUFFER_BIT, GL_NEAREST);

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

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