parent
fc557e372a
commit
08dac8e241
1 changed files with 20 additions and 15 deletions
|
@ -1,19 +1,19 @@
|
||||||
import opengl, pixie, staticglfw
|
import opengl, pixie, pixie/context
|
||||||
|
import staticglfw except Image
|
||||||
export pixie, staticglfw
|
export pixie
|
||||||
|
export staticglfw except Image
|
||||||
type Image = pixie.Image
|
|
||||||
|
|
||||||
var
|
var
|
||||||
screen* = newImage(800, 600)
|
dpi: float32 = 1.0
|
||||||
|
screen*: Image
|
||||||
|
ctx*: Context
|
||||||
window*: Window
|
window*: Window
|
||||||
mouseWheelDelta*: float32
|
|
||||||
|
|
||||||
proc getMousePos*(): Vec2 =
|
proc getMousePos*(): Vec2 =
|
||||||
## Get the mouse position.
|
## Get the mouse position.
|
||||||
var xpos, ypos: float64
|
var xpos, ypos: float64
|
||||||
getCursorPos(window, xpos.addr, ypos.addr)
|
getCursorPos(window, xpos.addr, ypos.addr)
|
||||||
vec2(xpos, ypos)
|
vec2(xpos, ypos) / dpi
|
||||||
|
|
||||||
proc isMouseDown*(): bool =
|
proc isMouseDown*(): bool =
|
||||||
## Get if the left mouse button is down.
|
## Get if the left mouse button is down.
|
||||||
|
@ -25,9 +25,6 @@ proc isKeyDown*(keyCode: int): bool =
|
||||||
## Examples: KEY_SPACE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
|
## Examples: KEY_SPACE, KEY_UP, KEY_DOWN, KEY_LEFT, KEY_RIGHT
|
||||||
getKey(window, keyCode.cint) == PRESS
|
getKey(window, keyCode.cint) == PRESS
|
||||||
|
|
||||||
proc onScroll(window: staticglfw.Window, xoffset, yoffset: float64) {.cdecl.} =
|
|
||||||
mouseWheelDelta += yoffset
|
|
||||||
|
|
||||||
proc tick*() =
|
proc tick*() =
|
||||||
## Called this every frame in a while loop.
|
## Called this every frame in a while loop.
|
||||||
|
|
||||||
|
@ -50,25 +47,33 @@ proc tick*() =
|
||||||
|
|
||||||
swapBuffers(window)
|
swapBuffers(window)
|
||||||
|
|
||||||
mouseWheelDelta = 0
|
|
||||||
pollEvents()
|
pollEvents()
|
||||||
|
|
||||||
if windowShouldClose(window) == 1:
|
if windowShouldClose(window) == 1:
|
||||||
quit()
|
quit()
|
||||||
|
|
||||||
proc start*(title = "Demo") =
|
ctx.setTransform(scale(vec2(dpi, dpi)))
|
||||||
|
|
||||||
|
proc start*(title = "Demo", width = 800, height = 600) =
|
||||||
## Start the demo.
|
## Start the demo.
|
||||||
if init() == 0:
|
if init() == 0:
|
||||||
quit("Failed to Initialize GLFW.")
|
quit("Failed to Initialize GLFW.")
|
||||||
|
|
||||||
windowHint(RESIZABLE, false.cint)
|
windowHint(RESIZABLE, false.cint)
|
||||||
window = createWindow(screen.width.cint, screen.height.cint, title, nil, nil)
|
window = createWindow(width.cint, height.cint, title, nil, nil)
|
||||||
if window == nil:
|
if window == nil:
|
||||||
quit("Failed to create window.")
|
quit("Failed to create window.")
|
||||||
makeContextCurrent(window)
|
makeContextCurrent(window)
|
||||||
discard window.setScrollCallback(onScroll)
|
|
||||||
loadExtensions()
|
loadExtensions()
|
||||||
|
|
||||||
|
var xscale, yscale: cfloat
|
||||||
|
window.getWindowContentScale(xscale.addr, yscale.addr)
|
||||||
|
dpi = xscale
|
||||||
|
screen = newImage(int(width.float32 * dpi), int(height.float32 * dpi))
|
||||||
|
window.setWindowSize(screen.width.cint, screen.height.cint)
|
||||||
|
glViewport(0, 0, screen.width.cint, screen.height.cint)
|
||||||
|
ctx = newContext(screen)
|
||||||
|
|
||||||
# Allocate a texture and bind it.
|
# Allocate a texture and bind it.
|
||||||
var dataPtr = screen.data[0].addr
|
var dataPtr = screen.data[0].addr
|
||||||
glTexImage2D(
|
glTexImage2D(
|
||||||
|
|
Loading…
Reference in a new issue