Skip to content
This repository was archived by the owner on Aug 27, 2024. It is now read-only.

Commit 6bb3358

Browse files
committed
Stencil test ready
1 parent baa176e commit 6bb3358

File tree

20 files changed

+613
-183
lines changed

20 files changed

+613
-183
lines changed

src/main/java/org/overrun/swgl/core/GlfwApplication.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package org.overrun.swgl.core;
2626

27+
import org.lwjgl.glfw.GLFWErrorCallback;
2728
import org.lwjgl.opengl.GL;
2829
import org.overrun.swgl.core.gl.GLStateMgr;
2930
import org.overrun.swgl.core.io.Keyboard;
@@ -87,6 +88,11 @@ public void updateTime() {
8788
public void boot() {
8889
try {
8990
prepare();
91+
if (initialErrorCallback == null) {
92+
GLFWErrorCallback.createPrint(getDebugStream()).set();
93+
} else {
94+
GLFWErrorCallback.create(initialErrorCallback).set();
95+
}
9096
if (!glfwInit())
9197
throw new IllegalStateException("Unable to initialize GLFW");
9298

@@ -103,43 +109,42 @@ public void boot() {
103109
preStart();
104110
window = new Window();
105111
window.createHandle(initialWidth, initialHeight, initialTitle);
106-
long hWnd = window.getHandle();
107-
window.setResizeFunc((handle, width, height) -> onResize(width, height));
112+
window.setResizeCb((handle, width, height) -> onResize(width, height));
108113

109114
// Setup IO
110115
keyboard = new Keyboard();
111116
keyboard.setWindow(window);
112-
glfwSetKeyCallback(hWnd, (handle, key, scancode, action, mods) -> {
117+
window.setKeyCb((handle, key, scancode, action, mods) -> {
113118
if (action == GLFW_PRESS) onKeyPress(key, scancode, mods);
114119
else if (action == GLFW_RELEASE) onKeyRelease(key, scancode, mods);
115120
else if (action == GLFW_REPEAT) onKeyRepeat(key, scancode, mods);
116121
});
117122
mouse = new Mouse(this);
118123
mouse.registerToWindow(window);
119-
glfwSetMouseButtonCallback(hWnd, (handle, button, action, mods) -> {
124+
window.setMouseBtnCb((handle, button, action, mods) -> {
120125
if (action == GLFW_PRESS) onMouseBtnPress(button, mods);
121126
else if (action == GLFW_RELEASE) onMouseBtnRelease(button, mods);
122127
});
123-
glfwSetWindowFocusCallback(hWnd, (handle, focused) -> {
128+
window.setFocusCb((handle, focused) -> {
124129
if (!focused) mouse.firstFocus = true;
125130
});
126-
glfwSetScrollCallback(hWnd, (handle, xoffset, yoffset) -> onScroll(xoffset, yoffset));
131+
window.setScrollCb((handle, xoffset, yoffset) -> onScroll(xoffset, yoffset));
127132

128133
timer = new Timer();
129-
glfwMakeContextCurrent(hWnd);
134+
window.makeContextCurr();
130135
glfwSwapInterval(initialSwapInterval);
131136
GL.createCapabilities(true);
132137
GLStateMgr.init();
133138
start();
134-
glfwShowWindow(hWnd);
139+
window.show();
135140
postStart();
136141
int frames = 0;
137142
double lastTime = Timer.getTime();
138-
while (!glfwWindowShouldClose(hWnd)) {
143+
while (!window.shouldClose()) {
139144
updateTime();
140145
update();
141146
run();
142-
glfwSwapBuffers(hWnd);
147+
window.swapBuffers();
143148
glfwPollEvents();
144149
++frames;
145150
while (Timer.getTime() >= lastTime + 1.0) {
@@ -167,6 +172,10 @@ public void boot() {
167172
glfwTerminate();
168173
}
169174
postClose();
175+
var cb = glfwSetErrorCallback(null);
176+
if (cb != null) {
177+
cb.free();
178+
}
170179
}
171180
}
172181

src/main/java/org/overrun/swgl/core/cfg/GlobalConfig.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
import org.jetbrains.annotations.NotNull;
2828
import org.jetbrains.annotations.Nullable;
29+
import org.lwjgl.glfw.GLFWErrorCallbackI;
2930

3031
import java.io.PrintStream;
3132

@@ -56,6 +57,10 @@ public class GlobalConfig {
5657
* The swgl-core version string.
5758
*/
5859
public static final String SWGL_CORE_VERSION = SWGL_CORE_VER_MAJOR + "." + SWGL_CORE_VER_MINOR + "." + SWGL_CORE_VER_PATCH + (SWGL_CORE_VER_SNAPSHOT != 0 ? "." + SWGL_CORE_VER_SNAPSHOT : "");
60+
/**
61+
* The initial GLFW error callback.
62+
*/
63+
public static GLFWErrorCallbackI initialErrorCallback = null;
5964
/**
6065
* The initial window width.
6166
*/

0 commit comments

Comments
 (0)