Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package pressure;
- import pressure.screen.Screen;
- import java.awt.Font;
- import java.io.InputStream;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.Sys;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.lwjgl.opengl.GL11;
- import org.newdawn.slick.Color;
- import org.newdawn.slick.TrueTypeFont;
- import org.newdawn.slick.util.ResourceLoader;
- public class Main {
- public static Screen screen = new Screen();
- public static TrueTypeFont font;
- private boolean antiAlias = true;
- long lastFrame, lastFPS;
- int fps, currentFPS;
- public void start() {
- initGL(464, 240);
- init();
- while (true) {
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
- render();
- Display.update();
- Display.sync(100);
- if (Display.isCloseRequested()) {
- Display.destroy();
- System.exit(0);
- }
- }
- }
- private void initGL(int Width, int Height) {
- try {
- Display.setDisplayMode(new DisplayMode(Width, Height));
- Display.create();
- Display.setTitle("Pressure");
- //Display.setVSyncEnabled(true);
- } catch (LWJGLException e) {
- e.printStackTrace();
- System.exit(0);
- }
- GL11.glClearColor(Palette.BACK_MAIN.getRed() / 255.f, Palette.BACK_MAIN.getGreen() / 255.f, Palette.BACK_MAIN.getBlue() / 255.f, 1f);
- GL11.glEnable(GL11.GL_TEXTURE_2D);
- GL11.glShadeModel(GL11.GL_SMOOTH);
- GL11.glDisable(GL11.GL_DEPTH_TEST);
- GL11.glDisable(GL11.GL_LIGHTING);
- GL11.glClearDepth(1);
- GL11.glEnable(GL11.GL_BLEND);
- GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
- GL11.glViewport(0, 0, Width, Height);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- GL11.glMatrixMode(GL11.GL_PROJECTION);
- GL11.glLoadIdentity();
- GL11.glOrtho(0, Width, Height, 0, 1, -1);
- GL11.glMatrixMode(GL11.GL_MODELVIEW);
- }
- public void init() {
- lastFPS = getTime();
- try {
- InputStream inputStream = ResourceLoader.getResourceAsStream("pressure/res/font.ttf");
- Font awtFont = Font.createFont(Font.TRUETYPE_FONT, inputStream);
- awtFont = awtFont.deriveFont(8f);
- font = new TrueTypeFont(awtFont, antiAlias);
- } catch (Exception e) {
- }
- }
- public void render() {
- Color.white.bind();
- screen.placeString(3, 1, "It just werks");
- screen.placeString(1, 3, "FPS: " + currentFPS);
- screen.render();
- updateFPS();
- }
- public long getTime() {
- return (Sys.getTime() * 1000) / Sys.getTimerResolution();
- }
- public void updateFPS() {
- if (getTime() - lastFPS > 1000) {
- currentFPS = fps;
- fps = 0;
- lastFPS += 1000;
- }
- fps++;
- }
- public static void main(String[] argv) {
- Main main = new Main();
- main.start();
- }
- }
Add Comment
Please, Sign In to add comment