a bit of fiddling to support different resolutions (as long as aspect ratio of window is 1:1)

This commit is contained in:
2024-07-31 14:02:23 +01:00
parent d90ed8afa2
commit a2c499c933
5 changed files with 16 additions and 14 deletions

Binary file not shown.

View File

@@ -14,16 +14,11 @@ message-types/input-msg.sml
message-types/draw-msg.sml
functional-core/app-type.sml
ann
"allowVectorExps true"
in
functional-core/app-update.sml
end
ann
"allowVectorExps true"
in
imperative-shell/constants.sml
functional-core/app-update.sml
imperative-shell/app-draw.sml
end

View File

@@ -26,7 +26,8 @@ struct
end
local
val clickPoints = genClickPoints (500, 500)
val clickPoints =
genClickPoints (Constants.windowWidth, Constants.windowHeight)
fun getVerticalClickPos (idx, horizontalPos, mouseX, mouseY, r, g, b) =
if idx = Vector.length clickPoints then
@@ -40,12 +41,14 @@ struct
(idx + 1, horizontalPos, mouseX, mouseY, r, g, b)
else
let
val hpos = horizontalPos - 250.0
val vpos = ~(curVerticalPos - 250.0)
val left = (hpos - 5.0) / 250.0
val right = (hpos + 5.0) / 250.0
val bottom = (vpos - 5.0) / 250.0
val top = (vpos + 5.0) / 250.0
val halfWidth = Real32.fromInt (Constants.windowWidth div 2)
val halfHeight = Real32.fromInt (Constants.windowHeight div 2)
val hpos = horizontalPos - halfWidth
val vpos = ~(curVerticalPos - halfHeight)
val left = (hpos - 5.0) / halfWidth
val right = (hpos + 5.0) / halfWidth
val bottom = (vpos - 5.0) / halfHeight
val top = (vpos + 5.0) / halfHeight
in
#[ left, bottom, r, g, b
, right, bottom, r, g, b

View File

@@ -1,5 +1,8 @@
structure Constants =
struct
val windowWidth = 900
val windowHeight = 900
val graphVertexShaderString =
"#version 300 es\n\
\layout (location = 0) in vec2 apos;\n\

View File

@@ -9,7 +9,8 @@ struct
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 window =
Glfw.createWindow (Constants.windowWidth, Constants.windowHeight, "MLton - dot to dot")
val _ = Glfw.makeContextCurrent window
val _ = Gles3.loadGlad ()