0
我將fbo渲染到紋理,並且紋理完美地顯示出來。但是,當我通過以下函數(使用GL_COMPRESSED_RGBA)運行紋理時,函數返回的textureresult被加擾。我正在使用最新版本的LWJGL。GL_COMPRESSED_RGBA給出了加擾輸出
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;
}