diff --git a/examples/demo.nim b/examples/demo.nim index 652e556..1a3698a 100644 --- a/examples/demo.nim +++ b/examples/demo.nim @@ -4,40 +4,55 @@ import glfw, glew import perf import common +proc frameBufferSize*(window: ptr Window): tuple[w, h: int32] = + var fbWidth, fbHeight: cint + window.getFramebufferSize(fbWidth.addr, fbHeight.addr) + + return (w: fbWidth, h: fbHeight) + +proc size*(window: ptr Window): tuple[w, h: int32] = + var width, height: cint + window.getWindowSize(width.addr, height.addr) + + return (w: width, h: height) + proc main = - var c = DefaultOpenglWindowConfig - c.version = glv32 - c.title = "Minimal Nim-GLFW example" - c.forwardCompat = true - c.profile = opCoreProfile - c.debugContext = false let fps = newGraph(RenderStyle.FPS, "Frame Time") cpuGraph = newGraph(RenderStyle.MS, "CPU Time") + discard glfw.init() - glfw.initialize() - var w = newWindow(c) + initHint(CONTEXT_VERSION_MAJOR, 3) + initHint(CONTEXT_VERSION_MINOR, 2) + when defined(macosx): + initHint(OPENGL_FORWARD_COMPAT, 1) + initHint(OPENGL_PROFILE, OPENGL_COMPAT_PROFILE) + else: + initHint(OPENGL_PROFILE, OPENGL_CORE_PROFILE) + + var w = createWindow(800, 600, "Minimal Nim-GLFW Example", nil, nil) + w.makeContextCurrent() swapInterval(0) setTime(0) - glew.init() + discard glew.init() let vg = nanovg.newContext() vg.loadFont(currentSourceDir()/"resources/Roboto-Regular.ttf", "sans") vg.loadFont(currentSourceDir()/"resources/Roboto-Bold.ttf", "sans-bold") vg.loadFont(currentSourceDir()/"resources/fa.ttf", "fa") var prevt = getTime() - while not w.shouldClose(): + while not w.windowShouldClose().bool: let t = getTime() let dt = t - prevt prevt = t - #let pos = w.cursorPos() let fbSize = w.frameBufferSize() glViewPort(0, 0, fbSize.w, fbSize.h) + glCullFace(GL_BACK) glFrontFace(GL_CCW) glClearColor(0.3, 0.3, 0.32, 1.0) @@ -63,7 +78,7 @@ proc main = cpuGraph.update(cpuTime) waitEvents() - w.destroy() + w.destroyWindow() vg.delete() glfw.terminate() diff --git a/examples/demo_sdl2_gpu.nim b/examples/demo_sdl2_gpu.nim index b897fa7..65b5003 100644 --- a/examples/demo_sdl2_gpu.nim +++ b/examples/demo_sdl2_gpu.nim @@ -66,27 +66,16 @@ proc main() = discard sdl.init(sdl.INIT_EVERYTHING.uint32) discard sdl.glSetAttribute(sdl.GL_STENCIL_SIZE, 1) - discard sdl.glSetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE.cint) - discard sdl.glSetAttribute(sdl.GL_CONTEXT_FLAGS, sdl.GL_CONTEXT_FORWARD_COMPATIBLE_FLAG.cint) - discard sdl.glSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3) - discard sdl.glSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 2) + + when defined(macosx): + discard sdl.glSetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE.cint) + discard sdl.glSetAttribute(sdl.GL_CONTEXT_FLAGS, sdl.GL_CONTEXT_FORWARD_COMPATIBLE_FLAG.cint) + discard sdl.glSetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3) + discard sdl.glSetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 2) + var w, h: cint - # let - # vert = gpu.loadShader(gpu.VERTEX_SHADER, currentSourceDir()/"resources/untextured.vert") - # frag = gpu.loadShader(gpu.FRAGMENT_SHADER, currentSourceDir()/"resources/untextured.frag") - # program = gpu.linkShaders(vert, frag) - - # glUseProgram(program) - - # let - # vertLoc = gpu.getAttributeLocation(program, "gpu_Vertex") - # colorLoc = gpu.getAttributeLocation(program, "gpu_Color") - # mvpLoc = gpu.getUniformLocation(program, "gpu_ModelViewProjectionMatrix") - let screen = gpu.initRenderer(gpu.RENDERER_OPENGL_3, 640, 480, sdl.WINDOW_ALLOW_HIGHDPI) - gpu.setRequiredFeatures(gpu.FEATURE_BASIC_SHADERS) - let vg = nanovg.newContext() discard sdl.glSetSwapInterval(0) @@ -152,4 +141,4 @@ proc main() = vg.delete() gpu.quit() -main() \ No newline at end of file +main() diff --git a/nanovg.nimble b/nanovg.nimble index 5c2e76c..a12f56f 100644 --- a/nanovg.nimble +++ b/nanovg.nimble @@ -9,12 +9,12 @@ srcDir = "src" # Dependencies requires "nim >= 1.0.6", - "nimterop#head", + "https://github.com/jyapayne/nimterop#367ec05", "regex >= 0.14.1", "opengl >= 1.2.6", - "nim-glfw#head", - "nim_sdl2", - "glew" + "sdl2#head", + "https://github.com/jyapayne/nim-glew#15383cf", + "https://github.com/jyapayne/nim-glfw#22bbdf6" import os @@ -71,4 +71,4 @@ task buildGLFWExample, "Build GLFW example": task buildGLFWExampleDebug, "Build GLFW example debug": let buildDir = setupGLFW() - exec "nimble c --app:gui --debugger:native -o:" & buildDir & "/" & "demo_glfw_debug".toExe & " -r examples/demo.nim" \ No newline at end of file + exec "nimble c --app:gui --debugger:native -o:" & buildDir & "/" & "demo_glfw_debug".toExe & " -r examples/demo.nim" diff --git a/nim-gdb.bash b/nim-gdb.bash deleted file mode 120000 index f6eba4b..0000000 --- a/nim-gdb.bash +++ /dev/null @@ -1 +0,0 @@ -nim-gdb \ No newline at end of file diff --git a/nim.cfg b/nim.cfg deleted file mode 100644 index 82d06b5..0000000 --- a/nim.cfg +++ /dev/null @@ -1,14 +0,0 @@ -@if useGlfw: - -d:glfwStaticLib -@end --d:GLEW_SetVer="2.1.0" -d:glewDL -d:glewStatic --d:nanovg_Git --d:nanovg_setver="1f9c8864fc556a1be4d4bf1d6bfe20cde25734b4" --d:nanovg_Static --d:SDL_SetVer="2.0.12" -d:SDL_DL -d:SDL_Static --d:SDL_ImageSetVer="2.0.5" -d:SDL_Image_DL -d:SDL_Image_Static --d:SDL_NetSetVer="2.0.1" -d:SDL_Net_DL -d:SDL_Net_Static --d:SDL_MixerSetVer="2.0.4" -d:SDL_Mixer_DL -d:SDL_Mixer_Static --d:SDL_ttf_SetVer="2.0.15" -d:SDL_TTF_DL -d:SDL_ttf_Static --d:SDL_GpuSetVer="def5ea1" -d:SDL_GPU_Git -d:SDL_Gpu_Static --d:SDL2_GFXPrimitivesSetVer="1.0.4" -d:SDL2_GFXPrimitives_DL -d:SDL2_GFXPrimitives_Static -d:SDL2_GFX_Static \ No newline at end of file diff --git a/src/nanovg/wrapper.nim b/src/nanovg/wrapper.nim index 8102a73..c38183c 100644 --- a/src/nanovg/wrapper.nim +++ b/src/nanovg/wrapper.nim @@ -12,6 +12,15 @@ const baseDir = currentSourcePath.parentDir().parentDir().parentDir() srcDir = baseDir/"build"/"nanovg" + defs = """ + nanovgGit + nanovgSetver=1f9c8864fc556a1be4d4bf1d6bfe20cde25734b4 + nanovgStatic + """ + +setDefines(defs.splitLines()) + + static: # Print generated Nim to output # cDebug() @@ -78,7 +87,7 @@ when defined(macosx): #{.passL: "/usr/local/lib/libSDL2_gpu.a -m64 -lglew -framework GLUT -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -framework Carbon -lm".} else: {.passC: "-DNANOVG_GL3_IMPLEMENTATION -DNANOVG_GLEW".} - when defined(nanovg_Static): + when isDefined(nanovgStatic): {.passL: "-m64 -framework GLUT -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -framework Carbon -framework CoreAudio -lm".} else: {.passL: "-m64 -lSDL2 -lglew -framework GLUT -framework OpenGL -framework Cocoa -framework IOKit -framework CoreVideo -framework Carbon -framework CoreAudio -lm".} @@ -88,7 +97,7 @@ elif defined(unix): when defined(useGlfw): {.passL: "-lGL -lGLU -lGLEW -lm -lglfw".} else: - {.passL: "-lGL -lGLU -lGLEW -lm -lSDL2".} + {.passL: "-lGL -lGLU -lGLEW -lm -lpthread -lglfw".} elif defined(windows): const inclPath = baseDir/"lib"/"include" when defined(amd64):