2013-01-18 3 views
0

LWJGL 및 Slick2D를 사용하고 있습니다. 프로젝트를 .jar로 내보내고 JarSplice를 사용하여 실행 파일을 생성하므로 실행 파일이있는 위치에 라이브러리 파일이 필요하지 않습니다. 내 문제는 Eclipse에서 프로젝트를 실행하면 모든 이미지가로드되지만 내 보낸 실행 파일을 실행하면 찾을 수 없으므로 이미지가로드되지 않는다는 것입니다. 사진/입술 폴더에있는이로드 텍스처에 대한 방법입니다 :내 보낸 jar 파일 텍스처가로드되지 않았습니다.

private Texture loadTexture(String key) { 
    try { 
     return TextureLoader.getTexture("PNG", new FileInputStream(
       new File("res/" + key + ".png"))); 
    } catch (FileNotFoundException e) { 
     e.printStackTrace(); 
    } catch (IOException e) { 
     e.printStackTrace(); 
    } 
    return null; 
} 

여기에 나는 질감로드 : 나는 항아리를 내보내는 방법을 많이 시도

Texture background = loadTexture("main_menu/bg"); 

을,하지만 난 어떤을하지 않습니다 작동 방식.

+0

질문 제목에 "해결"을 추가하지 마십시오. 이를 나타내는 올바른 방법은 완료 한대로 "수락 됨"확인란을 클릭하는 것입니다. – KatieK

답변

0

jar 내에있는 경우 클래스 경로 리소스로로드해야 할 수도 있습니다. 참조 :

getClass().getClassLoader().getResourceAsStream(...) 
0

체크 아웃 내에서 예전의 코드를,이도

ByteBuffer buf = null; 
    try{ 
    texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/" + key + ".png")); 
    int texId = texture.getTextureID(); 
    buf = ByteBuffer.allocateDirect(4*texture.getImageWidth()*texture.getImageHeight()); 
    }catch(IOException e){ 
     e.printStackTrace(); 
    } 

    // Create a new texture object in memory and bind it 
    //int texId = GL11.glGenTextures(); - if the trick with texture.getTextureID() won't work - use THIS 
    GL13.glActiveTexture(GL13.GL_TEXTURE0); 
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, texId); 

    // 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, texture.getImageWidth(), texture.getImageHeight(), 0, 
    GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf); 

    //then you can generate some mipmaps 

    //Setup the ST coordinate system 
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE); 
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE); 

    // Setup what to do when the texture has to be scaled 
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); 
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_NEAREST_MIPMAP_LINEAR); 

를 작동 할 수 있습니다 그리고 당신이 필요로하는 일이 texId입니다.

텍스처 사용 방법을 알고 싶습니다.).

0

내가 한 것은 이라는 소스가있는 netbeans 프로젝트에이라는 폴더가 있고 .jar를 만들 때 JarSplice와 함께 사용하여 lib와 native를로드했습니다. 그런 다음 winrar로 새 .jar 파일을 열었습니다. 소스을 .jar로 드래그하고 .jar을 실행할 때마다 jar 파일 내의 폴더를 사용합니다. 소스는 res와 같은 것이지만 이름을 바꿨습니다.

기본적으로 res 폴더를 .jar에 넣으면 작동합니다.

관련 문제