Advertisement
AL4ST4I2

TextureRect.class

Oct 24th, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.59 KB | None | 0 0
  1. package com.Uni.main.lib;
  2.  
  3.  
  4. import com.Uni.main.Rettangolo;
  5. import org.lwjgl.opengl.Display;
  6. import org.lwjgl.opengl.GL11;
  7. import org.newdawn.slick.opengl.Texture;
  8. import org.newdawn.slick.opengl.TextureLoader;
  9.  
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import java.io.IOException;
  13.  
  14. public class TextureRect extends Rettangolo {
  15.  
  16.     private static Texture texture;
  17.     private final String imagePath;
  18.     private static char c = ' ';
  19.  
  20.     public TextureRect(int x, int y, int width, int heigth,
  21.                        String path)
  22.     {
  23.  
  24.         super(x, y, width, heigth, c);
  25.         this.imagePath = path;
  26.     }
  27.  
  28.     public void loadImagine()
  29.     {
  30.         try {
  31.             // Load the wood texture from "res/images/wood.png"
  32.             texture = TextureLoader.getTexture("PNG", new FileInputStream(new File(imagePath)));
  33.         } catch (IOException e) {
  34.             e.printStackTrace();
  35.             Display.destroy();
  36.             System.exit(1);
  37.         }
  38.     }
  39.  
  40.     @Override
  41.     public void renderRect()
  42.     {
  43.         texture.bind();
  44.         GL11.glBegin(GL11.GL_QUADS);
  45.             GL11.glTexCoord2f(0, 0);
  46.             GL11.glVertex2i(xUpperLeft            , yUpperLeft           );
  47.             GL11.glTexCoord2f(1, 0);
  48.             GL11.glVertex2i(xUpperLeft + larghezza, yUpperLeft           );
  49.             GL11.glTexCoord2f(1, 1);
  50.             GL11.glVertex2i(xUpperLeft + larghezza, yUpperLeft + altezza);
  51.             GL11.glTexCoord2f(1, 1);
  52.             GL11.glVertex2i(xUpperLeft            , yUpperLeft + altezza);
  53.         GL11.glEnd();
  54.  
  55.     }
  56.  
  57.  
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement