# Conflicts:
#	app/src/main/java/sudoku/Main.java
#	app/src/main/java/sudoku/solver/Solver.java
This commit is contained in:
2025-01-28 17:59:15 +01:00
committed by Janet-Doe
parent b9788d6a51
commit 1930bc02bd
6 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
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;
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();
var caca = img.getBitDepths();
System.out.println(caca);
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, img.getWidth(), img.getHeight(), 0,
GL11.GL_RGBA,
GL11.GL_UNSIGNED_BYTE, pixels);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
return textureID;
}
public static void loadImages() {
BACKGROUND = loadTexture("background.png");
}
}