I am trying to make a simple chessboard in FBO and then make glReadPixels ().
When I do this without FBO, everything works fine. So I assume that my rendering function is ok, as well as glReadPixels (). With FBO, all I get is the lines that I draw after the FBO calls have been made.
Here is my code (Python aimed at cross-platform):
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)
My other function:
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()
Basically, the call to renderFBO () is done once, and then on_draw is called periodically.
dt = pyglet.clock.tick() renderFBO() pyglet.clock.schedule_interval(on_draw, 0.007) pyglet.app.run()