Skip to content

Commit 1fef735

Browse files
committed
Expose color argument for Frustum
1 parent 0f9e0a8 commit 1fef735

File tree

3 files changed

+54
-45
lines changed

3 files changed

+54
-45
lines changed

examples/demo.jl

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ using LinearAlgebra
44
using StaticArrays
55
using NeuralGraphicsGL
66

7+
import NeuralGraphicsGL as NGL
8+
79
function main()
8-
NeuralGraphicsGL.init()
9-
context = NeuralGraphicsGL.Context("でも"; width=1280, height=960)
10-
NeuralGraphicsGL.set_resize_callback!(context, NeuralGraphicsGL.resize_callback)
10+
NGL.init()
11+
context = NGL.Context("でも"; width=1280, height=960)
12+
NGL.set_resize_callback!(context, NGL.resize_callback)
1113

12-
bbox = NeuralGraphicsGL.Box(zeros(SVector{3, Float32}), ones(SVector{3, Float32}))
14+
bbox = NGL.Box(zeros(SVector{3, Float32}), ones(SVector{3, Float32}))
1315
P = SMatrix{4, 4, Float32}(I)
1416
V = SMatrix{4, 4, Float32}(I)
1517

@@ -24,33 +26,33 @@ function main()
2426
voxels_data_2 = Float32[
2527
0f0, 0f0, 0f0, 1f0, 0.1f0,
2628
0.2f0, 0f0, 0f0, 0.5f0, 0.1f0]
27-
voxels = NeuralGraphicsGL.Voxels(Float32[])
29+
voxels = NGL.Voxels(Float32[])
2830

29-
NeuralGraphicsGL.enable_blend()
31+
NGL.enable_blend()
3032

31-
NeuralGraphicsGL.render_loop(context; destroy_context=false) do
32-
NeuralGraphicsGL.imgui_begin(context)
33-
NeuralGraphicsGL.clear()
34-
NeuralGraphicsGL.set_clear_color(0.2, 0.2, 0.2, 1.0)
33+
NGL.render_loop(context; destroy_context=false) do
34+
NGL.imgui_begin(context)
35+
NGL.clear()
36+
NGL.set_clear_color(0.2, 0.2, 0.2, 1.0)
3537

3638
# bmin = zeros(SVector{3, Float32}) .- Float32(delta_time) * 5f0
3739
# bmax = ones(SVector{3, Float32}) .- Float32(delta_time) * 5f0
38-
# NeuralGraphicsGL.update_corners!(bbox, bmin, bmax)
39-
# NeuralGraphicsGL.draw(bbox, P, V)
40+
# NGL.update_corners!(bbox, bmin, bmax)
41+
# NGL.draw(bbox, P, V)
4042

41-
NeuralGraphicsGL.draw_instanced(voxels, P, V)
43+
NGL.draw_instanced(voxels, P, V)
4244

4345
if 2 < elapsed_time < 4
44-
NeuralGraphicsGL.update!(voxels, voxels_data_2)
46+
NGL.update!(voxels, voxels_data_2)
4547
elseif elapsed_time > 4
46-
NeuralGraphicsGL.update!(voxels, voxels_data)
48+
NGL.update!(voxels, voxels_data)
4749
end
4850

4951
CImGui.Begin("UI")
5052
CImGui.Text("HI!")
5153
CImGui.End()
5254

53-
NeuralGraphicsGL.imgui_end(context)
55+
NGL.imgui_end(context)
5456
glfwSwapBuffers(context.window)
5557
glfwPollEvents()
5658

@@ -60,8 +62,8 @@ function main()
6062
true
6163
end
6264

63-
NeuralGraphicsGL.delete!(voxels)
64-
NeuralGraphicsGL.delete!(bbox)
65-
NeuralGraphicsGL.delete!(context)
65+
NGL.delete!(voxels)
66+
NGL.delete!(bbox)
67+
NGL.delete!(context)
6668
end
6769
main()

examples/framebuffer_demo.jl

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,55 +8,59 @@ using FileIO
88
using ImageIO
99
using NeuralGraphicsGL
1010

11+
import NeuralGraphicsGL as NGL
12+
1113
function main()
12-
NeuralGraphicsGL.init()
13-
context = NeuralGraphicsGL.Context("でも"; width=1280, height=960, resizable=false)
14-
fb = NeuralGraphicsGL.Framebuffer(; width=1280, height=960)
15-
screen = NeuralGraphicsGL.Screen()
14+
NGL.init()
15+
context = NGL.Context("でも"; width=1280, height=960, resizable=false)
16+
fb = NGL.Framebuffer(; width=1280, height=960)
17+
screen = NGL.Screen()
1618

