纹理不显示循环

时间:2013-02-17 13:50:09

标签: opengl

跟进问题:

  • 我是否需要为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);
      }

drawObject():

   // 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);

数组inits ..

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;

1 个答案:

答案 0 :(得分:0)

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