Guest User

Untitled

a guest
May 26th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. package pressure;
  2.  
  3. import pressure.screen.Screen;
  4.  
  5. import java.awt.Font;
  6. import java.io.InputStream;
  7.  
  8. import org.lwjgl.LWJGLException;
  9. import org.lwjgl.Sys;
  10. import org.lwjgl.opengl.Display;
  11. import org.lwjgl.opengl.DisplayMode;
  12. import org.lwjgl.opengl.GL11;
  13.  
  14. import org.newdawn.slick.Color;
  15. import org.newdawn.slick.TrueTypeFont;
  16. import org.newdawn.slick.util.ResourceLoader;
  17.  
  18. public class Main {
  19.  
  20.     public static Screen screen = new Screen();
  21.     public static TrueTypeFont font;
  22.     private boolean antiAlias = true;
  23.     long lastFrame, lastFPS;
  24.     int fps, currentFPS;
  25.  
  26.     public void start() {
  27.         initGL(464, 240);
  28.         init();
  29.  
  30.         while (true) {
  31.             GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
  32.             render();
  33.  
  34.             Display.update();
  35.             Display.sync(100);
  36.  
  37.             if (Display.isCloseRequested()) {
  38.                 Display.destroy();
  39.                 System.exit(0);
  40.             }
  41.         }
  42.     }
  43.  
  44.     private void initGL(int Width, int Height) {
  45.         try {
  46.             Display.setDisplayMode(new DisplayMode(Width, Height));
  47.             Display.create();
  48.             Display.setTitle("Pressure");
  49.             //Display.setVSyncEnabled(true);
  50.         } catch (LWJGLException e) {
  51.             e.printStackTrace();
  52.             System.exit(0);
  53.         }
  54.  
  55.         GL11.glClearColor(Palette.BACK_MAIN.getRed() / 255.f, Palette.BACK_MAIN.getGreen() / 255.f, Palette.BACK_MAIN.getBlue() / 255.f, 1f);
  56.  
  57.         GL11.glEnable(GL11.GL_TEXTURE_2D);
  58.         GL11.glShadeModel(GL11.GL_SMOOTH);
  59.         GL11.glDisable(GL11.GL_DEPTH_TEST);
  60.         GL11.glDisable(GL11.GL_LIGHTING);
  61.  
  62.         GL11.glClearDepth(1);
  63.  
  64.         GL11.glEnable(GL11.GL_BLEND);
  65.         GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
  66.  
  67.         GL11.glViewport(0, 0, Width, Height);
  68.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  69.  
  70.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  71.         GL11.glLoadIdentity();
  72.         GL11.glOrtho(0, Width, Height, 0, 1, -1);
  73.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  74.     }
  75.  
  76.     public void init() {
  77.         lastFPS = getTime();
  78.  
  79.         try {
  80.             InputStream inputStream = ResourceLoader.getResourceAsStream("pressure/res/font.ttf");
  81.  
  82.             Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
  83.             awtFont = awtFont.deriveFont(8f);
  84.             font = new TrueTypeFont(awtFont, antiAlias);
  85.  
  86.         } catch (Exception e) {
  87.         }
  88.     }
  89.  
  90.     public void render() {
  91.         Color.white.bind();
  92.  
  93.         screen.placeString(3, 1, "It just werks");
  94.        
  95.         screen.placeString(1, 3, "FPS: " + currentFPS);
  96.  
  97.         screen.render();
  98.  
  99.         updateFPS();
  100.     }
  101.  
  102.     public long getTime() {
  103.         return (Sys.getTime() * 1000) / Sys.getTimerResolution();
  104.     }
  105.  
  106.     public void updateFPS() {
  107.         if (getTime() - lastFPS > 1000) {
  108.             currentFPS = fps;
  109.             fps = 0;
  110.             lastFPS += 1000;
  111.         }
  112.         fps++;
  113.     }
  114.  
  115.     public static void main(String[] argv) {
  116.         Main main = new Main();
  117.         main.start();
  118.     }
  119. }
Add Comment
Please, Sign In to add comment