On Tue, 6 Jan 2009, Tristam MacDonald wrote:
> On Mon, Jan 5, 2009 at 6:21 AM, Stéfan van der Walt
<[email protected]>wrote:
> > 1) How do I implement offscreen rendering? It seems like Framebuffer
> > Objects provide the best cross-"platform" solution, but Pyglet does
> > not explicitly provide an API to access those.
>
> Although pyglet does not wrap frame buffer objects, you can manage them
> yourself, as pyglet's opengl wrapper does expose the necessary extensions.
Indeed. Here's some code from my old wydget toolkit in pyglet contrib:
# create our frame buffer
fbo = gl.GLuint()
gl.glGenFramebuffersEXT(1, ctypes.byref(fbo))
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo)
# allocate a texture and add to the frame buffer
tex = image.Texture.create_for_size(gl.GL_TEXTURE_2D, w, h,
gl.GL_RGBA)
gl.glBindTexture(gl.GL_TEXTURE_2D, tex.id)
gl.glFramebufferTexture2DEXT(gl.GL_FRAMEBUFFER_EXT,
gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, tex.id, 0)
status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT)
assert status == gl.GL_FRAMEBUFFER_COMPLETE_EXT
# now render
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, fbo)
function()
gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0)
# clean up
gl.glDeleteFramebuffersEXT(1, ctypes.byref(fbo))
where function, w and h are things you need to provide.
> However, frame buffer objects still need a valid opengl context to operate
> (as do all opengl features). Your best bet would be to create a window with
> visible=False, and leave it invisible while rendering into your FBO. I
> can't guarantee this to work, as I haven't tried it, but the theory is
> sound.
pyglet creates a context at startup so that shouldn't be necessary.
Richard
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/pyglet-users?hl=en
-~----------~----~----~----~------~----~------~--~---