我将fbo渲染到纹理,纹理完美呈现。但是当我通过以下函数运行纹理时,使用GL_COMPRESSED_RGBA,函数返回的textureresult被加扰。我正在使用最新版本的LWJGL。
public static int burnToTexture(int textureId) {
// Create fbo for texture
fboId = glGenFramebuffersEXT();
fboTextureId = glGenTextures();
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
glBindTexture(GL_TEXTURE_2D, fboTextureId);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA, SAVE_WIDTH, SAVE_HEIGHT, 0,GL_RGBA, GL_INT, (java.nio.ByteBuffer) null);
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, fboTextureId, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// Render texture to fbo
glPushAttrib(GL_ALL_ATTRIB_BITS);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glViewport(0,0,SAVE_WIDTH,SAVE_HEIGHT);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, SAVE_WIDTH, 0, SAVE_HEIGHT);
glLoadIdentity();
glDisable(GL_DEPTH_TEST);
glClearColor(1.0f, 1.0f, 0.0f, 0.0f);
glClear (GL_COLOR_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, textureId);
glBegin (GL_QUADS);
glTexCoord2f(0.0f, 0.0f);
glVertex2i (-1, -1);
glTexCoord2f(1.0f, 0.0f);
glVertex2i (1, -1);
glTexCoord2f(1.0f, 1.0f);
glVertex2i (1, 1);
glTexCoord2f(0.0f, 1.0f);
glVertex2i (-1, 1);
glEnd();
glDisable(GL_TEXTURE_2D);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
glPopAttrib();
// Destroy fbo
glDeleteFramebuffersEXT(fboId);
return fboTextureId;
}