不能 glreadPixels 超过 3844x1065

Can't glreadPixels more than 3844x1065

我正在尝试将我制作的场景渲染到屏幕外 FBO,如果我将 width/height 设置为高于 3844/1065,我的最终图像将限于该分辨率。我正在使用两台显示器。下图是使用 4500x2160 分辨率渲染的。 "active" 面积为 3844x1065.

这是一些代码:

        windowWidth = 4500 
        windowHeight = 2160
        mainWindow = glfw.create_window(windowWidth, windowHeight, windowTitle, None, None)
        glfw.set_window_pos(mainWindow, 10, 10)
        glfw.make_context_current(mainWindow)
        glfw.set_window_size_callback(mainWindow, window_resize)
        frameBuffer = glGenFramebuffers(1)
        glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer)
        renderBuffer = glGenRenderbuffers(1)
        glBindRenderbuffer(GL_RENDERBUFFER, renderBuffer)
        glRenderbufferStorage(GL_RENDERBUFFER, GL_RGB8, windowWidth, windowHeight)
        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderBuffer)

        glDrawBuffer(GL_COLOR_ATTACHMENT0)
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        # draw all the stuff
        glReadBuffer(GL_COLOR_ATTACHMENT0)
        img_buf = glReadPixels(0, 0, windowWidth, windowHeight, GL_RGB, GL_UNSIGNED_BYTE)
        image = Image.frombytes(mode="RGB", size=(windowWidth, windowHeight), data=img_buf)
        image = image.transpose(Image.FLIP_TOP_BOTTOM)
        image.save('example.png')
        glfw.set_window_should_close(mainWindow, True)


        def window_resize(window, width, height):
            glViewport(0, 0, width, height)

找到提示:

如果我这样做:

     w,h = glfw.get_window_size(self.mainWindow)
     print(w)
     print(h)

我得到: 3844 1065

因此 GLFW 限制了我的 window 大小,并且绘图缓冲区仅使用该大小。

如何将绘图输出设置为所选尺寸的 FBO? (例如 5000x3000)。

window_resize的调用中set_window_size_callback的size参数是来自_GLFWwindowsizefun的,为3844x1065

视口大小始终必须是渲染目标的大小。这不一定是 window.

的大小

在渲染到渲染缓冲区之前,您必须将视口设置为渲染缓冲区大小:

glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer)
glViewport(windowWidth, windowHeight); //Not the size of the window but of the renderbuffer

glDrawBuffer(GL_COLOR_ATTACHMENT0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

# draw all the stuff

当您渲染到 FBO 以及 window 时,无论何时更改渲染目标都必须调整视口设置:

glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer)
glViewport(fboWidth, fboHeight);

# Render to FBO

glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(windowWidth, windowHeight);

# Render to Window