2012-08-14 173 views
1

我有一個紋理的天體。當附加圖像時呈現白色,但在給出顏色時呈現正確。我有理由認爲紋理被覆蓋,因此一些技巧會很棒。它以前工作正常,適當地顯示紋理。紋理顯示爲白色

編輯:如果我將紋理直接打印到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(); 

而且我在做我的大部分工作在緩存:

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

如果您未定義紋理座標,則可能發生這種情況。白色可能是像素0,0處的白色雲。你知道你正在使用舊的OpenGL函數嗎? – 2012-08-14 15:19:25

+0

LWJGL使用s.setTextureFlag(true)自動創建紋理座標;正如我所說的那樣,它曾經很好地工作,所以紋理座標不會成爲問題。 – RobotRock 2012-08-14 15:21:58

回答

0

我用

glPushAttrib(GL_ALL_ATTRIB_BITS); 

在開始和

glPopAttrib(); 

在結束時每幀復位的OpenGL狀態。