0

我将 fbo 渲染到纹理,纹理完美显示。但是,当我使用 GL_COMPRESSED_RGBA 通过以下函数运行纹理时,函数返回的纹理结果会被打乱。我正在使用最新版本的 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;
}
4

1 回答 1

2

压缩的图像格式不能进行颜色渲染。而且,顾名思义,您不能渲染到使用非颜色渲染格式的纹理。

于 2013-01-08T23:26:31.817 回答