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 "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"
|
runtimeOnly "org.lwjgl:lwjgl-stb::natives-windows"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +1,20 @@
|
|||||||
package gui;
|
package gui;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.IntBuffer;
|
|
||||||
import java.nio.LongBuffer;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.stb.STBImage;
|
||||||
|
|
||||||
import io.nayuki.png.ImageDecoder;
|
|
||||||
import io.nayuki.png.PngImage;
|
|
||||||
import io.nayuki.png.image.BufferedRgbaImage;
|
|
||||||
|
|
||||||
public class Images {
|
public class Images {
|
||||||
|
|
||||||
public static int BACKGROUND;
|
public static int BACKGROUND;
|
||||||
|
|
||||||
private static int loadTexture(String fileName) {
|
private static int loadTexture(String fileName) {
|
||||||
// Decoding
|
int[] width = new int[1];
|
||||||
PngImage png = null;
|
int[] height = new int[1];
|
||||||
try {
|
int[] channelCount = new int[1];
|
||||||
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();
|
|
||||||
|
|
||||||
var caca = img.getBitDepths();
|
ByteBuffer pixels = STBImage.stbi_load(fileName, width, height, channelCount, 4);
|
||||||
System.out.println(caca);
|
|
||||||
|
|
||||||
int textureID = GL11.glGenTextures();
|
int textureID = GL11.glGenTextures();
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureID);
|
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_PIXELS, 0); // Not on WebGL/ES
|
||||||
GL11.glPixelStorei(GL11.GL_UNPACK_SKIP_ROWS, 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.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_RGBA,
|
||||||
GL11.GL_UNSIGNED_BYTE, pixels);
|
GL11.GL_UNSIGNED_BYTE, pixels);
|
||||||
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user