Skip to content

Commit 78ffe7f

Browse files
committed
-added awtDebug flag
1 parent ee0991e commit 78ffe7f

File tree

5 files changed

+280
-9
lines changed

5 files changed

+280
-9
lines changed

src/main/kotlin/uno/awt/JawtDemo.kt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ fun main(args: Array<String>) {
124124
*
125125
* This implementation supports Windows only.
126126
*/
127-
open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
127+
open class LwjglCanvas(val glDebug: Boolean = false) : Canvas() {
128128

129129
val awt = Jawt.calloc().apply { version(JAWT_VERSION_1_4) }
130130

@@ -137,6 +137,8 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
137137

138138
var debugProc: Callback? = null
139139

140+
var awtDebug = false
141+
140142
private fun initInternal(hwnd: HWND) {
141143
// println("LwjglCanvas.initInternal ${Date().toInstant()}")
142144

@@ -145,7 +147,7 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
145147
GLFWErrorCallback.createPrint().set()
146148
glfw.init()
147149

148-
glfw.windowHint { debug = this@LwjglCanvas.debug }
150+
glfw.windowHint { debug = glDebug }
149151

150152
// glfwWindowHint can be used here to configure the GL context
151153
glfwWindow = GlfwWindow.fromWin32Window(hwnd).apply {
@@ -155,7 +157,7 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
155157

156158
glfwWindow.cursorPosCallback = { it.toString() }
157159

158-
if (debug)
160+
if (glDebug)
159161
debugProc = GLUtil.setupDebugMessageCallback()
160162

161163
glfw.swapInterval = VSync.OFF
@@ -205,7 +207,9 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
205207
var frames = 0
206208

207209
override fun paint(g: Graphics) {
208-
// println("paint " + Thread.currentThread().name)
210+
if (awtDebug) {
211+
println("paint start " + Thread.currentThread().name)
212+
}
209213

210214
// Lock the drawing surface
211215
val lock = JAWT_DrawingSurface_Lock(surface.Lock(), surface)
@@ -225,7 +229,7 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
225229
assert(hdc != NULL)
226230

227231
if (initialized)
228-
glfwWindow.makeContextCurrent()
232+
// glfwWindow.makeContextCurrent()
229233
else
230234
initInternal(HWND(surfaceInfo.hwnd()))
231235

@@ -240,13 +244,16 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
240244
}
241245

242246
// println("LwjglCanvas.render ${Date().toInstant()}")
247+
if (awtDebug) {
248+
println("paint before render ")
249+
}
243250
render()
244251
// println("/LwjglCanvas.render ${Date().toInstant()}")
245252

246253
if (swapBuffers)
247254
glfwWindow.swapBuffers()
248255

249-
if(fps) {
256+
if (fps) {
250257
val now = System.currentTimeMillis()
251258
time += now - last
252259
last = now
@@ -258,7 +265,7 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
258265
}
259266
}
260267

261-
glfwWindow.unmakeContextCurrent()
268+
//glfwWindow.unmakeContextCurrent()
262269

263270
} finally {
264271
// Free the drawing surface info
@@ -269,6 +276,10 @@ open class LwjglCanvas(val debug: Boolean = false) : Canvas() {
269276
JAWT_DrawingSurface_Unlock(surface.Unlock(), surface)
270277
}
271278

279+
if (awtDebug) {
280+
println("paint end")
281+
}
282+
272283
if (animated)
273284
repaint()
274285
}

src/main/kotlin/uno/glfw/direct fields.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ inline val GLFWVidMode.blueBits: Int
1919
inline val GLFWVidMode.refreshRate: Int
2020
get() = GLFWVidMode.nrefreshRate(address())
2121

22-
2322
inline class HWND(val L: Long)

src/main/kotlin/uno/glsl/Program.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// */
66
//
77
//
8-
//import com.jogamp.common.net.Uri
8+
//import com.jogamp.common.net.Urij
99
//import com.jogamp.opengl.GL.GL_FALSE
1010
//import com.jogamp.opengl.GL2ES2
1111
//import com.jogamp.opengl.GL2ES2.*
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//package main;
2+
//
3+
//import org.lwjgl.PointerBuffer;
4+
//import org.lwjgl.glfw.GLFWErrorCallback;
5+
//import org.lwjgl.glfw.GLFWVidMode;
6+
//import org.lwjgl.opengl.GL;
7+
//import org.lwjgl.system.MemoryStack;
8+
//
9+
//import java.nio.*;
10+
//import java.util.*;
11+
//
12+
//import static org.lwjgl.glfw.Callbacks.*;
13+
//import static org.lwjgl.glfw.GLFW.*;
14+
//import static org.lwjgl.opengl.GL11C.*;
15+
//import static org.lwjgl.system.MemoryStack.*;
16+
//import static org.lwjgl.system.MemoryUtil.*;
17+
//import static org.lwjgl.util.tinyfd.TinyFileDialogs.*;
18+
//
19+
//public final class HelloTinyFD {
20+
//
21+
// private HelloTinyFD() {
22+
// }
23+
//
24+
// public static void main(String[] args) {
25+
// GLFWErrorCallback.createPrint().set();
26+
// if (!glfwInit()) {
27+
// throw new IllegalStateException("Unable to initialize GLFW");
28+
// }
29+
//
30+
// long window = glfwCreateWindow(300, 300, "Hello tiny file dialogs!", NULL, NULL);
31+
// if (window == NULL) {
32+
// throw new RuntimeException("Failed to create the GLFW window");
33+
// }
34+
//
35+
// glfwSetKeyCallback(window, (windowHnd, key, scancode, action, mods) -> {
36+
// if (action == GLFW_RELEASE) {
37+
// return;
38+
// }
39+
//
40+
// switch (key) {
41+
// case GLFW_KEY_ESCAPE:
42+
// glfwSetWindowShouldClose(windowHnd, true);
43+
// break;
44+
// case GLFW_KEY_B:
45+
// tinyfd_beep();
46+
// break;
47+
// case GLFW_KEY_N:
48+
// System.out.println("\nOpening notification popup...");
49+
// System.out.println(tinyfd_notifyPopup("Please read...", "...this message.", "info"));
50+
// break;
51+
// case GLFW_KEY_1:
52+
// System.out.println("\nOpening message dialog...");
53+
// System.out.println(tinyfd_messageBox("Please read...", "...this message.", "okcancel", "info", true) ? "OK" : "Cancel");
54+
// break;
55+
// case GLFW_KEY_2:
56+
// System.out.println("\nOpening input box dialog...");
57+
// System.out.println(tinyfd_inputBox("Input Value", "How old are you?", "30"));
58+
// break;
59+
// case GLFW_KEY_3:
60+
// System.out.println("\nOpening file open dialog...");
61+
// System.out.println(tinyfd_openFileDialog("Open File(s)", "", null, null, true));
62+
// break;
63+
// case GLFW_KEY_4:
64+
// try (MemoryStack stack = stackPush()) {
65+
// PointerBuffer aFilterPatterns = stack.mallocPointer(2);
66+
//
67+
// aFilterPatterns.put(stack.UTF8("*.jpg"));
68+
// aFilterPatterns.put(stack.UTF8("*.png"));
69+
//
70+
// aFilterPatterns.flip();
71+
//
72+
// System.out.println("\nOpening file save dialog...");
73+
// System.out.println(tinyfd_saveFileDialog("Save Image", "", aFilterPatterns, "Image files (*.jpg, *.png)"));
74+
// }
75+
// break;
76+
// case GLFW_KEY_5:
77+
// System.out.println("\nOpening folder select dialog...");
78+
// System.out.println(tinyfd_selectFolderDialog("Select Folder", ""));
79+
// break;
80+
// case GLFW_KEY_6:
81+
// System.out.println("\nOpening color chooser dialog...");
82+
// try (MemoryStack stack = stackPush()) {
83+
// ByteBuffer color = stack.malloc(3);
84+
// String hex = tinyfd_colorChooser("Choose Color", "#FF00FF", null, color);
85+
// System.out.println(hex);
86+
// if (hex != null) {
87+
// System.out.println("\tR: " + (color.get(0) & 0xFF));
88+
// System.out.println("\tG: " + (color.get(1) & 0xFF));
89+
// System.out.println("\tB: " + (color.get(2) & 0xFF));
90+
// }
91+
// }
92+
// break;
93+
// }
94+
// });
95+
//
96+
// // Center window
97+
// GLFWVidMode vidmode = Objects.requireNonNull(glfwGetVideoMode(glfwGetPrimaryMonitor()));
98+
// glfwSetWindowPos(
99+
// window,
100+
// (vidmode.width() - 300) / 2,
101+
// (vidmode.height() - 300) / 2
102+
// );
103+
//
104+
// glfwMakeContextCurrent(window);
105+
// GL.createCapabilities();
106+
//
107+
// glfwSwapInterval(1);
108+
//
109+
// tinyfd_messageBox("tinyfd_query", "", "ok", "info", true);
110+
// System.out.println("tiny file dialogs " + tinyfd_version + " (" + tinyfd_response() + ")");
111+
// System.out.println();
112+
// System.out.println(tinyfd_needs);
113+
// System.out.println();
114+
// System.out.println("Press 1 to launch a message dialog.");
115+
// System.out.println("Press 2 to launch an input box fialog.");
116+
// System.out.println("Press 3 to launch a file open dialog.");
117+
// System.out.println("Press 4 to launch a file save dialog.");
118+
// System.out.println("Press 5 to launch a folder select dialog.");
119+
// System.out.println("Press 6 to launch a color chooser dialog.");
120+
// while (!glfwWindowShouldClose(window)) {
121+
// glfwPollEvents();
122+
//
123+
// glClear(GL_COLOR_BUFFER_BIT);
124+
// glfwSwapBuffers(window);
125+
// }
126+
//
127+
// GL.setCapabilities(null);
128+
//
129+
// glfwFreeCallbacks(window);
130+
// glfwDestroyWindow(window);
131+
// glfwTerminate();
132+
//
133+
// Objects.requireNonNull(glfwSetErrorCallback(null)).free();
134+
// }
135+
//
136+
//}

src/test/kotlin/uno/awe.kt

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
//package uno
2+
//
3+
//import glm_.and
4+
//import org.lwjgl.glfw.Callbacks.glfwFreeCallbacks
5+
//import org.lwjgl.glfw.GLFW.*
6+
//import org.lwjgl.glfw.GLFWErrorCallback
7+
//import org.lwjgl.glfw.GLFWVidMode
8+
//import org.lwjgl.opengl.GL
9+
//import org.lwjgl.opengl.GL11C.GL_COLOR_BUFFER_BIT
10+
//import org.lwjgl.opengl.GL11C.glClear
11+
//import org.lwjgl.system.MemoryStack.stackPush
12+
//import org.lwjgl.system.MemoryUtil.NULL
13+
//import org.lwjgl.util.tinyfd.TinyFileDialogs.*
14+
//import java.util.*
15+
//
16+
//object HelloTinyFD {
17+
//
18+
// @JvmStatic
19+
// fun main(args: Array<String>) {
20+
// GLFWErrorCallback.createPrint().set()
21+
// if (!glfwInit()) {
22+
// throw IllegalStateException("Unable to initialize GLFW")
23+
// }
24+
//
25+
// val window = glfwCreateWindow(300, 300, "Hello tiny file dialogs!", NULL, NULL)
26+
// if (window == NULL) {
27+
// throw RuntimeException("Failed to create the GLFW window")
28+
// }
29+
//
30+
// glfwSetKeyCallback(window) { windowHnd, key, scancode, action, mods ->
31+
// if (action == GLFW_RELEASE) {
32+
// return@glfwSetKeyCallback
33+
// }
34+
//
35+
// when (key) {
36+
// GLFW_KEY_ESCAPE -> glfwSetWindowShouldClose(windowHnd, true)
37+
// GLFW_KEY_B -> tinyfd_beep()
38+
// GLFW_KEY_N -> {
39+
// println("\nOpening notification popup...")
40+
// println(tinyfd_notifyPopup("Please read...", "...this message.", "info"))
41+
// }
42+
// GLFW_KEY_1 -> {
43+
// println("\nOpening message dialog...")
44+
// println(if (tinyfd_messageBox("Please read...", "...this message.", "okcancel", "info", true)) "OK" else "Cancel")
45+
// }
46+
// GLFW_KEY_2 -> {
47+
// println("\nOpening input box dialog...")
48+
// println(tinyfd_inputBox("Input Value", "How old are you?", "30"))
49+
// }
50+
// GLFW_KEY_3 -> {
51+
// println("\nOpening file open dialog...")
52+
// println(tinyfd_openFileDialog("Open File(s)", "", null, null, true))
53+
// }
54+
// GLFW_KEY_4 -> stackPush().use({ stack ->
55+
// val aFilterPatterns = stack.mallocPointer(2)
56+
//
57+
// aFilterPatterns.put(stack.UTF8("*.jpg"))
58+
// aFilterPatterns.put(stack.UTF8("*.png"))
59+
//
60+
// aFilterPatterns.flip()
61+
//
62+
// println("\nOpening file save dialog...")
63+
// println(tinyfd_saveFileDialog("Save Image", "", aFilterPatterns, "Image files (*.jpg, *.png)"))
64+
// })
65+
// GLFW_KEY_5 -> {
66+
// println("\nOpening folder select dialog...")
67+
// println(tinyfd_selectFolderDialog("Select Folder", ""))
68+
// }
69+
// GLFW_KEY_6 -> {
70+
// println("\nOpening color chooser dialog...")
71+
// stackPush().use { stack ->
72+
// val color = stack.malloc(3)
73+
// val hex = tinyfd_colorChooser("Choose Color", "#FF00FF", null, color)
74+
// println(hex)
75+
// if (hex != null) {
76+
// println("\tR: " + (color.get(0) and 0xFF))
77+
// println("\tG: " + (color.get(1) and 0xFF))
78+
// println("\tB: " + (color.get(2) and 0xFF))
79+
// }
80+
// }
81+
// }
82+
// }
83+
// }
84+
//
85+
// // Center window
86+
// val vidmode = Objects.requireNonNull<GLFWVidMode>(glfwGetVideoMode(glfwGetPrimaryMonitor()))
87+
// glfwSetWindowPos(
88+
// window,
89+
// (vidmode.width() - 300) / 2,
90+
// (vidmode.height() - 300) / 2
91+
// )
92+
//
93+
// glfwMakeContextCurrent(window)
94+
// GL.createCapabilities()
95+
//
96+
// glfwSwapInterval(1)
97+
//
98+
// tinyfd_messageBox("tinyfd_query", "", "ok", "info", true)
99+
// println("tiny file dialogs " + tinyfd_version + " (" + tinyfd_response() + ")")
100+
// println()
101+
// println(tinyfd_needs)
102+
// println()
103+
// println("Press 1 to launch a message dialog.")
104+
// println("Press 2 to launch an input box fialog.")
105+
// println("Press 3 to launch a file open dialog.")
106+
// println("Press 4 to launch a file save dialog.")
107+
// println("Press 5 to launch a folder select dialog.")
108+
// println("Press 6 to launch a color chooser dialog.")
109+
// while (!glfwWindowShouldClose(window)) {
110+
// glfwPollEvents()
111+
//
112+
// glClear(GL_COLOR_BUFFER_BIT)
113+
// glfwSwapBuffers(window)
114+
// }
115+
//
116+
// GL.setCapabilities(null)
117+
//
118+
// glfwFreeCallbacks(window)
119+
// glfwDestroyWindow(window)
120+
// glfwTerminate()
121+
//
122+
// Objects.requireNonNull<GLFWErrorCallback>(glfwSetErrorCallback(null)).free()
123+
// }
124+
//
125+
//}

0 commit comments

Comments
 (0)