Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static Texture loadTexture(String fileName){
- InputStream in = null;
- System.out.println("TEXTURE TEXTURE TEXTURE " + getJarPath().substring(1, getJarPath().length() - 4) + "/res/texture/" + fileName);
- try{
- in = new FileInputStream(new File(getJarPath().substring(1, getJarPath().length() - 4) + "/res/texture/" + fileName));
- PNGDecoder decoder = new PNGDecoder(in);
- ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
- decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
- buf.flip();
- int texID = GL11.glGenTextures();
- GL13.glActiveTexture(GL13.GL_TEXTURE0);
- GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
- GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, texID);
- GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
- GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
- GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
- 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_MIPMAP_LINEAR);
- return new Texture(texID);
- }catch(Exception e){
- e.printStackTrace();
- }finally{
- try {
- in.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- return null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement