Skip to content

Commit

Permalink
Get the GLVisualize cat to spin
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Sep 30, 2016
1 parent 74efa7a commit c567a72
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 66 deletions.
51 changes: 12 additions & 39 deletions example/glvisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,25 @@ using QML
using GLVisualize, GeometryTypes, GLAbstraction, Colors
using Reactive

# lines2d example
const N = 2048
function spiral(i, start_radius, offset)
Point2f0(sin(i), cos(i)) * (start_radius + ((i/2pi)*offset))
end
# 2D particles
curve_data(i, N) = Point2f0[spiral(i+x/20f0, 1, (i/20)+1) for x=1:N]

timesignal = Signal(0.)

t = const_lift(x-> (1f0-x)*100f0, timesignal)
color = map(RGBA{Float32}, colormap("Blues", N))

# The qml_time parameter is a Float64 from the QML slider
function render(qml_time)
# Cat example from GLVisualize
mesh = loadasset("cat.obj")
timesignal = Signal(0f0)
rotation_angle = const_lift(*, timesignal, 1f0*pi/180f0)
start_rotation = Signal(rotationmatrix_x(deg2rad(90f0)))
rotation = map(rotationmatrix_y, rotation_angle)
final_rotation = map(*, start_rotation, rotation)

# Render function that takes a parameter t from a QML slider
function render(t)
global robj
if(!isdefined(:robj))
robj = visualize(const_lift(curve_data, t, N), :lines, color=color)
robj = visualize(mesh, model=final_rotation)
end

push!(timesignal, qml_time)
push!(timesignal, Float32(t))

view(robj)

return
end

# Cat example shows up blank
# mesh = loadasset("cat.obj")
# timesignal = Signal(0.)
# rotation_angle = const_lift(*, timesignal, 2f0*pi)
# start_rotation = Signal(rotationmatrix_x(deg2rad(90f0)))
# rotation = map(rotationmatrix_y, rotation_angle)
# final_rotation = map(*, start_rotation, rotation)
#
# # Render function that takes a parameter t from a QML slider
# function render(t)
# global robj
# if(!isdefined(:robj))
# robj = visualize(mesh, model=final_rotation)
# end
#
# push!(timesignal, t)
#
# view(robj)
# end

@qmlapp joinpath(dirname(@__FILE__), "qml", "glvisualize.qml")
exec()
16 changes: 12 additions & 4 deletions example/qml/glvisualize.qml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,22 @@ ApplicationWindow {
Layout.alignment: Qt.AlignCenter

Text {
text: "t:"
text: "Angle:"
}

Slider {
id: time
id: angle
value: 0.
minimumValue: 0.
maximumValue: 1.
maximumValue: 360.
}
}

RowLayout {
Layout.fillWidth: true
Layout.alignment: Qt.AlignCenter
Text {
text: (Math.round(angle.value * 100) / 100).toString() + "°"
}
}

Expand All @@ -35,7 +43,7 @@ ApplicationWindow {
Layout.fillWidth: true
Layout.fillHeight: true
renderFunction: "render"
renderArguments: [time.value]
renderArguments: [angle.value]
}
}

Expand Down
35 changes: 12 additions & 23 deletions src/glvisualize_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,33 +113,22 @@ end

# Copy of the render function from GLWindow, Screen should be abstract so isopen and ishidden can be overridden
function qml_render(x::Screen, parent::Screen=x, context=x.area.value)
sa = value(x.area)
sa = SimpleRectangle(context.x+sa.x, context.y+sa.y, sa.w, sa.h) # bring back to absolute values
pa = context
sa_pa = intersect(pa, sa) # intersection with parent
if sa_pa != SimpleRectangle{Int}(0,0,0,0) # if it is in the parent area
#glEnable(GL_SCISSOR_TEST)
#glScissor(sa_pa)
#glViewport(sa)
colorbits = GL_DEPTH_BUFFER_BIT
if alpha(x.color) > 0
glClearColor(red(x.color), green(x.color), blue(x.color), alpha(x.color))
colorbits = colorbits | GL_COLOR_BUFFER_BIT
end
glClear(colorbits)

render(x.renderlist)
for window in x.children
render(window, x, sa)
end
end
colorbits = GL_DEPTH_BUFFER_BIT
if alpha(x.color) > 0
glClearColor(red(x.color), green(x.color), blue(x.color), alpha(x.color))
colorbits = colorbits | GL_COLOR_BUFFER_BIT
end
glClear(colorbits)

render(x.renderlist)
if !isempty(x.children)
println("warning: screen used in QML has children, but they are ignored")
end
end

function render_glvisualize_scene(state)
fb = GLWindow.framebuffer(state.screen)
GLWindow.prepare(fb)
qml_render(state.screen)
GLWindow.push_selectionqueries!(state.screen)
GLWindow.display(fb, state.screen)
#GLWindow.swapbuffers(state.screen)
GLWindow.render(fb.postprocess)
end

0 comments on commit c567a72

Please sign in to comment.