2013-01-22 67 views
1

我正在製作基於拼圖的遊戲,並且Tiles的紋理爲16x16。每當我嘗試加載紋理,因此它可以被渲染, 我得到這個錯誤:16x16紋理太大,Java openGL

java.io.IOException: Attempt to allocate a texture to big for the current hardware 
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:292) 
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:231) 
at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:184) 
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:64) 
at org.newdawn.slick.opengl.TextureLoader.getTexture(TextureLoader.java:24) 
at main.Tile.loadTexture(Tile.java:124) 
at main.Draw.drawMap(Draw.java:282) 
at main.Draw.render(Draw.java:324) 
at main.LaunchWindow.main(LaunchWindow.java:65) 
Exception in thread "main" java.lang.NullPointerException 
at main.Draw.drawMap(Draw.java:284) 
at main.Draw.render(Draw.java:324) 
at main.LaunchWindow.main(LaunchWindow.java:65) 

現在,我知道我的GPU可以處理它,因爲它的1GB的卡。

我跑

GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE) 

,並獲得16384

下面是加載紋理的代碼:

public void loadTexture(String a){ 
    try { 
     texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream(a)); 
     System.out.println(texture.getTextureRef()); 

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

並稱爲代碼時需要渲染它:

public void drawMap(Map b){ 
    Color.white.bind(); 
    glBegin(GL_QUADS); 

    b.divideMap(10); 
    Tile[][] t = b.makeMap(b.getK()); 

    for(int y = 0; y < b.tiles.length; y++){ 
     for(int x = 0; x < b.tiles[y].length; x++){ 
      Texture a; 
      t[y][x].loadTexture(t[y][x].getLocation()); 
      a = t[y][x].getTexture(); 
      System.out.println(a.getTextureRef()); 
      a.bind(); 
      glTexCoord2f(0,0); 
      glVertex2f(x,y); 
      glTexCoord2f(1,0); 
      glVertex2f(x + a.getWidth(), y); 
      glTexCoord2f(1,1); 
      glVertex2f(x + a.getWidth(), y + a.getHeight()); 
      glTexCoord2f(0,1); 
      glVertex2f(x, y + a.getHeight()); 
     } 
    } 

    glEnd(); 
} 

回答

3

Don不知道框架,但從代碼中我看到你正在加載所有紋理的每一幀,並從不釋放它們。幾幀後,你內存不足。