2011-10-20 103 views

回答

5

您可以使用像創建幀緩衝區對象:

GLint fbo, tex; // "handles" for framebuffer and it's texture 
glGenFramebuffersEXT(1, &fbo); 
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 

// setup texture for colour attachment 
glGenTextures(1, &tex); 
glEnable(GL_TEXTURE_2D); 
glDisable(GL_COLOR_MATERIAL); 
glBindTexture(GL_TEXTURE_2D, tex); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 
// set a size fotr the texture, but not any initial data 
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, fbo_resX, fbo_resY, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); 
// You might want a depth attachment here too perhaps? 
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0); 

const GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT); 
assert(status == GL_FRAMEBUFFER_COMPLETE_EXT); 

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 

然後你使用它像:

// specify which FBO to use 
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo); 
// glDraw... 

// return to the default 
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); 

,你喜歡,你可以創建多個幀緩存並綁定到他們時,你請。 (給或拿)。你需要一個有效的OpenGL上下文來使用它,這通常接近於在大多數平臺上創建一個窗口,但是你不需要在窗口中繪製任何東西。

-2

您可以使用Simple DirectMedia Layer(SDL)。

相關問題