2012-05-06 27 views
1

所以我試圖用自定義字體來繪製文本到屏幕上,我已經完成了。問題出現在同時使用紋理時。涉及真正的字體和紋理的問題LWJGL

我打開我的紋理是這樣的:

INT紋理{

 try { 
      InputStream in = new FileInputStream(filelocation); 
      PNGDecoder decoder = new PNGDecoder(in); 
      ByteBuffer buffer = BufferUtils.createByteBuffer(4 
        * decoder.getWidth() * decoder.getHeight()); 
      decoder.decode(buffer, decoder.getWidth() * 4, Format.RGBA); 
      buffer.flip(); 
      in.close(); 
      //glBindTexture(GL_TEXTURE_2D, Texture); 
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 
        GL_NEAREST); 
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 
        GL_NEAREST); 
      glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), 
        decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, 
        buffer); 
      glBindTexture(GL_TEXTURE_2D, 0); 
     } catch (FileNotFoundException ex) { 
      System.err 
        .println("Textures are not in their correct location."); 
      Display.destroy(); 
      System.exit(1); 
     } catch (IOException ex) { 
      System.err 
        .println("Textures are not in their correct location."); 
      Display.destroy(); 
      System.exit(1); 
     } 
    } 

與我的字體像這樣

公共靜態無效負載(浮點大小){

try { 
     InputStream inputStream = ResourceLoader.getResourceAsStream(filelocation); 

     Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream); 
     awtFont = awtFont.deriveFont(size); 
     fontname = new TrueTypeFont(awtFont, true); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

正在發生的事情是一些輸入流如何變得「混淆起來」,我想要的文字就是繪圖機智h我加載的紋理。

我在Font.class的遊戲循環之前加載字體,紋理從它們使用的類中加載,在遊戲循環中被調用。

我搜索了這個問題,找不到任何東西。 如果你能理解我,請提前致謝。

回答

0

而不是InputStreams混合起來,它更可能是紋理綁定。 在您的紋理類中,以下行被註釋掉:

// glBindTexture(GL_TEXTURE_2D,Texture);

這會導致紋理圖像被加載到先前綁定到GL_TEXTURE2D的任何內容中,替換之前的紋理。

您需要的紋理綁定,然後才能將圖像加載到其與glTexImage2D

+0

我忘了我在取消註釋代碼企圖掩飾這個問題了,對不起。 你知道我該如何解決我遇到的問題嗎? –

+0

我們需要看到你在渲染時綁定紋理。你能證明這一點嗎? – Aaron

+0

這是顯示列表: 'int buttonDisplayList = glGenLists(1); \t \t glNewList(buttonDisplayList,GL_COMPILE); \t \t { \t \t \t glBegin(GL_QUADS); \t \t \t glTexCoord2f(0,0); \t \t \t glVertex2f(xlocation,ylocation); \t \t \t glTexCoord2f(1,0); \t \t \t glVertex2f((xlocation + width),ylocation); \t \t \t glTexCoord2f(1,1); glVertex2f((xlocation + width),(ylocation-height));其中,glVertex2f((xlocation + width),(ylocation-height)); glVertex2f \t \t \t glTexCoord2f(0,1); \t \t \t glVertex2f(xlocation,(ylocation-height)); \t \t \t glEnd(); \t \t} \t \t glEndList();' –