From c567a72add08a5caa61a6ca927807d2de87ed1cb Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Fri, 30 Sep 2016 19:17:28 +0200 Subject: [PATCH] Get the GLVisualize cat to spin See issue https://github.com/JuliaGL/GLVisualize.jl/issues/94 --- example/glvisualize.jl | 51 +++++++++--------------------------- example/qml/glvisualize.qml | 16 ++++++++--- src/glvisualize_callbacks.jl | 35 +++++++++---------------- 3 files changed, 36 insertions(+), 66 deletions(-) diff --git a/example/glvisualize.jl b/example/glvisualize.jl index 6e88382..8ee9005 100644 --- a/example/glvisualize.jl +++ b/example/glvisualize.jl @@ -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() diff --git a/example/qml/glvisualize.qml b/example/qml/glvisualize.qml index 72366b1..585d226 100644 --- a/example/qml/glvisualize.qml +++ b/example/qml/glvisualize.qml @@ -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() + "°" } } @@ -35,7 +43,7 @@ ApplicationWindow { Layout.fillWidth: true Layout.fillHeight: true renderFunction: "render" - renderArguments: [time.value] + renderArguments: [angle.value] } } diff --git a/src/glvisualize_callbacks.jl b/src/glvisualize_callbacks.jl index 4c97d06..54029a6 100644 --- a/src/glvisualize_callbacks.jl +++ b/src/glvisualize_callbacks.jl @@ -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