Is it possible to load PNG Textures and draw Strings in LWJGL WITHOUT using the Slick Framework?
Everytime I google “how to load png images in lwjgl” I get answers like this -> “hey just use the textureloader from the slick framework”.
Same for “how to draw strings in lwjgl” -> “just use the TTFFont Class from the slick framework”
But I don’t want to use this half-way-crossframework design. Because I don’t think that this is the best way.
Are there any Libraries or Extensions for LWJGL that are only made for Textures or Strings?
Basically, you take a
BufferedImage, use getRGB() to get the RGB of each pixel, take that data and put it into a ByteBuffer (the data type used to input image data to OpenGL), set some texture data, and create theGL_TEXTURE_2D.This code by Krythic does it:
To use this code, do something like this:
You can either save the textureID as a
finalvariable(if the texture never changes), or unload the texture after each render usingGL11.glDeleteTextures(textureID);To do text, just create a
BufferedImagemanually, and use createGraphics() to get a graphics2D() instance for the image. Then, usedrawString()to draw onto theBufferedImage, load it into theTextureLoader, render it onscreen, and unload the texture using the method above.