From 3463c597a7c19719159747273ead240db00722e6 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 23 Aug 2020 21:34:57 -0600 Subject: [PATCH] Add example --- examples/ex1.nim | 34 ++++++++++++++++++++++++++++++++++ examples/nim.cfg | 1 + src/glfw/glfw.nim | 4 ++-- 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 examples/ex1.nim diff --git a/examples/ex1.nim b/examples/ex1.nim new file mode 100644 index 0000000..63dccb5 --- /dev/null +++ b/examples/ex1.nim @@ -0,0 +1,34 @@ +import glfw +import opengl + +# Init GLFW +if init() == 0: + raise newException(Exception, "Failed to Initialize GLFW") + +# Open window. +var window = createWindow(800, 600, "GLFW3 WINDOW", nil, nil) +# Connect the GL context. +window.makeContextCurrent() +# This must be called to make any GL function work +loadExtensions() + +# Run while window is open. +while windowShouldClose(window) == 0: + + # Draw red color screen. + glClearColor(1, 0, 0, 1) + glClear(GL_COLOR_BUFFER_BIT) + + # Swap buffers (this will display the red color) + window.swapBuffers() + + # Check for events. + pollEvents() + # If you get ESC key quit. + if window.getKey(KEY_ESCAPE) == 1: + window.setWindowShouldClose(1) + +# Destroy the window. +window.destroyWindow() +# Exit GLFW. +terminate() diff --git a/examples/nim.cfg b/examples/nim.cfg index 85bf6c4..bfa8de3 100644 --- a/examples/nim.cfg +++ b/examples/nim.cfg @@ -1 +1,2 @@ --path:"../src/" +--passL:"-lm -pthread -lpthread" diff --git a/src/glfw/glfw.nim b/src/glfw/glfw.nim index 023336d..06305ad 100644 --- a/src/glfw/glfw.nim +++ b/src/glfw/glfw.nim @@ -15,13 +15,12 @@ const setDefines(defs.splitLines()) -{.passL: "-lpthread".} getHeader( "glfw3.h", giturl = "https://github.com/glfw/glfw", outdir = srcDir, altNames = "glfw,glfw3", - cmakeFlags = &"-DCMAKE_C_FLAGS=-lpthread" + cmakeFlags = &"-DCMAKE_C_FLAGS='-lpthread -pthread -lm'" ) static: @@ -35,6 +34,7 @@ static: cIncludeDir(srcDir/"include"/"GLFW") cPluginPath(symbolPluginPath) +{.passL: "-lm -lpthread -pthread".} when isDefined(glfw3Static): cImport(srcDir/"include"/"GLFW"/"glfw3.h", recurse = true, flags = "-f=ast2 -E__,_ -F__,_ -H")