Skip to content

Commit e92192b

Browse files
committed
Updated ThinGL
1 parent c57b5ef commit e92192b

File tree

4 files changed

+53
-119
lines changed

4 files changed

+53
-119
lines changed

build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ dependencies {
2727
}
2828
includeInJar "net.java.dev.jna:jna:5.17.0"
2929

30-
includeInJar("net.raphimc:thingl:0.0.6-20250602.204901-1") {
31-
exclude group: "org.slf4j", module: "slf4j-api"
32-
}
30+
includeInJar "net.raphimc:thingl:0.0.7-20250611.224829-3"
3331
includeInJar "org.lwjgl:lwjgl-glfw:3.3.6"
3432
includeInJar "org.lwjgl:lwjgl-opengl:3.3.6"
3533
includeInJar "org.lwjgl:lwjgl-freetype:3.3.6"

src/main/java/net/raphimc/noteblocktool/frames/visualizer/ExtendedThinGL.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
package net.raphimc.noteblocktool.frames.visualizer;
1919

2020
import net.raphimc.thingl.ThinGL;
21-
import net.raphimc.thingl.implementation.ApplicationInterface;
22-
import net.raphimc.thingl.implementation.WindowInterface;
21+
import net.raphimc.thingl.implementation.application.ApplicationInterface;
22+
import net.raphimc.thingl.implementation.window.WindowInterface;
2323

2424
import java.util.function.Function;
2525
import java.util.function.Supplier;

src/main/java/net/raphimc/noteblocktool/frames/visualizer/NoteBlockToolApplicationInterface.java

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/main/java/net/raphimc/noteblocktool/frames/visualizer/VisualizerWindow.java

Lines changed: 50 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -17,96 +17,31 @@
1717
*/
1818
package net.raphimc.noteblocktool.frames.visualizer;
1919

20-
import net.lenni0451.commons.logging.impl.SysoutLogger;
2120
import net.raphimc.noteblocktool.util.SoundSystemSongPlayer;
2221
import net.raphimc.thingl.ThinGL;
23-
import net.raphimc.thingl.framebuffer.impl.TextureFramebuffer;
24-
import net.raphimc.thingl.framebuffer.impl.WindowFramebuffer;
25-
import net.raphimc.thingl.implementation.DebugMessageCallback;
26-
import net.raphimc.thingl.implementation.GLFWWindowInterface;
27-
import net.raphimc.thingl.wrapper.Blending;
22+
import net.raphimc.thingl.implementation.application.StandaloneApplicationInterface;
23+
import net.raphimc.thingl.implementation.application.StandaloneApplicationRunner;
24+
import net.raphimc.thingl.implementation.window.GLFWWindowInterface;
2825
import org.joml.Matrix4fStack;
2926
import org.lwjgl.glfw.GLFW;
30-
import org.lwjgl.glfw.GLFWErrorCallback;
31-
import org.lwjgl.opengl.GL;
32-
import org.lwjgl.opengl.GL11C;
3327

