0

跟进问题:

  • 我需要为 FBO 设置不同的活动纹理吗?这可能是原因,因为我没有考虑到这一点。无论哪种方式,我的活动纹理都有问题。如果我在这一切之前将活动纹理设置为 TEXTURE_1,我会得到对象的纹理(但是错误的纹理)。

    for (int side = 0; side < 2; side++)
    {
    
        glPushAttrib(GL_ALL_ATTRIB_BITS);
        glBindTexture(GL_TEXTURE_2D, 0); // Delete this line and a, wrong, texure pops up for the second iteration
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, modelsFboId[side]);
    
        glViewport(0,0,screenWidth,screenHeight);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(SCREEN_FOV, SCREEN_RAT, NEAR, FAR);
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
        glShadeModel(GL_SMOOTH);
        glHint(GL_PERSPECTIVE_CORRECTION_HINT,
            GL_NICEST);
        glDisable(GL_BLEND);
        glEnable(GL_DEPTH_TEST);
        glDepthFunc(GL_LESS);
        glDepthMask(true);
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        glClearDepth(1.0f);
        glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glLoadIdentity (); 
    
        camera.look();
    
        drawObject();
    
        glDisable(GL_DEPTH_TEST);
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
    
        glPopAttrib();
    }
    

我循环了两个 fbo,它们也是在一个循环中创建的。fbo 工作正常,但是纹理不想绑定的第二次迭代。我尝试为第二次迭代切换到不同的活动纹理,我禁用了一个着色器,我也尝试设置 clientactivetexture。如果我跳过第一次迭代,则第二个循环不起作用。当我附加颜色而不是纹理时,对象会显示(它根本不显示纹理绑定)。

我试图追踪这个错误两天了,但无济于事。

此外,在这个循环之后,我有第二个循环,它是相同的,除了它使用一个显示列表,它对两个迭代都很好,这可能表明了一些事情。

    for (int side = 0; side < 2; side++) {
        modelsFboId[side] = glGenFramebuffersEXT();                                     
        modelsFboTextureId[side] = glGenTextures();                                     
        modelsDepthRenderBufferId[side] = glGenRenderbuffersEXT();

        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, modelsFboId[side]);    

        glBindTexture(GL_TEXTURE_2D, modelsFboTextureId[side]);                             
        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_RGBA8, screenWidth, screenHeight, 0,GL_RGBA, GL_INT, (java.nio.ByteBuffer) null); 
        glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_2D, modelsFboTextureId[side], 0); 

        glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, modelsDepthRenderBufferId[side]);         
        glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT, screenWidth, screenHeight);
        glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT, modelsDepthRenderBufferId[side]); 
        glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
      }

绘制对象():

   // using bind slick, texture int doesn't change in this function nor any other

    if (textureMode == 1) {
        glColor3f(color.x, color.y, color.z);
    } else if (textureMode == 0) {
        glColor3f(1.0f, 1.0f, 1.0f);
        glEnable(GL_TEXTURE_2D);
        textures[texture].bind();
    }

    glPushMatrix();
    ..rotations.. all seems definitely fine here and certainly doesn't change in correspondence to the prev iteration.

    .. draw actual object.. tried LWJGL sphere, a simple cube and some other LWJGL objects
    glPopMatrix();

    if (textureMode == 0)
        glDisable(GL_TEXTURE_2D);

数组初始化..

int skyFboId[] = {-1, -1};
int skyFboTextureId[] = {-1, -1};

int modelsFboId[] = {-1, -1};
int modelsFboTextureId[] = {-1, -1};
int modelsDepthRenderBufferId[] = {-1, -1};

int listModelsFboId[] = {-1, -1};
int listModelsFboTextureId[] = {-1, -1};
int listModelsDepthRenderBufferId[] = {-1, -1};
int listModelsTextureLocation = -1;
4

1 回答 1

0

显然,Slick 库需要使用 TextureImpl.unbind() 取消绑定纹理。

于 2013-02-18T13:32:09.180 回答