2025-08-19 13:21:43 -07:00
|
|
|
# vim: set et sta sw=4 ts=4 :
|
|
|
|
|
|
2025-08-19 22:35:50 -07:00
|
|
|
import
|
|
|
|
|
std/os,
|
|
|
|
|
std/strformat
|
2025-08-19 13:21:43 -07:00
|
|
|
import raylib
|
|
|
|
|
|
|
|
|
|
# Emscripten specific imports
|
2025-08-19 13:26:36 -07:00
|
|
|
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
|
|
|
|
|
)
|
|
|
|
|
|
2025-08-19 22:35:50 -07:00
|
|
|
# This only works with:
|
|
|
|
|
# --passL:"-s EXPORT_FUNCTIONS=_nativeGreet", but it breaks raylib loading.
|
|
|
|
|
# hmmmmm. EXPORT_ALL=1 is also a no go.
|
|
|
|
|
# Maybe it won't be necessary with raylib/opengl input
|
|
|
|
|
#
|
|
|
|
|
#[ proc nativeGreet*(): int {.exportc.} =
|
|
|
|
|
echo "Oh jeez, hello from native nim!"
|
|
|
|
|
return 0 ]#
|
|
|
|
|
|
|
|
|
|
|
2025-08-19 13:26:36 -07:00
|
|
|
proc mainLoop() {.cdecl.} =
|
2025-08-19 13:21:43 -07:00
|
|
|
defer: closeWindow()
|
|
|
|
|
|
2025-08-19 13:26:36 -07:00
|
|
|
initWindow( 800, 600, "raylib nim playground" )
|
2025-08-19 13:21:43 -07:00
|
|
|
|
2025-08-19 22:35:50 -07:00
|
|
|
var count = 0
|
|
|
|
|
|
2025-08-19 13:21:43 -07:00
|
|
|
while not windowShouldClose():
|
2025-08-19 13:26:36 -07:00
|
|
|
|
|
|
|
|
beginDrawing();
|
2025-08-19 22:35:50 -07:00
|
|
|
clearBackground( WHITE );
|
2025-08-19 13:26:36 -07:00
|
|
|
beginMode3D( camera );
|
|
|
|
|
drawGrid( 10, 1.0f );
|
|
|
|
|
endMode3D();
|
|
|
|
|
|
|
|
|
|
var col = if isCursorOnScreen(): BLUE else: GRAY
|
2025-08-19 22:35:50 -07:00
|
|
|
drawText( "OH SNAP IT'S WORKING\n{count}".fmt, 10, 10, 20, col );
|
2025-08-19 13:26:36 -07:00
|
|
|
endDrawing();
|
|
|
|
|
|
2025-08-19 22:35:50 -07:00
|
|
|
count = count + 1
|
|
|
|
|
|
2025-08-19 13:26:36 -07:00
|
|
|
if defined( emscripten ):
|
2025-08-19 13:21:43 -07:00
|
|
|
emscripten_sleep 10
|
2025-08-19 13:26:36 -07:00
|
|
|
echo "wasm: hi"
|
2025-08-19 13:21:43 -07:00
|
|
|
else:
|
|
|
|
|
sleep 10
|
2025-08-19 13:26:36 -07:00
|
|
|
echo "native: hi"
|
|
|
|
|
|
2025-08-19 13:21:43 -07:00
|
|
|
|
2025-08-19 13:26:36 -07:00
|
|
|
if defined( emscripten ):
|
|
|
|
|
emscripten_set_main_loop( mainLoop, 0, true );
|
|
|
|
|
else:
|
|
|
|
|
mainLoop()
|
2025-08-19 13:21:43 -07:00
|
|
|
|
|
|
|
|
|