纹理显示为白色

时间:2012-08-14 15:08:03

标签: java opengl textures

我有一个纹理skydome。它在附加图像时呈现白色,但在给定颜色时呈现正确。我有理由假设纹理被覆盖,因此有一些提示会很好。它曾经很好地工作,适当地显示纹理。

编辑:如果我将纹理直接打印到fbo,它确实会显示纹理。然而,当我将它映射到球体时,它显示为白色。给球体一个颜色,并用颜色正确显示。另外,对于记录,白色不是清晰的颜色。我使用的图像非常大(3000x1000~)。

ADD:任何地方都没有错误。

更改:

glActiveTextureARB(GL_TEXTURE6_ARB);
glCallList(SkySphere.getDisplayList());

要:

glActiveTextureARB(GL_TEXTURE0_ARB);
glCallList(SkySphere.getDisplayList());

显示正确的图像一次,第一次循环,然后再显示白色。

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fboId);

    glViewport(0,0,screenWidth,screenHeight);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(90.0f, ((float)screenWidth/(float)screenHeight),0.1f,100.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glShadeModel(GL_SMOOTH);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT,
        GL_NICEST);
    glDisable(GL_DEPTH_TEST);
    glClearColor(1.0f,1.0f,0.0f,1.0f);
    glClear (GL_COLOR_BUFFER_BIT);

    glLoadIdentity (); 

    camera.look();
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_LIGHTING);

    glActiveTextureARB(GL_TEXTURE6_ARB);
    glCallList(SkySphere.getDisplayList());

    glDisable(GL_TEXTURE_2D);

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

这是skysphere代码:

public static int loadTexture(String filename) {
        ByteBuffer buf = null;
        int tWidth = 0;
        int tHeight = 0;

        .. load png into buffer..

        // Create a new texture object in memory and bind it
        textureId = GL11.glGenTextures();
        GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);

        // All RGB bytes are aligned to each other and each component is 1 byte
        GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1);

        // Upload the texture data and generate mip maps (for scaling)
        GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, tWidth, tHeight, 0, 
                        GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);          
        // Setup what to do when the texture has to be scaled
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, 
                        GL11.GL_NEAREST);
        GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, 
                        GL11.GL_LINEAR);


        return textureId;
}

public static int getDisplayList() {
    return displayList;
}

public static int makeSphere() {
    Sphere s = new Sphere();       // an LWJGL class for drawing sphere
    s.setOrientation(GLU.GLU_INSIDE);  // normals point inwards
    s.setTextureFlag(true);           // generate texture coords
    displayList = GL11.glGenLists(1);
    GL11.glNewList(displayList, GL11.GL_COMPILE);
    {
        GL11.glPushMatrix();
        {
                    GL11.glBindTexture(GL11.GL_TEXTURE_2D, getTextureId());
            //GL11.glTranslatef(0,0,0);
            GL11.glRotatef(90f, 1,0,0);     // rotate the sphere to align the axis vertically
            s.draw(1, 48, 48);              // run GL commands to draw sphere
        }
        GL11.glPopMatrix();
    }
    GL11.glEndList();
    return displayList;
}

在initGL中:

    SkySphere.createShader();
    SkySphere.loadTexture("textures/panorama2.png");
    SkySphere.makeSphere();

此外,我在framebuffers中完成了大部分工作:

    glBindTexture(GL_TEXTURE_2D, 0);
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, modelsFboId);

有时将深度复制到纹理:

    glActiveTextureARB(GL_TEXTURE3_ARB);
    glBindTexture(GL_TEXTURE_2D, modelsDepthTextureId);
    glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, screenWidth, screenHeight);
    glBindTexture(GL_TEXTURE_2D, 0);

    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);    

1 个答案:

答案 0 :(得分:0)

我用过

    glPushAttrib(GL_ALL_ATTRIB_BITS);

开头和

    glPopAttrib();

最后重置每个帧的OpenGL状态。