2011-12-20 1 views
1

플레이어 클래스에서 "Player.png"파일을로드하는 데 이상한 오류가 발생합니다.java.io.IOException "플레이어"텍스처를 화면에 추가 할 때 어려움이 있습니다

코드 조직이 매우 엉성하고 사용하는 방법이 끔찍하다는 것을 이해합니다. 코드의 절반은 튜토리얼에서 빌려 왔습니다.

2 개의 클래스로해야 할 일은 녹색, 파란색 타일로 화면을 작성하여 W, A, S, D 키로 오른쪽, 왼쪽, 위, 아래로 이동할 수있는 "플레이어"스프라이트로 채우는 것입니다. .

오류 :

java.io.IOException: Attempt to allocate a texture to big for the current hardware at org.newdawn.slick.opengl.InternalTextureLoader.getTexture(InternalTextureLoader.java:293) 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 test.PlayerClass.render(PlayerClass.java:69) at test.Main.render(Main.java:110) at test.Main.run(Main.java:82) at test.Main.main(Main.java:27)

메인 클래스

public class Main{ 

    private static boolean running = true; 
    public static final int WIDTH = 1024; 
    public static final int HEIGHT = 768; 
    private static Texture tile; 

static PlayerClass playerClass = new PlayerClass(100, 100, 32, 32); 


public static void main(String[] args){ 

    Main main = new Main(); 
    main.run(); 
} 

//Initialize Method 
public static void init(int width, int height) throws LWJGLException 
{ 
    DisplayMode[] m = Display.getAvailableDisplayModes(); 
    for(DisplayMode mode : m) 
    { 
     if(mode.getWidth() == 1024 && mode.getHeight() == 768 && mode.getBitsPerPixel() == 32) 
     { 
      Display.setDisplayMode(mode); 
     } 

    } 
    Display.setTitle("Game"); 
    Display.setVSyncEnabled(true); 
    Display.sync(100); 
    Display.create(); 

    GL11.glMatrixMode(GL11.GL_PROJECTION); 
    GL11.glLoadIdentity(); 

    GL11.glOrtho(0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight(), 0, -1, 1); 
    GL11.glMatrixMode(GL11.GL_MODELVIEW); 
    GL11.glLoadIdentity(); 

    GL11.glEnable(GL11.GL_ALPHA_TEST); 
    GL11.glAlphaFunc(GL11.GL_GREATER, 0.2f); 
    GL11.glEnable(GL11.GL_TEXTURE_2D); 



    try { 
     tile = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("RPG/tile.png")); 
    } 
    catch (IOException e) 
    { 
     e.printStackTrace(); 
    } 
} 

public void run() 
{ 
    try { 
     init(1024, 768); 
    } catch (LWJGLException e) { 
     e.printStackTrace(); 
    } 
    while(running) 
    { 
     Display.update(); 
     drawTiled(WIDTH, HEIGHT); 
     input(); 
     update(); 
     render(); 

    } 
    cleanup(); 
} 

public static void input() 
{ 
    if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) 
    { 
     running = false; 
    } 

    playerClass.input(); 

} 

public static void update() 
{ 


} 
public static void render() 
{ 
    GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); 
    GL11.glLoadIdentity(); 

    try { 
     playerClass.render(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 

    Display.update(); 


} 

public static void cleanup() 
{ 
    Display.destroy(); 
} 

public void drawTiled(int screenWidth, int screenHeight) { 
    Color.white.bind(); 
    tile.bind(); 
    int numberPerRow = screenWidth/tile.getTextureWidth(); 
    int numberOfRows = screenHeight/tile.getTextureHeight(); 
    GL11.glBegin(GL11.GL_QUADS); 
    for (int j = 0; j < numberOfRows; j++) { 
     //System.out.print("{"); 
     for (int i = 0; i < numberPerRow; i++) 
     { 

      //top left 
      GL11.glTexCoord2f(0, 0); 
      GL11.glVertex2f(tile.getTextureWidth() * i, tile.getTextureHeight() * j); 

      //top right 
      GL11.glTexCoord2f(1, 0); 
      GL11.glVertex2f(tile.getTextureWidth() * (i + 1), tile.getTextureHeight() * j); 

      //bottom right 
      GL11.glTexCoord2f(1, 1); 
      GL11.glVertex2f(tile.getTextureWidth() * (i + 1), tile.getTextureHeight() * (j + 1)); 

      //bottom left 
      GL11.glTexCoord2f(0, 1); 
      GL11.glVertex2f(tile.getTextureWidth() * i, tile.getTextureHeight() * (j + 1));  
     } 

    } 
    } 
} 

