45 lines
1.4 KiB
Java
45 lines
1.4 KiB
Java
package gui.constants;
|
|
|
|
import java.nio.ByteBuffer;
|
|
|
|
import org.lwjgl.opengl.GL11;
|
|
import org.lwjgl.stb.STBImage;
|
|
|
|
import gui.AssetManager;
|
|
|
|
public class Images {
|
|
|
|
public static int BACKGROUND;
|
|
|
|
private static int loadTexture(byte[] imageData) {
|
|
int[] width = new int[1];
|
|
int[] height = new int[1];
|
|
int[] channelCount = new int[1];
|
|
|
|
ByteBuffer img = ByteBuffer.allocateDirect(imageData.length);
|
|
img.put(imageData);
|
|
img.flip();
|
|
ByteBuffer pixels = STBImage.stbi_load_from_memory(img, width, height, channelCount, 4);
|
|
|
|
int textureID = GL11.glGenTextures();
|
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
|
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
|
|
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
|
|
GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 1); // Not on WebGL/ES
|
|
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_PIXELS, 0); // Not on WebGL/ES
|
|
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 0); // Not on WebGL/ES
|
|
GL11.glPixelStorei(GL11.GL_UNPACK_ROW_LENGTH, 0); // Not on WebGL/ES
|
|
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, width[0], height[0], 0,
|
|
GL11.GL_RGBA,
|
|
GL11.GL_UNSIGNED_BYTE, pixels);
|
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
|
|
|
return textureID;
|
|
}
|
|
|
|
public static void reloadImages() {
|
|
BACKGROUND = loadTexture(AssetManager.getResource(Options.BackgroundPath));
|
|
}
|
|
|
|
}
|