Send to FBO + glReadPixels all black

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() # draw a simple line. works fine DropFrameTest() # draw a simple line. works fine 

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() 
+4
source share
1 answer

Guessing, you only linked the framebuffer to GL_DRAW_FRAMEBUFFER. Use

 glBindFramebuffer(GL_FRAMEBUFFER, ... 

and

 glFramebufferRenderbuffer(GL_FRAMEBUFFER, ... 

for reading and writing with the same FBO.

I am sure that you already have, but check the completeness of the framebuffer (glCheckFramebufferStatus) and for GL errors (glGetError or a new extension) is also very useful.

[EDIT]
(Tactics for solving the shotgun problem from the comments )

If you see the image in the first frame, but none of them should remain next to the previous frame.

  • The most common problem is to forget to clear the depth buffer, but you did not.
  • Followed by buffers and stencil mixing (none of them look like they are allowed to start).
  • Maybe a new FBO descriptor is created every frame , and you end up?
  • Another common problem is the accumulation of matrix transformations, but you have glLoadIdentity, so there should be no problems.
+4
source

Source: https://habr.com/ru/post/1497259/


All Articles