Skip to content

Commit

Permalink
Update example and callbacks for GLVisualize master
Browse files Browse the repository at this point in the history
  • Loading branch information
barche committed Oct 7, 2016
1 parent c567a72 commit b9b1c9d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
19 changes: 8 additions & 11 deletions example/glvisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion example/qml/glvisualize.qml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ ApplicationWindow {
id: jvp
Layout.fillWidth: true
Layout.fillHeight: true
renderFunction: "render"
renderFunction: "render_callback"
renderArguments: [angle.value]
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/glvisualize_callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type GLVisualizeState
scroll::Signal{Vec{2, Float64}}
hasfocus::Signal{Bool}
entered_window::Signal{Bool}
mouseinside::Signal{Bool}

screen::Screen

Expand All @@ -37,6 +38,7 @@ type GLVisualizeState
Signal(Vec(0.,0.)),
Signal(Vec(0.,0.)),
Signal(false),
Signal(false),
Signal(false)
)
end
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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

0 comments on commit b9b1c9d

Please sign in to comment.