# 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

BIN
app/background.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

View File

@@ -14,6 +14,9 @@ plugins {
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
flatDir {
dirs("$rootProject.projectDir/libs")
}
}
dependencies {
@@ -31,6 +34,10 @@ dependencies {
implementation 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
implementation "io.github.spair:imgui-java-app:1.88.0"
implementation ":PNG-library"
runtimeOnly "org.lwjgl:lwjgl-stb::natives-windows"
}
application {

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");
}
}

View File

@@ -26,6 +26,12 @@ public class Main extends Application {
Fonts.createFonts();
stateMachine.pushState(new MainMenu(stateMachine));
}
@Override
protected void preRun() {
super.preRun();
Images.loadImages();
}
@Override
public void process() {

View File

@@ -2,6 +2,7 @@ package gui.menu;
import java.util.Stack;
import gui.Images;
import imgui.ImGui;
import imgui.ImVec2;
import imgui.flag.ImGuiKey;
@@ -41,6 +42,12 @@ public class StateMachine {
var displaySize = ImGui.getIO().getDisplaySize();
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
ImGui.setNextWindowSize(displaySize);
ImGui.begin("Background", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground | ImGuiWindowFlags.NoBringToFrontOnFocus | ImGuiWindowFlags.NoInputs);
ImGui.image(Images.BACKGROUND, displaySize, new ImVec2(displaySize.x / 100, displaySize.y / 100));
ImGui.end();
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
ImGui.setNextWindowSize(displaySize);
ImGui.begin("##Main Window", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground);
menus.get(menus.size() - 1).render();

BIN
libs/PNG-library.jar Normal file

Binary file not shown.