From b9b1c9d1458452f03672c31b60082c28eaccd1ce Mon Sep 17 00:00:00 2001 From: Bart Janssens Date: Fri, 7 Oct 2016 23:11:36 +0200 Subject: [PATCH] Update example and callbacks for GLVisualize master Continuing on https://github.com/JuliaGL/GLVisualize.jl/issues/94 --- example/glvisualize.jl | 19 ++++++++----------- example/qml/glvisualize.qml | 2 +- src/glvisualize_callbacks.jl | 12 +++++++----- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/example/glvisualize.jl b/example/glvisualize.jl index 8ee9005..4fcecba 100644 --- a/example/glvisualize.jl +++ b/example/glvisualize.jl @@ -3,26 +3,23 @@ ENV["QSG_RENDER_LOOP"] = "basic" using QML using GLVisualize, GeometryTypes, GLAbstraction, Colors -using Reactive # 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) +function render_callback(degrees) + rotation_angle = Float32(degrees)*pi/180f0 + rotation = rotationmatrix_x(deg2rad(90f0)) * rotationmatrix_y(rotation_angle) + global robj if(!isdefined(:robj)) - robj = visualize(mesh, model=final_rotation) + robj = visualize(mesh, model=rotation) + _view(robj) end - push!(timesignal, Float32(t)) - - view(robj) + set_arg!(robj, :model, rotation) + #yield() # without this yield the rotation matrix is never updated end @qmlapp joinpath(dirname(@__FILE__), "qml", "glvisualize.qml") diff --git a/example/qml/glvisualize.qml b/example/qml/glvisualize.qml index 585d226..e170c3b 100644 --- a/example/qml/glvisualize.qml +++ b/example/qml/glvisualize.qml @@ -42,7 +42,7 @@ ApplicationWindow { id: jvp Layout.fillWidth: true Layout.fillHeight: true - renderFunction: "render" + renderFunction: "render_callback" renderArguments: [angle.value] } } diff --git a/src/glvisualize_callbacks.jl b/src/glvisualize_callbacks.jl index 54029a6..1d92405 100644 --- a/src/glvisualize_callbacks.jl +++ b/src/glvisualize_callbacks.jl @@ -22,6 +22,7 @@ type GLVisualizeState scroll::Signal{Vec{2, Float64}} hasfocus::Signal{Bool} entered_window::Signal{Bool} + mouseinside::Signal{Bool} screen::Screen @@ -37,6 +38,7 @@ type GLVisualizeState Signal(Vec(0.,0.)), Signal(Vec(0.,0.)), Signal(false), + Signal(false), Signal(false) ) end @@ -98,7 +100,7 @@ function on_framebuffer_setup(state, handle, width, height) state.screen.glcontext = GLWindow.GLContext(window, fb) end - GLVisualize.set_root_screen(state.screen) + GLVisualize.add_screen(state.screen) GLWindow.add_complex_signals!(state.screen) end @@ -115,8 +117,8 @@ end function qml_render(x::Screen, parent::Screen=x, context=x.area.value) 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 + glClearColor(red(x.color), green(x.color), blue(x.color), alpha(x.color)) + colorbits = colorbits | GL_COLOR_BUFFER_BIT end glClear(colorbits) @@ -129,6 +131,6 @@ end function render_glvisualize_scene(state) fb = GLWindow.framebuffer(state.screen) qml_render(state.screen) - GLWindow.push_selectionqueries!(state.screen) - GLWindow.render(fb.postprocess) + # GLWindow.push_selectionqueries!(state.screen) + #GLWindow.render(fb.postprocess) end