플레이어 클래스

public class PlayerClass { 
    private float x, y; 
    private int w, h; 
    private Texture player; 
    private FloatBuffer verts = BufferUtils.createFloatBuffer(2 * 4); 
    private FloatBuffer tex = BufferUtils.createFloatBuffer(2 * 4); 

public PlayerClass(float X, float Y, int W, int H) 
{ 
    x = X; 
    y = Y; 
    w = W; 
    h = H; 

    verts.put(new float[]{ 
     0.0f, 0.0f, 
     32.0f, 0.0f, 
     32.0f, 32.0f, 
     0.0f, 32.0f 

    }); 

    tex.put(new float[]{ 
     0.0f, 0.0f, 
     1.0f, 0.0f, 
     1.0f, 1.0f, 
     0.0f, 1.0f 
    });  
} 

public void input() 
{ 
    if(Keyboard.isKeyDown(Keyboard.KEY_W)) 
    { 
     y -= 10; 
    } 

    else if(Keyboard.isKeyDown(Keyboard.KEY_S)) 
    { 
     y += 10; 
    } 

    if(Keyboard.isKeyDown(Keyboard.KEY_A)) 
    { 
     x -= 10; 
    } 

    else if(Keyboard.isKeyDown(Keyboard.KEY_D)) 
    { 
     x += 10; 
    } 

} 

public void render() throws IOException 
{ 
    player = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("RPG/player.png")); 

    player.bind(); 
    verts.rewind(); 
    tex.rewind(); 

    GL11.glEnableClientState(GL11.GL_VERTEX_ARRAY); 
    GL11.glEnableClientState(GL11.GL_TEXTURE_COORD_ARRAY); 

    GL11.glTranslatef(x, y, 0.0f); 

    GL11.glVertexPointer(2, 0, verts); 
    GL11.glTexCoordPointer(2, 0, tex); 

    GL11.glDrawArrays(GL11.GL_QUADS, 0, 4); 

    GL11.glTranslatef(-x, -y, 0.0f); 

    GL11.glDisableClientState(GL11.GL_VERTEX_ARRAY); 
    GL11.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY); 
    } 
} 

답변

1

실행이 :

System.out.println(GL11.glGetInteger(GL11.GL_MAX_TEXTURE_SIZE)); 

그래픽 카드에서 허용하는 최대 텍스처 크기를 알려줍니다. 그래픽 카드가 사용하려고하는 크기의 텍스처를 처리 할 수 ​​있는지 확인하십시오. 오류에 따르면, 그것은 할 수 없습니다.

+0

답장을 보내 주셔서 감사합니다. 내 그래픽 카드 캔트처럼 보입니다 :(. – Streak324

0

크기가 최대 인 것은 tile.png입니다. 최대 텍스처 크기는 카드에 따라 다를 수 있으며, 다른 요인들도 있습니다. 파일이이 측정 기준을 벗어난 것 같습니다.

코디의 답변을 통해 카드의 최대 텍스처 크기를 얻을 수 있습니다. 많은 사람들이 사용하기 위해 게임을 작성하는 경우에는 해당 코드를 실행중인 카드의 기능에 따라 다른 해상도 텍스처를로드하는 방식으로 게임 코드에 통합하는 것이 좋습니다. 지원하려는 모든 카드에서 작동하는 기본값을 찾아 모든 설치에 사용하십시오.

:

다음은 유용하게 찾을 수있는이 문제, 그것에 대해 몇 가지 역사, 그리고 더 많은 기술 정보에 대한 자세한 내용을 설명 할 것입니다 몇 가지 추가 읽기입니다

+0

새로운 비디오 카드를 구입해야합니다. – Streak324

관련 문제