python framebuffer_Python GL.glDeleteFramebuffers方法代码示例

# 需要导入模块: from OpenGL import GL [as 别名]

# 或者: from OpenGL.GL import glDeleteFramebuffers [as 别名]

def setup_fb(self, width, height):

'''Sets up FrameBuffer that will be used as container

for 1 pass of rendering'''

# Clean up old FB and Texture

if self.fb_texture is not None and \

GL.glIsTexture(self.fb_texture):

GL.glDeleteTextures([self.fb_texture])

if self.fbo is not None and GL.glIsFramebuffer(self.fbo):

GL.glDeleteFramebuffers(1, [self.fbo])

# initialize FrameBuffer

self.fbo = GL.glGenFramebuffers(1)

GL.glBindFramebuffer(GL.GL_FRAMEBUFFER, self.fbo)

depthbuffer = GL.glGenRenderbuffers(1)

GL.glBindRenderbuffer(GL.GL_RENDERBUFFER, depthbuffer)

GL.glRenderbufferStorage(GL.GL_RENDERBUFFER, GL.GL_DEPTH_COMPONENT32F,

width, height)

GL.glFramebufferRenderbuffer(

GL.GL_FRAMEBUFFER, GL.GL_DEPTH_ATTACHMENT, GL.GL_RENDERBUFFER,

depthbuffer

)

# end of FrameBuffer initialization

# generate the texture we render to, and set parameters

self.fb_texture = GL.glGenTextures(1) # create target texture

# bind to new texture, all future texture functions will modify this

# particular one

GL.glBindTexture(GL.GL_TEXTURE_2D, self.fb_texture)

# set how our texture behaves on x,y boundaries

GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT)

GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT)

# set how our texture is filtered

GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR)

GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)

# occupy width x height texture memory, (None at the end == empty

# image)

GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA32F, width,

height, 0, GL.GL_RGBA, GL.GL_FLOAT, None)

# --- end texture init

# Set "fb_texture" as our colour attachment #0

GL.glFramebufferTexture2D(

GL.GL_FRAMEBUFFER, GL.GL_COLOR_ATTACHMENT0, GL.GL_TEXTURE_2D,

self.fb_texture,

0 # mipmap level, normally 0

)

# verify that everything went well

status = GL.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER)

assert status == GL.GL_FRAMEBUFFER_COMPLETE, status

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值