I am following a youtube tutorial about making an rpg in Java with OpenGL.
Now I am slowly getting ahead, and there is no GUI type tutorial yet so I want to add some text to say my stats and other stuff.
Here is the main class of my code
package com.base.engine;
import static org.lwjgl.opengl.GL11.GL_COLOR_BUFFER_BIT;
import static org.lwjgl.opengl.GL11.GL_DEPTH_TEST;
import static org.lwjgl.opengl.GL11.GL_MODELVIEW;
import static org.lwjgl.opengl.GL11.GL_PROJECTION;
import static org.lwjgl.opengl.GL11.glClear;
import static org.lwjgl.opengl.GL11.glClearColor;
import static org.lwjgl.opengl.GL11.glDisable;
import static org.lwjgl.opengl.GL11.glLoadIdentity;
import static org.lwjgl.opengl.GL11.glMatrixMode;
import static org.lwjgl.opengl.GL11.glOrtho;
import java.util.ArrayList;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import com.base.game.GUI;
import com.base.game.Game;
import com.base.game.Time;
public class Main {
public static Game game;
private static GUI gui;
public static void main(String[] args){
initDisplay();
initGL();
initGame();
gui = new GUI("i");
gameLoop();
cleanUp();
}
public static ArrayList<GameObject> sphereCollide(float x, float y, float radius)
{
return game.sphereCollide(x, y, radius);
}
public static ArrayList<GameObject> rectangleCollide(float x1, float y1, float x2, float y2)
{
return game.rectangleCollide(x1,y1,x2,y2);
}
public static void initGame(){
game = new Game();
}
public static void getInput(){
game.getInput();
}
public static void update(){
game.update();
}
public static void render(){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
game.render();
gui.drawText("Welcome to the jungle!");
Display.update();
Display.sync(60);
}
public static void cleanUp(){
Display.destroy();
Keyboard.destroy();
}
public static void gameLoop(){
Time.init();
while(!Display.isCloseRequested())
{
Time.update();
getInput();
update();
render();
}
}
public static void initGL(){
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, Display.getWidth(), 0, Display.getHeight(), -1, 1);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glClearColor(0, 0, 0, 0);
glDisable(GL11.GL_TEXTURE_2D);
}
public static void initDisplay(){
try {
Display.setDisplayMode(new DisplayMode(800,600));
Display.create();
Keyboard.create();
Display.setVSyncEnabled(true);
} catch (LWJGLException e) {
e.printStackTrace();
}
}
}
Here is the GUI class I kinda made.
package com.base.game;
import java.awt.Font;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL11.*;
import org.newdawn.slick.Color;
import org.newdawn.slick.TrueTypeFont;
import com.base.engine.Main;
/**
* @author Owen Butler
*/
public class GUI {
private TrueTypeFont font;
private TrueTypeFont font2;
public GUI(String text) {
// load a default java font
Font awtFont = new Font("Times New Roman", Font.BOLD, 24);
font = new TrueTypeFont(awtFont, false);
}
public void drawText(String text)
{
font.drawString((int)100, (int)50, "THE LIGHTWEIGHT JAVA GAMES LIBRARY", Color.yellow);
}
}
Now this works in a since. It adds something to the screen, but not text, instead it adds a yellow box. No text at all.