我試圖將頂點數據從紋理複製到頂點緩衝區,然後繪製頂點緩衝區。據我所知,最好的方法是將紋理綁定到fbo,並使用glReadPixels將其複製到vbo。但是,我似乎無法得到這個工作:glReadPixels失敗,錯誤「無效操作」。實現渲染到頂點數組,glReadPixels失敗(無效操作)
更正,示例和替代方法的歡迎。 :)
下面是相關代碼:
glEnable(GL_TEXTURE_2D)
w, h = 32, 32
vbo = glGenBuffers(1)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, sizeof(c_float)*w*h*4, None, GL_STREAM_COPY)
glBindBuffer(GL_ARRAY_BUFFER, 0)
fbo = glGenFramebuffersEXT(1)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo)
tex = glGenTextures(1)
glBindTexture(GL_TEXTURE_2D, tex)
# tex params here
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, w, h, 0, GL_RGBA, GL_FLOAT, None)
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0)
assert glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) == 36053
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT)
glBindBuffer(GL_PIXEL_PACK_BUFFER, vbo)
glReadPixels(0, 0, w, h, GL_RGBA, GL_FLOAT, None) # invalid operation?
GetTexImage可以爲您節省一對夫婦的指令(不需要FBO) – kvark 2011-04-22 14:02:56
該代碼看起來不錯。你確定錯誤發生在glReadPixels之後嗎? – kvark 2011-04-22 14:07:38
是的,pyopengl自動檢查錯誤,它是glReadPixels導致錯誤。 – doeke 2011-04-22 14:24:42