Hey, nice. Lots to learn still, but this is working.
This commit is contained in:
parent
eb25270d34
commit
740211ed4c
3 changed files with 53 additions and 32 deletions
23
config.nims
23
config.nims
|
|
@ -1,5 +1,5 @@
|
||||||
|
|
||||||
when defined(emscripten):
|
when defined( emscripten ):
|
||||||
--define:GraphicsApiOpenGlEs2
|
--define:GraphicsApiOpenGlEs2
|
||||||
# --define:NaylibWebResources
|
# --define:NaylibWebResources
|
||||||
# switch("define", "NaylibWebResourcesPath=resources")
|
# switch("define", "NaylibWebResourcesPath=resources")
|
||||||
|
|
@ -8,20 +8,27 @@ when defined(emscripten):
|
||||||
--os:linux
|
--os:linux
|
||||||
--cpu:wasm32
|
--cpu:wasm32
|
||||||
--cc:clang
|
--cc:clang
|
||||||
--clang.exe:emcc
|
when defined( windows ):
|
||||||
--clang.linkerexe:emcc
|
--clang.exe:emcc.bat # Replace C
|
||||||
--clang.cpp.exe:emcc
|
--clang.linkerexe:emcc.bat # Replace C linker
|
||||||
--clang.cpp.linkerexe:emcc
|
--clang.cpp.exe:emcc.bat # Replace C++
|
||||||
|
--clang.cpp.linkerexe:emcc.bat # Replace C++ linker.
|
||||||
|
else:
|
||||||
|
--clang.exe:emcc
|
||||||
|
--clang.linkerexe:emcc
|
||||||
|
--clang.cpp.exe:emcc
|
||||||
|
--clang.cpp.linkerexe:emcc
|
||||||
--mm:arc
|
--mm:arc
|
||||||
--threads:on
|
--threads:on
|
||||||
--panics:on
|
--panics:on
|
||||||
--exceptions:goto
|
--exceptions:goto
|
||||||
--define:noSignalHandler
|
--define:noSignalHandler
|
||||||
--passL:"-03"
|
--passL:"-Oz" # Production build
|
||||||
|
# --passL:"-O0 -gDebug -gsource-map" # Debug build
|
||||||
# --passL:"-s EXPORT_NAME=Test1Module"
|
# --passL:"-s EXPORT_NAME=Test1Module"
|
||||||
# --passL:"-s MODULARIZE=1"
|
# --passL:"-s MODULARIZE=1"
|
||||||
--passL:"-s ASYNCIFY" # async support
|
--passL:"-s ASYNCIFY" # async support
|
||||||
# --passL:"-s JSPI" # async support
|
# --passL:"-s JSPI" # async support
|
||||||
--passL:"-o index.html"
|
--passL:"-o build/index.html"
|
||||||
# --passL:"--shell-file minshell.html"
|
--passL:"--shell-file minshell.html"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,10 @@
|
||||||
# Package
|
# Package
|
||||||
|
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
author = "Mahlon E. Smith"
|
author = "Mahlon E. Smith"
|
||||||
description = "Dinking around with raylib and wasm target"
|
description = "Dinking around with raylib and wasm target"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
|
|
||||||
requires "nim >= 2.2.4"
|
requires "nim >= 2.2.4"
|
||||||
requires "naylib >= 25.33.0"
|
requires "naylib >= 25.33.0"
|
||||||
|
|
@ -14,9 +14,9 @@ task make, "Native build":
|
||||||
exec "mkdir -p build && nim c --outdir:build -d:release --opt:speed src/nim_wasm_test.nim"
|
exec "mkdir -p build && nim c --outdir:build -d:release --opt:speed src/nim_wasm_test.nim"
|
||||||
|
|
||||||
task makeweb, "Emscripten build":
|
task makeweb, "Emscripten build":
|
||||||
exec "mkdir -p build && nim c --outdir:build -d:emscripten src/nim_wasm_test.nim"
|
exec "mkdir -p build && nim c -d:emscripten -d:release src/nim_wasm_test.nim"
|
||||||
|
|
||||||
task runweb, "Run a local webserver for the wasm build":
|
task runweb, "Run a local webserver for the wasm build":
|
||||||
exec "nimhttpd -H:'Cross-Origin-Opener-Policy: same-origin' -H:'Cross-Origin-Embedder-Policy: require-corp'"
|
exec "nimhttpd -H:'Cross-Origin-Opener-Policy: same-origin' -H:'Cross-Origin-Embedder-Policy: require-corp' build/"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,31 +4,45 @@ import std/os
|
||||||
import raylib
|
import raylib
|
||||||
|
|
||||||
# Emscripten specific imports
|
# Emscripten specific imports
|
||||||
proc emscripten_set_main_loop(f: proc() {.cdecl.}, a: cint, b: bool) {.importc.}
|
proc emscripten_set_main_loop( f: proc() {.cdecl.}, a: cint, b: bool ) {.importc.}
|
||||||
proc emscripten_sleep(a: cuint) {.importc.}
|
proc emscripten_sleep( a: cuint ) {.importc.}
|
||||||
|
|
||||||
|
var camera = Camera(
|
||||||
|
position: Vector3(x: 5, y: 5, z: 10), # Camera position
|
||||||
|
target: Vector3(x: 0, y: 0, z: 0), # Camera target it looks-at
|
||||||
|
up: Vector3(x: 0, y: 1, z: 0), # Camera up vector (rotation over its axis)
|
||||||
|
fovy: 45, # Camera field-of-view apperture in Y (degrees)
|
||||||
|
projection: Perspective # Defines projection type, see CameraProjection
|
||||||
|
)
|
||||||
|
|
||||||
proc main() =
|
proc mainLoop() {.cdecl.} =
|
||||||
defer: closeWindow()
|
defer: closeWindow()
|
||||||
|
|
||||||
initWindow( 600, 400, "raylib nim playground" )
|
initWindow( 800, 600, "raylib nim playground" )
|
||||||
|
|
||||||
while not windowShouldClose():
|
while not windowShouldClose():
|
||||||
if defined(emscripten):
|
|
||||||
|
beginDrawing();
|
||||||
|
clearBackground( RAYWHITE );
|
||||||
|
beginMode3D( camera );
|
||||||
|
drawGrid( 10, 1.0f );
|
||||||
|
endMode3D();
|
||||||
|
|
||||||
|
var col = if isCursorOnScreen(): BLUE else: GRAY
|
||||||
|
drawText( "OH SNAP IT'S WORKING", 10, 10, 20, col );
|
||||||
|
endDrawing();
|
||||||
|
|
||||||
|
if defined( emscripten ):
|
||||||
emscripten_sleep 10
|
emscripten_sleep 10
|
||||||
|
echo "wasm: hi"
|
||||||
else:
|
else:
|
||||||
sleep 10
|
sleep 10
|
||||||
|
echo "native: hi"
|
||||||
main()
|
|
||||||
|
|
||||||
|
if defined( emscripten ):
|
||||||
|
emscripten_set_main_loop( mainLoop, 0, true );
|
||||||
|
else:
|
||||||
|
mainLoop()
|
||||||
|
|
||||||
|
|
||||||
# when defined(emscripten):
|
|
||||||
# # Emscripten can't block so it will call this callback instead.
|
|
||||||
# emscripten_set_main_loop(main_loop, 0, true);
|
|
||||||
# else:
|
|
||||||
# # When running native code we can block in an infinite loop.
|
|
||||||
# while windowShouldClose(window) == 0:
|
|
||||||
# mainLoop()
|
|
||||||
# # If you get ESC key quit.
|
|
||||||
# if window.getKey(KEY_ESCAPE) == 1:
|
|
||||||
# window.setWindowShouldClose(1)
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue