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:

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.

First, afaik there is no "TextureLoader" class in LWJGL, are you using some external library?Second, not related to the problem but I don't think it's a good idea to create textures in a loop, textures should be created only once then used multiple times after creation. Except that your drawString method is called only once, which I don't think is the case.

- Don't create strings with new String[]- Don't create a new Texture object every frame.. that will be slow. Generally you should try to never allocate new objects within your game loop.- Use a proper bitmap font renderer instead of rendering each glyph as its own texture. For example:https://github.com/mattdesl/lwjgl-basics

Yeah, noticed I forgot to mention that I used slick-util for the TextureLoader. I don't know how to edit posts though. Anyway, i've been trying to figure this out, and if I load a texture in the constructor of my MainComponent they display just fine. So should I just load ALL the textures at once on startup into the Texture[] array and then use them as needed? Btw thanks SO MUCH just for replying this has been bugging me SO BAD(no pun intended)

@davedes I saw many posts on the web about making one 256x256 texture with the whole font on it, each character in a 16x16 square, and I tried to use that. My idea was when using the glTexCoord(x,y) to use a floating point to specify which character I wanted. I figured since the chars were 16px long and the whole thing was 256px, in order to map the second(to the right) char of the very top row, the coords would be(0.0625, 0), being that the length of one char was 0.0625(1/16). But, i was getting stretched images of several chars at once, so I switched to the individual characters.

I'm wayyy confused; What is glCoord() doing? Is it like glVertex()? Because if i divided the actual plotting point by 256, i'd be way off of the desired drawing point.

EDIT: Okay, now I get it, the x and y refer to the individual characters. Like the top right would be (16,0). Okay. So now, i'll use a HashMap to connect the characters to their corresponding (x,y) coords and then use that to pick and draw the character. Sweet!

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org