Use local context instead of global

This commit is contained in:
Joey Yakimowich-Payne 2020-04-25 22:07:47 -06:00
commit 77e390e9be
6 changed files with 302 additions and 274 deletions

View file

@ -23,10 +23,10 @@ proc main =
setTime(0)
glewInit()
nanovg.init()
nanovg.loadFont(currentSourceDir()/"resources/Roboto-Regular.ttf", "sans")
nanovg.loadFont(currentSourceDir()/"resources/Roboto-Bold.ttf", "sans-bold")
nanovg.loadFont(currentSourceDir()/"resources/fa.ttf", "fa")
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():
@ -43,16 +43,16 @@ proc main =
glClearColor(0.3, 0.3, 0.32, 1.0)
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT or GL_STENCIL_BUFFER_BIT)
withFrame(w):
let x = glyphPositions("Some仮名thing is up", 0, 0)
drawWindow("Title", 50, 50, 300, 400)
drawLabel("Hello!", 10, 10, 280, 20)
drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, rgba(128, 16, 8, 255))
drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, rgba(12, 130, 80, 255))
drawButton("Testing", 100, 300, 160, 28)
vg.withFrame(w):
let x = vg.glyphPositions("Some仮名thing is up", 0, 0)
vg.drawWindow("Title", 50, 50, 300, 400)
vg.drawLabel("Hello!", 10, 10, 280, 20)
vg.drawButton(ICON_TRASH, "Delete", 100, 200, 160, 28, rgba(128, 16, 8, 255))
vg.drawButton(ICON_TRASH, "Deleter", 100, 250, 160, 28, rgba(12, 130, 80, 255))
vg.drawButton("Testing", 100, 300, 160, 28)
fps.render(5, 5)
cpuGraph.render(210, 5)
vg.render(fps, 5, 5)
vg.render(cpuGraph, 210, 5)
w.swapBuffers()
pollEvents()
@ -64,6 +64,7 @@ proc main =
waitEvents()
w.destroy()
vg.delete()
glfw.terminate()
main()