I recevie 0 errors but I get this in the console:
>Exception in thread "main" java.lang.NullPointerException
>>at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:2052)
>>>at game.engine.GameLoop.start(GameLoop.java:22)
>>>>at game.engine.GameLoop.main(GameLoop.java:15)
I tried to put the actual value into “glMatrixMode()” instead of “GL11.GL_PROJECTION” but it returns same Exception.
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.Display;
public class GameLoop
{
//Main
public static void main(String[] argv)
{
GameLoop.start();
}
//Metodo che gestisce il loop
public static void start()
{
//Inizializzazione OpenGL
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, 800, 600, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
try
{
Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
} catch (LWJGLException e)
{
e.printStackTrace();
System.exit(0);
}
while(!Display.isCloseRequested())
{
Entità.pulisci();
Entità.colora();
Entità.disegna();
Display.update();
}
}
}
import org.lwjgl.opengl.GL11;
public class Entità
{
//Disegna un poligono
public static void disegna()
{
GL11.glBegin(GL11.GL_QUADS);
GL11.glVertex2f(100,100);
GL11.glVertex2f(200,100);
GL11.glVertex2f(200,200);
GL11.glVertex2f(100,200);
GL11.glEnd();
}
//Pulisce il buffer
public static void pulisci()
{
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
}
//Setta il colore al poligono
public static void colora()
{
GL11.glColor3f(0.5f,0.5f,1.0f);
}
}
I don’t have any experience with Java or LWJGL, but from looking at your code it seems
creates the actual display canvas (or however you may call it) which also sets up the OpenGL context. Thus calling any OpenGL function (like
GL11.glMatrixMode) before those is likely to result in some error, as in your case a null pointer exception.So try to put those four functions after the display creation. You are making changes to the OpenGL context, thus you first need a valid context.