17-
bbox = NeuralGraphicsGL.BBox(zeros(SVector{3, Float32}), ones(SVector{3, Float32}))
19+
bbox = NGL.BBox(zeros(SVector{3, Float32}), ones(SVector{3, Float32}))
20+
frustum = NGL.Frustum()
1821
P = SMatrix{4, 4, Float32}(I)
1922
V = SMatrix{4, 4, Float32}(I)
2023

2124
delta_time = 0.0
2225
last_time = time()
2326
elapsed_time = 0.0
2427

25-
NeuralGraphicsGL.render_loop(context; destroy_context=false) do
26-
NeuralGraphicsGL.imgui_begin(context)
28+
NGL.render_loop(context; destroy_context=false) do
29+
NGL.imgui_begin(context)
2730

28-
NeuralGraphicsGL.bind(fb)
31+
NGL.bind(fb)
2932

30-
NeuralGraphicsGL.enable_depth()
31-
NeuralGraphicsGL.set_clear_color(0.2, 0.2, 0.2, 1.0)
32-
NeuralGraphicsGL.clear()
33+
NGL.enable_depth()
34+
NGL.set_clear_color(0.2, 0.2, 0.2, 1.0)
35+
NGL.clear()
3336

3437
bmin = zeros(SVector{3, Float32}) .- Float32(delta_time) * 5f0
3538
bmax = ones(SVector{3, Float32}) .- Float32(delta_time) * 5f0
36-
NeuralGraphicsGL.update_corners!(bbox, bmin, bmax)
37-
NeuralGraphicsGL.draw(bbox, P, V)
39+
NGL.update_corners!(bbox, bmin, bmax)
40+
NGL.draw(bbox, P, V; color=SVector{4, Float32}(0f0, 1f0, 0f0, 1f0))
41+
NGL.draw(frustum, V, P, V; color=SVector{4, Float32}(0f0, 1f0, 0f0, 1f0))
3842

39-
NeuralGraphicsGL.unbind(fb)
43+
NGL.unbind(fb)
4044

41-
NeuralGraphicsGL.disable_depth()
42-
NeuralGraphicsGL.set_clear_color(0.0, 0.0, 0.0, 1.0)
43-
NeuralGraphicsGL.clear(GL_COLOR_BUFFER_BIT)
45+
NGL.disable_depth()
46+
NGL.set_clear_color(0.0, 0.0, 0.0, 1.0)
47+
NGL.clear(GL_COLOR_BUFFER_BIT)
4448

4549
screen_texture = fb[GL_COLOR_ATTACHMENT0]
46-
drawed_data = NeuralGraphicsGL.get_data(screen_texture)
50+
drawed_data = NGL.get_data(screen_texture)
4751
save("screen.png", rotl90(colorview(RGB{N0f8}, drawed_data)))
4852

4953
depth_texture = fb[GL_DEPTH_ATTACHMENT]
50-
depth_data = NeuralGraphicsGL.get_data(depth_texture)[1, :, :]
54+
depth_data = NGL.get_data(depth_texture)[1, :, :]
5155
save("depth.png", rotl90(colorview(Gray{Float32}, depth_data)))
5256

53-
NeuralGraphicsGL.draw(screen, screen_texture)
57+
NGL.draw(screen, screen_texture)
5458

5559
CImGui.Begin("UI")
5660
CImGui.Text("HI!")
5761
CImGui.End()
5862

59-
NeuralGraphicsGL.imgui_end(context)
63+
NGL.imgui_end(context)
6064
glfwSwapBuffers(context.window)
6165
glfwPollEvents()
6266

@@ -67,9 +71,9 @@ function main()
6771
false
6872
end
6973

70-
NeuralGraphicsGL.delete!(bbox)
71-
NeuralGraphicsGL.delete!(screen)
72-
NeuralGraphicsGL.delete!(fb)
73-
NeuralGraphicsGL.delete!(context)
74+
NGL.delete!(bbox)
75+
NGL.delete!(screen)
76+
NGL.delete!(fb)
77+
NGL.delete!(context)
7478
end
7579
main()

src/frustum.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ end
1818
- `fL`: Frustum camera's look at matrix.
1919
- `P`: User controlled camera's perspective matrix.
2020
- `L`: User controlled camera's look at matrix.
21+
- `color`: Color of the frustum.
2122
"""
22-
draw(f::Frustum, fL, P, L) = draw(f.box_clip_space, P, L * inv(fL))
23+
function draw(f::Frustum, fL, P, L; color::SVec4f0 = SVec4f0(1f0, 0f0, 0f0, 1f0))
24+
draw(f.box_clip_space, P, L * inv(fL); color)
25+
end

0 commit comments

Comments
 (0)