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
|
|
@ -4,31 +4,45 @@ import std/os
|
|||
import raylib
|
||||
|
||||
# Emscripten specific imports
|
||||
proc emscripten_set_main_loop(f: proc() {.cdecl.}, a: cint, b: bool) {.importc.}
|
||||
proc emscripten_sleep(a: cuint) {.importc.}
|
||||
proc emscripten_set_main_loop( f: proc() {.cdecl.}, a: cint, b: bool ) {.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()
|
||||
|
||||
initWindow( 600, 400, "raylib nim playground" )
|
||||
initWindow( 800, 600, "raylib nim playground" )
|
||||
|
||||
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
|
||||
echo "wasm: hi"
|
||||
else:
|
||||
sleep 10
|
||||
|
||||
main()
|
||||
echo "native: hi"
|
||||
|
||||
|
||||
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