bye bye png lib
This commit is contained in:
@@ -35,7 +35,7 @@ dependencies {
|
||||
|
||||
implementation "io.github.spair:imgui-java-app:1.88.0"
|
||||
|
||||
implementation ":PNG-library"
|
||||
implementation "org.lwjgl:lwjgl-stb:3.3.4"
|
||||
|
||||
runtimeOnly "org.lwjgl:lwjgl-stb::natives-windows"
|
||||
}
|
||||
|
||||
@@ -1,47 +1,20 @@
|
||||
package gui;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.IntBuffer;
|
||||
import java.nio.LongBuffer;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import io.nayuki.png.ImageDecoder;
|
||||
import io.nayuki.png.PngImage;
|
||||
import io.nayuki.png.image.BufferedRgbaImage;
|
||||
import org.lwjgl.stb.STBImage;
|
||||
|
||||
public class Images {
|
||||
|
||||
public static int BACKGROUND;
|
||||
|
||||
private static int loadTexture(String fileName) {
|
||||
// Decoding
|
||||
PngImage png = null;
|
||||
try {
|
||||
png = PngImage.read(new File(fileName));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
return -1;
|
||||
}
|
||||
BufferedRgbaImage img = (BufferedRgbaImage) ImageDecoder.toImage(png);
|
||||
ByteBuffer pixels = ByteBuffer.allocateDirect(img.getWidth() * img.getHeight() * Long.BYTES);
|
||||
for (int y = 0; y < img.getHeight(); y++) {
|
||||
for (int x = 0; x < img.getWidth(); x++) {
|
||||
long value = img.getPixel(x, y);
|
||||
int red = (int) ((value >> 48) & 0xFF);
|
||||
int blue = (int) ((value >> 32) & 0xFF);
|
||||
int green = (int) ((value >> 16) & 0xFF);
|
||||
int alpha = 255;
|
||||
pixels.putInt(red << 24 | green << 16 | blue << 8 | alpha);
|
||||
}
|
||||
}
|
||||
pixels.flip();
|
||||
int[] width = new int[1];
|
||||
int[] height = new int[1];
|
||||
int[] channelCount = new int[1];
|
||||
|
||||
var caca = img.getBitDepths();
|
||||
System.out.println(caca);
|
||||
ByteBuffer pixels = STBImage.stbi_load(fileName, width, height, channelCount, 4);
|
||||
|
||||
int textureID = GL11.glGenTextures();
|
||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
|
||||
@@ -51,7 +24,7 @@ public class Images {
|
||||
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, img.getWidth(), img.getHeight(), 0,
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user