Skip to content

Commit

Permalink
workaround for draw_list 2^16 limit
Browse files Browse the repository at this point in the history
  • Loading branch information
inkydragon committed Sep 1, 2019
1 parent b1b0061 commit 1df4ac6
Showing 1 changed file with 51 additions and 16 deletions.
67 changes: 51 additions & 16 deletions test/Fractals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ ImGui_ImplOpenGL3_Init(glsl_version)
rule_list = getAllRules()

while !GLFW.WindowShouldClose(window)

GLFW.PollEvents()
# start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame()
Expand All @@ -64,11 +63,11 @@ while !GLFW.WindowShouldClose(window)
CImGui.Text("L-Systems")
listbox_item_current, listbox_items = @cstatic listbox_item_current=Cint(0) listbox_items=rule_list begin
# list box
@c CImGui.ListBox("L-Systems\n(click to select one)", &listbox_item_current, listbox_items, length(listbox_items), 3)
@c CImGui.ListBox("L-Systems\n(click to select one)", &listbox_item_current, listbox_items, length(listbox_items), 5)
end
CImGui.Text("L-System parameters")
iter, angle, slen = @cstatic iter=Cint(4) angle=Cfloat(0.0) slen=Cfloat(10) begin
@c CImGui.CImGui.SliderInt("Iteration times", &iter, 1, 6, "%d")
@c CImGui.CImGui.SliderInt("Iteration times", &iter, 1, 8, "%d")
@c CImGui.DragFloat("Initial angle", &angle, 1, -180.0, 180.0, "%.0f")
@c CImGui.DragFloat("Step length", &slen, 0.5, 0.5, 30, "%.0f")
end
Expand All @@ -78,17 +77,22 @@ while !GLFW.WindowShouldClose(window)
thickness, col = @cstatic thickness=Cfloat(2.0) col=Cfloat[1.0,1.0,0.4,1.0] begin
@c CImGui.DragFloat("Width", &thickness, 0.05, 1.0, 8.0, "%.02f")
CImGui.ColorEdit4("Color", col)
end
end
CImGui.Text("Adjust Original Point")
dx, dy = @cstatic dx=Cfloat(256.0) dy=Cfloat(128.0) begin
@c CImGui.DragFloat("dx ->", &dx, 4, 0.0, 512.0, "%.0f")
@c CImGui.DragFloat("dy V", &dy, 4, 0.0, 512.0, "%.0f")
@c CImGui.DragFloat("dx ->", &dx, 4, 0.0, 4096.0, "%.0f")
@c CImGui.DragFloat("dy V", &dy, 4, 0.0, 2048.0, "%.0f")
end
CImGui.Separator()


@cstatic currentChild = 0
wpos = CImGui.GetWindowPos()
backupPos = CImGui.GetCursorScreenPos()

# draw lines
p = CImGui.GetCursorScreenPos()
col32 = CImGui.ColorConvertFloat4ToU32(ImVec4(col...))

begin
x::Cfloat = p.x + 4.0 + dx
y::Cfloat = p.y + 4.0 + dy
Expand All @@ -102,17 +106,48 @@ while !GLFW.WindowShouldClose(window)

# L System
steps = genStep(RULES[listbox_item_current+1], param)
for ((sx, sy), (ex, ey)) in steps
CImGui.AddLine(draw_list,
ImVec2(sx, sy),
ImVec2(ex, ey),
col32,
th
);
slen = length(steps)
if slen > (2^13 - 8)
times = Int(floor(slen/(2^13 - 8)))
idxm = (2^13 - 8)
for i in 0:(times-1)
CImGui.SetCursorScreenPos(backupPos)
CImGui.BeginChild(currentChild+=1)
draw_list = CImGui.GetWindowDrawList()
for ((sx, sy), (ex, ey)) in steps[(1+idxm*i):idxm*(1+i)]
CImGui.AddLine(draw_list,
ImVec2(sx, sy),
ImVec2(ex, ey),
col32,
th
);
end
CImGui.EndChild()
end
CImGui.SetCursorScreenPos(backupPos)
CImGui.BeginChild(currentChild+=1)
draw_list = CImGui.GetWindowDrawList()
for ((sx, sy), (ex, ey)) in steps[(1+idxm*times):end]
CImGui.AddLine(draw_list,
ImVec2(sx, sy),
ImVec2(ex, ey),
col32,
th
);
end
CImGui.EndChild()
else
for ((sx, sy), (ex, ey)) in steps
CImGui.AddLine(draw_list,
ImVec2(sx, sy),
ImVec2(ex, ey),
col32,
th
);
end
end

end

CImGui.End() #= widgets end ---------------------------------------------=#

# rendering
Expand Down

0 comments on commit 1df4ac6

Please sign in to comment.