Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.3.1 use ivec #12

Merged
merged 2 commits into from
Oct 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ The basic model for using Boxy goes something like this:
```nim
import boxy, opengl, staticglfw

let windowSize = vec2(1280, 800)
let windowSize = ivec2(1280, 800)

if init() == 0:
quit("Failed to Initialize GLFW.")

windowHint(RESIZABLE, false.cint)

let window = createWindow(
windowSize.x.cint, windowSize.y.cint, "GLFW + Boxy", nil, nil
)
let window = createWindow(windowSize.x, windowSize.y, "GLFW + Boxy", nil, nil)

makeContextCurrent(window)
loadExtensions()
Expand All @@ -47,7 +45,7 @@ proc display() =
# Clear the screen and begin a new frame.
bxy.beginFrame(windowSize)
# Draw the white background.
bxy.drawRect(rect(vec2(0, 0), windowSize), color(1, 1, 1, 1))
bxy.drawRect(rect(vec2(0, 0), windowSize.vec2), color(1, 1, 1, 1))
# Draw the rhino.
bxy.drawImage("rhino", vec2(100, 100))
# End this frame, flushing the draw commands.
Expand Down
4 changes: 2 additions & 2 deletions boxy.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.3.0"
version = "0.3.1"
author = "Andre von Houck and Ryan Oldenburg"
description = "2D GPU rendering with a tiling atlas."
license = "MIT"
Expand All @@ -7,6 +7,6 @@ srcDir = "src"

requires "nim >= 1.2.2"
requires "pixie >= 3.0.0"
requires "vmath >= 1.0.11"
requires "vmath >= 1.1.0"
requires "opengl >= 1.2.3"
requires "bitty >= 0.1.2"
14 changes: 6 additions & 8 deletions examples/bigbang.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import boxy, opengl, staticglfw, random

let windowSize = vec2(1280, 800)
let windowSize = ivec2(1280, 800)

if init() == 0:
quit("Failed to Initialize GLFW.")

windowHint(RESIZABLE, false.cint)

let window = createWindow(
windowSize.x.cint, windowSize.y.cint, "GLFW + Boxy", nil, nil
)
let window = createWindow(windowSize.x, windowSize.y, "GLFW + Boxy", nil, nil)

makeContextCurrent(window)
loadExtensions()
Expand All @@ -28,18 +26,18 @@ proc display() =
bxy.beginFrame(windowSize)

# Draw the bg.
bxy.drawRect(rect(vec2(0, 0), windowSize), color(0, 0, 0, 1))
bxy.drawRect(rect(vec2(0, 0), windowSize.vec2), color(0, 0, 0, 1))

bxy.saveTransform()
bxy.translate(windowSize/2)
bxy.translate(windowSize.vec2 / 2)
bxy.scale(0.1)

randomize(2022)
for i in 0 .. 5000:
let pos = vec2(gauss(), gauss()) * frame.float32 * 10
bxy.drawImage("star1",
center=pos,
angle=rand(0.0 .. PI)
center = pos,
angle = rand(0.0 .. PI)
)

bxy.restoreTransform()
Expand Down
10 changes: 4 additions & 6 deletions examples/glfw_basic.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import boxy, opengl, staticglfw

let windowSize = vec2(1280, 800)
let windowSize = ivec2(1280, 800)

if init() == 0:
quit("Failed to Initialize GLFW.")

windowHint(RESIZABLE, false.cint)

let window = createWindow(
windowSize.x.cint, windowSize.y.cint, "GLFW + Boxy", nil, nil
)
let window = createWindow(windowSize.x, windowSize.y, "GLFW + Boxy", nil, nil)

makeContextCurrent(window)
loadExtensions()
Expand All @@ -26,9 +24,9 @@ proc display() =
# Clear the screen and begin a new frame.
bxy.beginFrame(windowSize)
# Draw the white background.
bxy.drawRect(rect(vec2(0, 0), windowSize), color(1, 1, 1, 1))
bxy.drawRect(rect(vec2(0, 0), windowSize.vec2), color(1, 1, 1, 1))
# Draw the rhino.
bxy.drawImage("rhino", vec2((i mod windowSize.x.int).float32, 0))
bxy.drawImage("rhino", vec2((i mod windowSize.x).float32, 0))
# End this frame, flushing the draw commands.
bxy.endFrame()
# Swap buffers displaying the new Boxy frame.
Expand Down
12 changes: 5 additions & 7 deletions examples/masking.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import boxy, opengl, staticglfw

let windowSize = vec2(1280, 800)
let windowSize = ivec2(1280, 800)

if init() == 0:
quit("Failed to Initialize GLFW.")

windowHint(RESIZABLE, false.cint)

let window = createWindow(
windowSize.x.cint, windowSize.y.cint, "GLFW + Boxy", nil, nil
)
let window = createWindow(windowSize.x, windowSize.y, "GLFW + Boxy", nil, nil)

makeContextCurrent(window)
loadExtensions()
Expand All @@ -28,16 +26,16 @@ proc display() =
bxy.beginFrame(windowSize)

# Draw the bg.
bxy.drawRect(rect(vec2(0, 0), windowSize), color(0, 0, 0, 1))
bxy.drawRect(rect(vec2(0, 0), windowSize.vec2), color(0, 0, 0, 1))

# Draw the mask.
bxy.beginMask()
bxy.drawImage("mask", center=windowSize/2, angle = 0)
bxy.drawImage("mask", center=windowSize.vec2 / 2, angle = 0)
bxy.endMask()

# Use the mask.
bxy.saveTransform()
bxy.translate(windowSize/2)
bxy.translate(windowSize.vec2 / 2)
bxy.scale(1.2 + 0.2 * sin(frame.float32/100))
bxy.drawImage("greece", center=vec2(0, 0), angle = 0)
bxy.restoreTransform()
Expand Down
15 changes: 7 additions & 8 deletions examples/spinner.nim
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import boxy, opengl, staticglfw

let windowSize = vec2(1280, 800)
let windowSize = ivec2(1280, 800)

if init() == 0:
quit("Failed to Initialize GLFW.")

windowHint(RESIZABLE, false.cint)

let window = createWindow(
windowSize.x.cint, windowSize.y.cint, "GLFW + Boxy", nil, nil
)
let window = createWindow(windowSize.x, windowSize.y, "GLFW + Boxy", nil, nil)

makeContextCurrent(window)
loadExtensions()
Expand All @@ -30,12 +28,13 @@ proc display() =
bxy.beginFrame(windowSize)

# Draw the bg.
bxy.drawImage("bg", rect=rect(vec2(0, 0), windowSize))
bxy.drawImage("bg", rect = rect(vec2(0, 0), windowSize.vec2))

# Draw the rings.
bxy.drawImage("ring1", center=windowSize/2, angle = frame.float / 100)
bxy.drawImage("ring2", center=windowSize/2, angle = -frame.float / 190)
bxy.drawImage("ring3", center=windowSize/2, angle = frame.float / 170)
let center = windowSize.vec2 / 2
bxy.drawImage("ring1", center, angle = frame.float / 100)
bxy.drawImage("ring2", center, angle = -frame.float / 190)
bxy.drawImage("ring3", center, angle = frame.float / 170)

# End this frame, flushing the draw commands.
bxy.endFrame()
Expand Down
20 changes: 10 additions & 10 deletions src/boxy.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type
tileRun: int
takenTiles: BitArray ## Flag for if the tile is taken or not.
proj: Mat4
frameSize: Vec2 ## Dimensions of the window frame.
frameSize: IVec2 ## Dimensions of the window frame.
vertexArrayId, maskFramebufferId: GLuint
frameBegun, maskBegun: bool
pixelate: bool ## Makes texture look pixelated, like a pixel game.
Expand Down Expand Up @@ -160,7 +160,7 @@ proc createAtlasTexture(boxy: Boxy, size: int): Texture =
result.magFilter = magLinear
bindTextureData(result, nil)

proc addMaskTexture(boxy: Boxy, frameSize = vec2(1, 1)) =
proc addMaskTexture(boxy: Boxy, frameSize = ivec2(1, 1)) =
# Must be >0 for framebuffer creation below
# Set to real value in beginFrame
let maskTexture = Texture()
Expand Down Expand Up @@ -539,37 +539,37 @@ proc popMask*(boxy: Boxy) =
dec boxy.maskTextureWrite
boxy.maskTextureRead = boxy.maskTextureWrite

proc beginFrame*(boxy: Boxy, frameSize: Vec2, proj: Mat4) =
proc beginFrame*(boxy: Boxy, frameSize: IVec2, proj: Mat4) =
## Starts a new frame.
if boxy.frameBegun:
raise newException(BoxyError, "beginFrame has already been called")

boxy.frameBegun = true
boxy.proj = proj

if boxy.maskTextures[0].width != frameSize.x.int32 or
boxy.maskTextures[0].height != frameSize.y.int32:
if boxy.maskTextures[0].width != frameSize.x or
boxy.maskTextures[0].height != frameSize.y:
# Resize all of the masks.
boxy.frameSize = frameSize
for i in 0 ..< boxy.maskTextures.len:
boxy.maskTextures[i].width = frameSize.x.int32
boxy.maskTextures[i].height = frameSize.y.int32
boxy.maskTextures[i].width = frameSize.x
boxy.maskTextures[i].height = frameSize.y
if i > 0:
# Never resize the 0th mask because its just white.
bindTextureData(boxy.maskTextures[i], nil)

glViewport(0, 0, boxy.frameSize.x.GLint, boxy.frameSize.y.GLint)
glViewport(0, 0, boxy.frameSize.x, boxy.frameSize.y)

glClearColor(0, 0, 0, 0)
glClear(GL_COLOR_BUFFER_BIT)

boxy.clearMask()

proc beginFrame*(boxy: Boxy, frameSize: Vec2) {.inline.} =
proc beginFrame*(boxy: Boxy, frameSize: IVec2) {.inline.} =
beginFrame(
boxy,
frameSize,
ortho(0.float32, frameSize.x, frameSize.y, 0, -1000, 1000)
ortho(0.float32, frameSize.x.float32, frameSize.y.float32, 0, -1000, 1000)
)

proc endFrame*(boxy: Boxy) =
Expand Down
2 changes: 1 addition & 1 deletion src/boxy/glsl/100/atlas.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ varying vec2 pos;
varying vec2 uv;
varying vec4 color;

uniform vec2 windowFrame;
uniform ivec2 windowFrame;
uniform sampler2D atlasTex;
uniform sampler2D maskTex;

Expand Down
2 changes: 1 addition & 1 deletion src/boxy/glsl/100/mask.frag
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ varying vec2 pos;
varying vec2 uv;
varying vec4 color;

uniform vec2 windowFrame;
uniform ivec2 windowFrame;
uniform sampler2D atlasTex;
uniform sampler2D maskTex;

Expand Down
2 changes: 1 addition & 1 deletion src/boxy/glsl/410/atlas.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ in vec2 pos;
in vec2 uv;
in vec4 color;

uniform vec2 windowFrame;
uniform ivec2 windowFrame;
uniform sampler2D atlasTex;
uniform sampler2D maskTex;

Expand Down
2 changes: 1 addition & 1 deletion src/boxy/glsl/410/mask.frag
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ in vec2 pos;
in vec2 uv;
in vec4 color;

uniform vec2 windowFrame;
uniform ivec2 windowFrame;
uniform sampler2D atlasTex;
uniform sampler2D maskTex;

Expand Down