Advertisement
Fga

Artist Class -27 episode

Fga
Jul 28th, 2015
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package helpers;
  2.  
  3. import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
  4. import static org.lwjgl.opengl.GL11.GL_PROJECTION;
  5. import static org.lwjgl.opengl.GL11.GL_QUADS;
  6. import static org.lwjgl.opengl.GL11.glBegin;
  7. import static org.lwjgl.opengl.GL11.glEnd;
  8. import static org.lwjgl.opengl.GL11.glLoadIdentity;
  9. import static org.lwjgl.opengl.GL11.glMatrixMode;
  10. import static org.lwjgl.opengl.GL11.glOrtho;
  11. import static org.lwjgl.opengl.GL11.glVertex2f;
  12. import static org.lwjgl.opengl.GL11.*;
  13.  
  14. import java.io.IOException;
  15. import java.io.InputStream;
  16.  
  17. import org.lwjgl.LWJGLException;
  18. import org.lwjgl.opengl.Display;
  19. import org.lwjgl.opengl.DisplayMode;
  20. import org.newdawn.slick.opengl.Texture;
  21. import org.newdawn.slick.opengl.TextureLoader;
  22. import org.newdawn.slick.util.ResourceLoader;
  23.  
  24. public class Artist {
  25.  
  26.     public static final int WIDTH = 1280, HEIGHT = 960;
  27.    
  28.     public static void BeginSession() {
  29.         Display.setTitle("Indie Programmer");
  30.         try {
  31.             Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
  32.             Display.create();
  33.         } catch (LWJGLException e) {
  34.             e.printStackTrace();
  35.         }
  36.        
  37.         glMatrixMode(GL_PROJECTION);
  38.         glLoadIdentity();
  39.         glOrtho(0, WIDTH, HEIGHT, 0, 1, -1);
  40.         glMatrixMode(GL_MODELVIEW);
  41.         glEnable(GL_TEXTURE_2D);
  42.         glEnable(GL_BLEND);
  43.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  44.        
  45.     }
  46.    
  47.     public static void DrawQuad(float x, float y, float width, float height) {
  48.         glBegin(GL_QUADS);
  49.         glVertex2f(x, y); //Top left corner
  50.         glVertex2f(x + width, y); //Top right corner
  51.         glVertex2f(x + width, y + height); //Bottom right corner
  52.         glVertex2f(x, y + height); //Bottom left corner
  53.         glEnd();
  54.     }
  55.    
  56.     public static void DrawQuadTex(Texture tex, float x, float y, float width, float height) {
  57.         tex.bind();
  58.         glTranslatef(x, y, 0);
  59.         glBegin(GL_QUADS);
  60.         glTexCoord2f(0, 0);
  61.         glVertex2f(0, 0);
  62.         glTexCoord2f(1, 0);
  63.         glVertex2f(width, 0);
  64.         glTexCoord2f(1, 1);
  65.         glVertex2f(width, height);
  66.         glTexCoord2f(0, 1);
  67.         glVertex2f(0, height);
  68.         glEnd();
  69.         glLoadIdentity();
  70.     }
  71.    
  72.     public static Texture LoadTexture(String path, String fileType) {
  73.         Texture tex = null;
  74.         InputStream in = ResourceLoader.getResourceAsStream(path);
  75.         try {
  76.             tex = TextureLoader.getTexture(fileType, in);
  77.         } catch (IOException e) {
  78.             e.printStackTrace();
  79.         }
  80.         return tex;
  81.     }
  82.    
  83.     public static Texture QuickLoad(String name) {
  84.         Texture tex = null;
  85.         tex = LoadTexture("res/" + name + ".png", "PNG");
  86.         return tex;
  87.     }
  88.    
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement