This commit is contained in:
2024-07-28 14:22:17 +01:00
commit 319ba58b3e
17 changed files with 5124 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
structure Constants =
struct
val boxVertexShaderString =
"#version 300 es\n\
\layout (location = 0) in vec2 apos;\n\
\void main()\n\
\{\n\
\ gl_Position = vec4(apos.x, apos.y, 0.0f, 1.0f);\n\
\}"
val boxFragmentShaderString =
"#version 300 es\n\
\precision mediump float;\n\
\out vec4 FragColor;\n\
\uniform vec4 col;\n\
\void main()\n\
\{\n\
\ FragColor = col;\n\
\}";
val initialDr: Real32.real = 217.0 / 255.0
val initialDg: Real32.real = 233.0 / 255.0
val initialDb: Real32.real = 227.0 / 255.0
val initialNr: Real32.real = 17.0 / 255.0
val initialNg: Real32.real = 77.0 / 255.0
val initialNb: Real32.real = 91.0 / 255.0
end

View File

@@ -0,0 +1,73 @@
structure Shell =
struct
open CML
datatype msg = KEY of int * int * int * int
fun keyCallback mailbox (key, scancode, action, mode) =
(print "hello\n";
Mailbox.send (mailbox, (KEY (key, scancode, action, mode))))
fun callbackListener mailbox =
let
val _ =
case Mailbox.recv mailbox of
KEY (key, scancode, action, mode) =>
print (String.concat
[ "key: "
, Int.toString key
, " scancode: "
, Int.toString scancode
, " action: "
, Int.toString action
, " mode: "
, Int.toString mode
, "\n"
])
in
callbackListener mailbox
end
fun loop (window) =
if not (Glfw.windowShouldClose window) then
let
val _ = Gles3.clearColor (0.1, 0.1, 0.1, 0.1)
val _ = Gles3.clear ()
val _ = Glfw.pollEvents ()
val _ = Glfw.swapBuffers window
in
loop (window)
end
else
Glfw.terminate ()
fun main () =
let
(* Set up GLFW. *)
val _ = Glfw.init ()
val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3)
val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ())
val _ = Glfw.windowHint (Glfw.SAMPLES (), 4)
val window = Glfw.createWindow (500, 500, "MLton - box x box")
val _ = Glfw.makeContextCurrent window
val _ = Gles3.loadGlad ()
val inputMailbox = Mailbox.mailbox ()
(* Set callback sender *)
val _ = CML.spawn (fn () =>
let
val kbCallback = keyCallback inputMailbox
val _ = Key.export kbCallback
val _ = Key.setCallback window
in
()
end)
(* Set callback listener *)
val _ = CML.spawn (fn () => callbackListener inputMailbox)
in
loop (window)
end
end
val _ = RunCML.doit (Shell.main, NONE)