I am writing some very basic code, which will take mouse clicks, and put vertexes at them. When I use a superclass that I wrote called BasicLWJGLapp then my process method throws a NullPointerException. When I copypasta the classes into a single class, the error is not thrown. What is causing a NullPointerException of MyLWJGLapp.java:38? Thanks in advance!
Superclass:
package BasicLWJGL;
import static org.lwjgl.opengl.GL11.*;
import org.lwjgl.LWJGLException;
import org.lwjgl.Sys;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class BasicLWJGLapp {
int notfps = 0;
long lastFrame = 0;
long lastFPS = 0;
public int fps = 0;
public BasicLWJGLapp(int width, int height, boolean startfull, boolean fullResolution, String displayTitle, boolean fpsInTitle)
{
try{
setDisplayMode(width, height, fullResolution, startfull);
Display.create();
}catch (LWJGLException e){
e.printStackTrace();
System.exit(0);
}
lastFPS = getTime();
setup(width, height);
Display.setTitle(displayTitle);
while(!Display.isCloseRequested()){
draw();
Display.update();
updateFPS();
process();
if(!startfull)
Display.sync(Display.getDesktopDisplayMode().getFrequency());
if(fpsInTitle)
Display.setTitle(displayTitle+" FPS: "+fps);
}
Display.destroy();
}
public BasicLWJGLapp(int width, int height, String displayTitle)
{
this(width, height, false, true, displayTitle, false);
}
public BasicLWJGLapp(String displayTitle)
{
this(854, 480, displayTitle);
}
public BasicLWJGLapp()
{
this("LWJGL");
}
public final void setDisplayMode(int width, int height, boolean fullResolution, boolean fullScreen)
{
try{
if(fullScreen){
if(fullResolution)
Display.setDisplayMode(Display.getDesktopDisplayMode());
else
Display.setDisplayMode(new DisplayMode(width, height));
Display.setFullscreen(fullScreen);
Display.setVSyncEnabled(fullScreen);
}else{
Display.setDisplayMode(new DisplayMode(width, height));
}
}catch (LWJGLException e){
e.printStackTrace();
System.exit(0);
}
}
private void updateFPS()
{
if(getTime()-lastFPS>1000){
fps = notfps;
notfps = 0;
lastFPS += 1000;
}
notfps++;
}
private long getDelta()
{
long delta = getTime()-lastFrame;
lastFrame = getTime();
return delta;
}
public final long getTime()
{
return (Sys.getTime()*1000)/Sys.getTimerResolution();
}
private void setup(int width, int height)
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, 1, -1);
glMatrixMode(GL_MODELVIEW);
}
public void process()
{
}
public void draw()
{
glBegin(GL_QUADS);
int ten = 10;
int twen = 20;
glVertex2i(ten, ten);
glVertex2i(twen, ten);
glVertex2i(twen, twen);
glVertex2i(ten, twen);
glEnd();
}
}
Subclass (that is run by my runner)
package my;
import java.util.ArrayList;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.Display;
import BasicLWJGL.BasicLWJGLapp;
import static org.lwjgl.opengl.GL11.*;
public class MyLWJGLapp extends BasicLWJGLapp{
ArrayList<int[]> coords = new ArrayList<int[]>();
public MyLWJGLapp()
{
super("My App");
}
public void draw(){
glBegin(GL_POINTS);
try{
for(int[] a : coords){
glVertex2i(a[0], a[1]);
}
}catch(NullPointerException f*ckyou){}
glEnd();
process();
}
public void process()
{
while(Mouse.next()){
if(Mouse.getEventButton()==0){
coords.add(new int[] {Mouse.getX(), Mouse.getY()});
}else if(Mouse.getEventButton()==1) {
coords.clear();
}
}
}
}