public
Last active

A Python port of the initialization code from a gamedev.net post

  • Download Gist
try_init_FBO
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
# Ported from: http://www.gamedev.net/topic/318673-fbo-question/
#
# Revised to remove the references to cocos2d
 
import pyglet
from pyglet.gl import *
from ctypes import c_ulong
 
def init():
# Ported from: http://www.gamedev.net/topic/318673-fbo-question/
numBuffers = 1
lp_color_tex = c_ulong()
glGenTextures(numBuffers, lp_color_tex);
color_tex = lp_color_tex
# initialize textures
glBindTexture(GL_TEXTURE_2D,color_tex);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,512,512,0,GL_RGBA,GL_INT,0);
lp_depth_rb = c_ulong()
glGenRenderbuffersEXT(1, lp_depth_rb);
depth_rb = lp_depth_rb.value
# initialize depth render buffer
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depth_rb);
glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, 512, 512);
lp_fb = c_ulong()
glGenFramebuffersEXT(numBuffers, lp_fb);
fb = lp_fb.value
# initialize frame buffers
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D,color_tex, 0);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb);
 
if __name__ == '__main__':
init()

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.