Okay, so I am new to LWJGL. I know Java pretty well, though. Anyway, I decided to create a clone of Pong, just to try it out, and had it working right up until I wanted to display text. Well, I just made a bunch of font files and was going to make a drawString() method. It would look like this:
public void drawString(String draw, float x, float y) {
StringTokenizer t = new StringTokenizer(draw);
String[] chars = new String[2048];
for(int i = 0;i<draw.length();i++) {
chars[i] = t.nextToken("");
}
Texture[] tex = new Texture[2048];
glEnable(GL_TEXTURE_2D);
for(int j = 0;j<draw.length();j++) {
try {
tex[j] = TextureLoader.getTexture("PNG", new FileInputStream("res/font/" + chars[j] + ".png"));
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
int o = 0;
for(int a = 0;a<tex.length;a++) {
drawRect(x+o, y, FONT_CONST, FONT_CONST, tex[a]);
}
}
But, when I run, since the score is 0 it tries to load a Texture. It doesn’t report a FileNotFound or IOException, but is passing the Texture as null, since I keep getting NullPointerExceptions from the drawRect() call. This is really confusing me; I would be very grateful for help.