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

Working on shadows. #43

Merged
merged 7 commits into from
Aug 14, 2022
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
2 changes: 1 addition & 1 deletion boxy.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ license = "MIT"
srcDir = "src"

requires "nim >= 1.2.2"
requires "shady >= 0.1.1"
requires "shady >= 0.1.3"
requires "pixie >= 4.3.0"
requires "opengl >= 1.2.6"
requires "bitty >= 0.1.4"
2 changes: 1 addition & 1 deletion examples/blur.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ window.onFrame = proc() =
let radius = 50 * (sin(frame.float32/100) + 1)

# Blurs the current pushed layer.
bxy.blurLayer(radius)
bxy.blurEffect(radius)

bxy.popLayer()

Expand Down
8 changes: 4 additions & 4 deletions examples/layer_tints.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ window.onFrame = proc() =
bxy.drawImage("greece", center = vec2(0, 0), angle = 0, color(1, 1, 1, 1))
bxy.restoreTransform()

bxy.popLayer(tintColor = color(1, 1, 1, 0.5))
bxy.popLayer(tintColor = color(1, 1, 1, 0.5))
bxy.popLayer(tintColor = color(1, 1, 1, 0.5))
bxy.popLayer(tintColor = color(1, 1, 1, 0.5))
bxy.popLayer(tint = color(1, 1, 1, 0.5))
bxy.popLayer(tint = color(1, 1, 1, 0.5))
bxy.popLayer(tint = color(1, 1, 1, 0.5))
bxy.popLayer(tint = color(1, 1, 1, 0.5))

# End this frame, flushing the draw commands.
bxy.endFrame()
Expand Down
2 changes: 1 addition & 1 deletion examples/layers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ window.onFrame = proc() =
bxy.drawImage("mask", center = vec2(0, 0), angle = 0, color(1, 1, 1, 1))
bxy.restoreTransform()

bxy.popLayer(tintColor = c2)
bxy.popLayer(tint = c2)

# End this frame, flushing the draw commands.
bxy.endFrame()
Expand Down
2 changes: 1 addition & 1 deletion examples/masking.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ window.onFrame = proc() =
"mask",
center = window.size.vec2 / 2,
angle = 0,
tintColor = color(1, 0, 0, 1)
tint = color(1, 0, 0, 1)
)
bxy.popLayer(blendMode = MaskBlend)

Expand Down
56 changes: 56 additions & 0 deletions examples/shadow.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import boxy, opengl, windy

let window = newWindow("Boxy Shadow", ivec2(1280, 800))
makeContextCurrent(window)
loadExtensions()

let bxy = newBoxy()

# Load the image.
bxy.addImage("mask", readImage("examples/data/mask.png"))

var frame: int

# Called when it is time to draw a new frame.
window.onFrame = proc() =
# Clear the screen and begin a new frame.
bxy.beginFrame(window.size)

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

bxy.pushLayer()

bxy.saveTransform()
bxy.translate(window.size.vec2/2)
bxy.drawImage(
"mask",
center = vec2(0, 0),
angle = 0,
tint = color(1, 1, 1, 1)
)
bxy.restoreTransform()

# Set the shadow blur amount based on time.
let radius = 50 * (sin(frame.float32/100) + 1)

# Shadow follows the mouse.
let mouse = ivec2(window.mousePos.x, window.mousePos.y).vec2

bxy.dropShadowEffect(
color(0, 0, 0, 1),
(mouse - window.size.vec2/2) / 10,
radius,
10
)

bxy.popLayer()

# End this frame, flushing the draw commands.
bxy.endFrame()
# Swap buffers displaying the new Boxy frame.
window.swapBuffers()
inc frame

while not window.closeRequested:
pollEvents()
Loading