简体   繁体   English

纹理显示为白色

[英]Texture appears white

I have a textured skydome. 我有一个纹理的穹顶。 It renders white when an image is attached, but it does renders right when a color is given. 附加图像时它呈现白色,但是当给出颜色时它呈现正确。 I have reasons to assume the texture is overwritten, thus some tips on this would be great. 我有理由假设纹理被覆盖,因此有关此的一些技巧将非常有用。 It used to work fine, displaying the texture appropriately. 它过去可以正常工作,可以适当显示纹理。

EDIT: If I print the texture directly to the fbo, it does show the texture. 编辑:如果我直接将纹理打印到fbo,它会显示纹理。 However when I map it to the sphere it shows up white. 但是,当我将其映射到球体时,它显示为白色。 Give the sphere a color, and it shows correctly with the color. 给球体指定颜色,然后正确显示该颜色。 Also for the record, white is not the clear color. 另外,白色不是清晰的颜色。 And I use an image that's quite large (3000x1000~). 而且我使用的图像非常大(3000x1000〜)。

ADD: No errors are given anywhere. 添加:任何地方都没有错误。

Changing: 变更:

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

To: 至:

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

displays the proper image once, first cycle, then, white again. 一次显示正确的图像,首先循环,然后再次显示白色。

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

This is the skysphere code: 这是天际代码:

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;
}

In initGL: 在initGL中:

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

Also I'm doing most of my work in framebuffers: 另外,我也在帧缓冲区中完成大部分工作:

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

And in one occasion copy the depth to a texture: 有时将深度复制到纹理中:

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

I used 我用了

    glPushAttrib(GL_ALL_ATTRIB_BITS);

at the beginning and 在开始和

    glPopAttrib();

at the end to reset the OpenGL states each frame. 最后重置每帧的OpenGL状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM