Advertisement
Guest User

Untitled

a guest
Mar 12th, 2014
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.55 KB | None | 0 0
  1.     public static Texture loadTexture(String fileName){
  2.     InputStream in = null;
  3.     System.out.println("TEXTURE TEXTURE TEXTURE " + getJarPath().substring(1, getJarPath().length() - 4) + "/res/texture/" + fileName);
  4.  
  5.     try{
  6.         in = new FileInputStream(new File(getJarPath().substring(1, getJarPath().length() - 4) + "/res/texture/" + fileName));
  7.  
  8.         PNGDecoder decoder = new PNGDecoder(in);
  9.  
  10.         ByteBuffer buf = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
  11.         decoder.decode(buf, decoder.getWidth() * 4, Format.RGBA);
  12.         buf.flip();
  13.  
  14.  
  15.  
  16.         int texID = GL11.glGenTextures();
  17.         GL13.glActiveTexture(GL13.GL_TEXTURE0);
  18.         GL11.glBindTexture(GL11.GL_TEXTURE_2D, texID);
  19.  
  20.         GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, texID);
  21.  
  22.         GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buf);
  23.  
  24.         GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
  25.  
  26.         GL11.glTexParameteri(GL11.GL_TEXTURE_2D,  GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
  27.         GL11.glTexParameteri(GL11.GL_TEXTURE_2D,  GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
  28.  
  29.         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_NEAREST);
  30.         GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR_MIPMAP_LINEAR);
  31.  
  32.         return new Texture(texID);
  33.     }catch(Exception e){
  34.         e.printStackTrace();
  35.     }finally{
  36.         try {
  37.         in.close();
  38.         } catch (IOException e) {
  39.         e.printStackTrace();
  40.         }
  41.     }
  42.  
  43.     return null;
  44.  
  45.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement