package engine;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
public class Window {
private static String title = "Ultimate Tetris";
private static String version = "Alpha";
private int width;
private int height;
private boolean fullScreen;
private boolean vSync;
public static boolean play = true;
public Window(){
//Load Settings
Settings settings = new Settings();
fullScreen = settings.getFullScreen();
width = settings.getScreenWith();
height = settings.getScreenWith();
vSync = settings.getVSync();
//Initialize Game Settings
initialize();
}
public void initialize(){
try{
//Load Window
if(fullScreen){
Display.setFullscreen(fullScreen);
}else{
Display.setDisplayMode(new DisplayMode(width, height));
}
Display.setTitle(title + " " + version);
Display.setVSyncEnabled(true);
Display.create();
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glDisable(GL11.GL_DEPTH_TEST);
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);
}catch(LWJGLException e){
e.printStackTrace();
System.out.println("GAME EXITING\nFAILED TO INITIALIZE GAME DATA!");
System.out.println("Error: Window.initialize() " + e);
Window.play = false;
System.exit(0);
}
}
public static void main(String[] args){
new Window();
GameState state = new GameState();
while(play && !Display.isCloseRequested()){
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
state.updateGameState();
Display.update();
Display.sync(100);
}
Display.destroy();
}
}
package engine;
import org.lwjgl.Sys;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import java.awt.Font;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
public class Debug {
private int fps = 0;
private String FPS = "";
private long lastLoopTime = getTime();
private long lastFPSTime;
private static long timerTicksPerSecond = Sys.getTimerResolution();
private TrueTypeFont font;
public boolean debugON = false;
public Debug(){
Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
font = new TrueTypeFont(awtFont, true);
}
private long getTime(){
return (Sys.getTime() * 1000) / timerTicksPerSecond;
}
private void sleep(long time){
try{
Thread.sleep((time * timerTicksPerSecond) / 1000);
}catch(InterruptedException e){
e.printStackTrace();
System.out.println("Error: Debug.sleep() " + e);
}
}
public String getOSVersion(){
return System.getProperty("os.version");
}
public String getOSName(){
return System.getProperty("os.name");
}
public String getOSType(){
return System.getProperty("os.arch");
}
public String getJavaVersion(){
return System.getProperty("java.version");
}
public String getJavaVendor(){
return System.getProperty("java.vendor");
}
public String getMaxRAM(){
return Long.toString(Runtime.getRuntime().maxMemory()) + " bytes";
}
public String getTotalRAM(){
return Long.toString(Runtime.getRuntime().totalMemory()) + " bytes";
}
public String getFreeRAM(){
return Long.toString(Runtime.getRuntime().freeMemory()) + " bytes";
}
public String getCPUCores(){
return Integer.toString(Runtime.getRuntime().availableProcessors());
}
public String getFPS(){
return FPS;
}
public String getMousePosition(){
return "X: " + Mouse.getX() + " Y: " + Mouse.getY();
}
public void calculateFPS(){
long delta = getTime() - lastLoopTime;
lastLoopTime = getTime();
lastFPSTime += delta;
fps++;
if(lastFPSTime >= 1000){
FPS = Integer.toString(fps);
lastFPSTime = 0;
fps = 0;
}
}
public void draw(){
font.drawString(10, 10, "Hello World");
}
}
My code is based off of the tutorial created by NeHe (http://lwjgl.org/wiki/index.php?title=Slick-Util_Library_-Part_3-_TrueType_Fonts_for_LWJGL), and it works when I tested it out as exactly shown on the website, but when I tried to integrate it into my game engine, it no longer works.