opengl - Render to FBO + glReadPixels all black -
i trying render simple checkerboard in fbo , glreadpixels().
when without fbo, works fine. assume render function ok , glreadpixels(). fbo, lines draw after calls fbo have been done.
here code (python, aiming 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) 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 simple line. works fine dropframetest() # draw simple line. works fine
in main, call renderfbo() done once, , on_draw called periodically.
dt = pyglet.clock.tick() renderfbo() pyglet.clock.schedule_interval(on_draw, 0.007) pyglet.app.run()
at guess, you've bound framebuffer gl_draw_framebuffer only. use
glbindframebuffer(gl_framebuffer, ...
and
glframebufferrenderbuffer(gl_framebuffer, ...
to both read , write same fbo.
i'm sure have checking framebuffer completeness (glcheckframebufferstatus) , gl errors (glgeterror, or new extension) useful.
[edit]
(the shotgun problem solving tactics from comments)
if see image on first frame, none on next there must staying behind previous frame.
- the common problem forgetting clear depth buffer - haven't.
- next stencil buffers , blending (neither they're enabled begin with).
- maybe new fbo handle being generated each frame , you're running out?
- another common problem accumulating matrix transforms, have glloadidentity should no issue there.
Comments
Post a Comment