Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Classe creata da me per semplificare la gestione delle texture
- */
- import org.newdawn.slick.opengl.Texture;
- import org.newdawn.slick.opengl.TextureLoader;
- import org.newdawn.slick.util.ResourceLoader;
- import org.lwjgl.opengl.GL11;
- import static org.lwjgl.opengl.GL11.*;
- class ImageObject
- {
- private String name;
- private Texture image;
- private int x;
- private int y;
- public ImageObject(String name, String image, String imagetype) throws java.io.IOException
- {
- this.name = name;
- this.image = TextureLoader.getTexture(imagetype,ResourceLoader.getResourceAsStream(image));
- }
- public boolean setImage(String image, String imagetype)
- {
- try{
- this.image = TextureLoader.getTexture(imagetype,ResourceLoader.getResourceAsStream(image));
- return true;
- }
- catch(Exception e)
- {
- return false;
- }
- }
- public void setX(int x){ this.x = x;}
- public void setY(int y){ this.y = y;}
- public int getX(){ return x;}
- public int getY(){ return y;}
- public void bind()
- {
- image.bind();
- glBegin(GL_QUADS);
- glTexCoord2f(0,0);//parti della texture da inizializzare rispetto ai vertici
- glVertex2f(x,y);//primo vertice
- glTexCoord2f(1,0);
- glVertex2f(x+image.getTextureWidth(),y);//secondo vertice
- glTexCoord2f(1,1);
- glVertex2f(x+image.getTextureWidth(),y+image.getTextureHeight());//terzo vertice
- glTexCoord2f(0,1);
- glVertex2f(x,y+image.getTextureHeight());//quarto vertice
- glEnd();
- }
- }
Add Comment
Please, Sign In to add comment