I’m doing a test for getting a font in Java, basically getting a larger png of the alphabet, then cut it into smaller parts to get each individual letter as a separate subImage. So far I was using BufferedImage and java.awt.Graphics.
However, I’m planning on using LWJGL in the future, and would like to get more familiar with it(for this test I’m even creating the display with LWJGL), and would like to know if there was an equivalent of subImages in LWJGL’s OpenGL. I’d prefer not to get slick.
Here’s the image, just in case it helps:
https://i.stack.imgur.com/nFPQp.png
And here is the code I’m using, it could help.
package typeandscreen;
*imports go here, cut to save space*
public class Font{
final int width = 78;
final int height = 12;
final int rows = 2;
final int cols = 13;
BufferedImage letters[] = new BufferedImage[rows*cols];
void test(){
try{
final BufferedImage totalImage = ImageIO.read(new File("ABCabcs.png"));
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
letters[(i * cols) + j] = totalImage.getSubimage(
j * width,
i * height,
width,
height
);
}
}
} catch(IOException e){
e.printStackTrace();
}
}
}
I’m not sure about a specific method, but here is my method to support Spritesheets…
First I load the entire image into a single Texture, I then assign a few variables to help determine which part of the Sprite sheet I want to display with the following method:
The last two variables allow me to have a spritesheet with variable cell sizes.
Then my Sprite rendering method looks like the following…
Which will draw the correct cell (or cells) of the Spritesheet.