我试图在FBO中渲染一个简单的棋盘,然后执行glReadPixels()。
当我没有FBO时,一切正常。所以我假设我的渲染函数没问题,glReadPixels()也是如此。有了FBO,我得到的就是在调用FBO后我画的线条。
这是我的代码(Python,瞄准跨平台):
def renderFBO():
#WhyYouNoWorking(GL_FRAMEBUFFER) # degug function... error checking
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, framebuffer)
glBindRenderbuffer( GL_RENDERBUFFER, renderbufferA)
glRenderbufferStorage( GL_RENDERBUFFER, GL_RGBA, window.width, window.height)
glBindRenderbuffer( GL_RENDERBUFFER, renderbufferB)
glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, window.width, window.height)
glBindFramebuffer( GL_DRAW_FRAMEBUFFER, framebuffer)
glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbufferA)
glFramebufferRenderbuffer( GL_DRAW_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, renderbufferB)
#WhyYouNoWorking(GL_FRAMEBUFFER)
glDrawBuffer(GL_COLOR_ATTACHMENT0)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glViewport( 0, 0, window.width, window.height)
DrawChecker(Nbr = 16, Dark = 25.0/255, Light = 75.0/255)
for i in range(len(labelSysInfo)):
pyglet.text.Label(labelSysInfo[i], font_name='Times New Roman', font_size=26, x=(window.width*0.68), y= (window.height*0.04*i)+(window.height*2/3), anchor_x='left', anchor_y='center', color = (250, 250, 250, 150)).draw()
glReadPixels(0, 0, window.width, window.height, GL_RGBA, GL_UNSIGNED_BYTE, a)
glBindFramebuffer( GL_FRAMEBUFFER, 0)
我的其他功能:
def on_draw(dt):
glDrawBuffer(GL_BACK)
glClear(GL_COLOR_BUFFER_BIT)
glClearColor( 0.0, 0.0, 0.0, 1.0)
glLoadIdentity()
glEnable(GL_TEXTURE_2D)
glDisable(GL_TEXTURE_2D)
BlueLine() # draw a simple line. works fine
DropFrameTest() # draw a simple line. works fine
在main中,对renderFBO()的调用完成一次,然后定期调用on_draw。
dt = pyglet.clock.tick()
renderFBO()
pyglet.clock.schedule_interval(on_draw, 0.007)
pyglet.app.run()
答案 0 :(得分:4)
猜测,您已将帧缓冲区绑定到GL_DRAW_FRAMEBUFFER。使用
glBindFramebuffer(GL_FRAMEBUFFER, ...
和
glFramebufferRenderbuffer(GL_FRAMEBUFFER, ...
使用相同的FBO进行读写。
我确信你已经有了检查帧缓冲完整性(glCheckFramebufferStatus)和GL错误(glGetError,或者新扩展)也非常有用。
[修改]
(霰弹枪问题解决策略来自评论)
如果您在第一帧上看到图像,但在下一帧上没有图像,则必须在前一帧中留下一些东西。