Guest User

Untitled

a guest
Jun 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. /*
  2.     Classe creata da me per semplificare la gestione delle texture
  3. */
  4.  
  5. import org.newdawn.slick.opengl.Texture;
  6. import org.newdawn.slick.opengl.TextureLoader;
  7. import org.newdawn.slick.util.ResourceLoader;
  8. import org.lwjgl.opengl.GL11;
  9.  
  10. import static org.lwjgl.opengl.GL11.*;
  11. class ImageObject
  12. {
  13.     private String name;
  14.     private Texture image;
  15.     private int x;
  16.     private int y;
  17.    
  18.     public ImageObject(String name, String image, String imagetype) throws java.io.IOException
  19.     {
  20.         this.name = name;
  21.         this.image = TextureLoader.getTexture(imagetype,ResourceLoader.getResourceAsStream(image));
  22.     }
  23.     public boolean setImage(String image, String imagetype)
  24.     {
  25.         try{
  26.             this.image = TextureLoader.getTexture(imagetype,ResourceLoader.getResourceAsStream(image));
  27.             return true;
  28.         }
  29.         catch(Exception e)
  30.         {
  31.             return false;
  32.         }
  33.        
  34.     }
  35.     public void setX(int x){ this.x = x;}
  36.     public void setY(int y){ this.y = y;}
  37.     public int getX(){ return x;}
  38.     public int getY(){ return y;}
  39.     public void bind()
  40.     {
  41.         image.bind();
  42.         glBegin(GL_QUADS);
  43.             glTexCoord2f(0,0);//parti della texture da inizializzare rispetto ai vertici
  44.             glVertex2f(x,y);//primo vertice
  45.             glTexCoord2f(1,0);
  46.             glVertex2f(x+image.getTextureWidth(),y);//secondo vertice
  47.             glTexCoord2f(1,1);
  48.             glVertex2f(x+image.getTextureWidth(),y+image.getTextureHeight());//terzo vertice
  49.             glTexCoord2f(0,1);
  50.             glVertex2f(x,y+image.getTextureHeight());//quarto vertice
  51.         glEnd();
  52.     }
  53. }
Add Comment
Please, Sign In to add comment