34-
public class VisualizerWindow {
28+
public class VisualizerWindow extends StandaloneApplicationRunner {
3529

3630
private final DropRenderer dropRenderer;
31+
private final Runnable openCallback;
3732
private final Runnable closeCallback;
3833
private final Thread renderThread;
39-
private long window;
4034

4135
public VisualizerWindow(final SoundSystemSongPlayer songPlayer, final Runnable openCallback, final Runnable closeCallback) {
36+
super(new Configuration()
37+
.setWindowTitle("NoteBlockTool Song Visualizer - " + songPlayer.getSong().getTitleOrFileNameOr("No Title"))
38+
.setDebugMode(true)
39+
.setExtendedDebugMode(false));
40+
4241
this.dropRenderer = new DropRenderer(songPlayer);
42+
this.openCallback = openCallback;
4343
this.closeCallback = closeCallback;
44-
this.renderThread = new Thread(() -> {
45-
GLFWErrorCallback.createPrint(System.err).set();
46-
47-
if (!GLFW.glfwInit()) {
48-
throw new IllegalStateException("Unable to initialize GLFW");
49-
}
50-
51-
GLFW.glfwDefaultWindowHints();
52-
GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GLFW.GLFW_TRUE);
53-
GLFW.glfwWindowHint(GLFW.GLFW_FOCUS_ON_SHOW, GLFW.GLFW_FALSE);
54-
GLFW.glfwWindowHint(GLFW.GLFW_CLIENT_API, GLFW.GLFW_OPENGL_API);
55-
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_CREATION_API, GLFW.GLFW_NATIVE_CONTEXT_API);
56-
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 4);
57-
GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 5);
58-
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
59-
GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_FORWARD_COMPAT, GLFW.GLFW_TRUE);
60-
61-
this.window = GLFW.glfwCreateWindow(1280, 720, "NoteBlockTool Song Visualizer - " + songPlayer.getSong().getTitleOrFileNameOr("No Title"), 0L, 0L);
62-
if (this.window == 0L) {
63-
throw new RuntimeException("Failed to create the GLFW window");
64-
}
65-
openCallback.run();
66-
67-
GLFW.glfwMakeContextCurrent(this.window);
68-
GLFW.glfwSwapInterval(1);
69-
GL.createCapabilities();
70-
71-
ThinGL.LOGGER = SysoutLogger.builder().name("ThinGL").build();
72-
ThinGL.setInstance(new ExtendedThinGL(NoteBlockToolApplicationInterface::new, GLFWWindowInterface::new));
73-
DebugMessageCallback.install(false);
74-
75-
this.dropRenderer.init();
76-
77-
ThinGL.glStateManager().enable(GL11C.GL_BLEND);
78-
Blending.standardBlending();
79-
ThinGL.glStateManager().enable(GL11C.GL_DEPTH_TEST);
80-
ThinGL.glStateManager().setDepthFunc(GL11C.GL_LEQUAL);
81-
final TextureFramebuffer mainFramebuffer = new TextureFramebuffer();
82-
mainFramebuffer.setClearColor(0.5F, 0.5F, 0.5F, 0.5F);
83-
final Matrix4fStack positionMatrix = new Matrix4fStack(8);
84-
85-
while (!GLFW.glfwWindowShouldClose(this.window)) {
86-
ThinGL.get().onStartFrame();
87-
mainFramebuffer.bind(true);
88-
mainFramebuffer.clear();
89-
90-
positionMatrix.pushMatrix();
91-
this.dropRenderer.render(positionMatrix);
92-
positionMatrix.popMatrix();
93-
94-
mainFramebuffer.unbind();
95-
mainFramebuffer.blitTo(WindowFramebuffer.INSTANCE, true, false, false);
96-
ThinGL.get().onFinishFrame();
97-
GLFW.glfwSwapBuffers(this.window);
98-
GLFW.glfwPollEvents();
99-
ThinGL.get().onEndFrame();
100-
}
101-
102-
this.dropRenderer.free();
103-
ThinGL.get().free();
104-
GLFW.glfwDestroyWindow(this.window);
105-
GLFW.glfwTerminate();
106-
if (this.closeCallback != null) {
107-
this.closeCallback.run();
108-
}
109-
}, "Visualizer Render Thread");
44+
this.renderThread = new Thread(this::launch, "Visualizer Render Thread");
11045
this.renderThread.setDaemon(true);
11146
this.renderThread.start();
11247

@@ -138,4 +73,42 @@ public void close() {
13873
}
13974
}
14075

76+
@Override
77+
protected void setWindowFlags() {
78+
super.setWindowFlags();
79+
GLFW.glfwWindowHint(GLFW.GLFW_FOCUS_ON_SHOW, GLFW.GLFW_FALSE);
80+
}
81+
82+
@Override
83+
protected void createWindow() {
84+
super.createWindow();
85+
this.openCallback.run();
86+
}
87+
88+
@Override
89+
protected ThinGL createThinGL() {
90+
return new ExtendedThinGL(StandaloneApplicationInterface::new, GLFWWindowInterface::new);
91+
}
92+
93+
@Override
94+
protected void init() {
95+
super.init();
96+
this.dropRenderer.init();
97+
this.mainFramebuffer.setClearColor(0.5F, 0.5F, 0.5F, 0.5F);
98+
}
99+
100+
@Override
101+
protected void render(final Matrix4fStack positionMatrix) {
102+
this.dropRenderer.render(positionMatrix);
103+
}
104+
105+
@Override
106+
protected void free() {
107+
this.dropRenderer.free();
108+
super.free();
109+
if (this.closeCallback != null) {
110+
this.closeCallback.run();
111+
}
112+
}
113+
141114
}

0 commit comments

Comments
 (0)