Advertisement
Guest User

Untitled

a guest
May 3rd, 2015
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. using Romeo, GLFW, GLAbstraction, Reactive, ModernGL, GLWindow, Color, ImmutableArrays
  2.  
  3. function main()
  4. root_screen = Romeo.ROOT_SCREEN
  5.  
  6. screenAarea = lift(root_screen.area) do area
  7. Rectangle{Int}(0, 0, div(area.w, 2), area.h)
  8. end
  9. screenBarea = lift(root_screen.area) do area
  10. Rectangle{Int}(div(area.w, 2), 0, div(area.w, 2), area.h)
  11. end
  12. global_inputs = root_screen.inputs
  13. #checks if mouse is inside screenA or B
  14. insidescreen = lift(global_inputs[:mouseposition]) do mpos
  15. isinside(screenAarea.value, mpos...) || isinside(screenBarea.value, mpos...)
  16. end
  17. # creates signals for the camera, which are only active if mouse is inside screen
  18. camera_input = merge(global_inputs, Dict(
  19. :mouseposition => keepwhen(insidescreen, Vector2(0.0), global_inputs[:mouseposition]),
  20. :scroll_x => keepwhen(insidescreen, 0, global_inputs[:scroll_x]),
  21. :scroll_y => keepwhen(insidescreen, 0, global_inputs[:scroll_y]),
  22. ))
  23. #this is the reason we have to go through all this. For the correct perspective projection, the camera needs the correct screen rectangle.
  24. camera_input[:window_size] = lift(x->Vector4(x.x, x.y, x.w, x.h), screenAarea)
  25. # creates cameras for the sceen with the new inputs
  26. ocameraA = OrthographicPixelCamera(camera_input)
  27. pcameraA = PerspectiveCamera(camera_input, Vec3(2), Vec3(0))
  28. camera_input[:window_size] = lift(x->Vector4(x.x, x.y, x.w, x.h), screenBarea)
  29. # creates cameras for the sceen with the new inputs
  30. ocameraB = OrthographicPixelCamera(camera_input)
  31. pcameraB = PerspectiveCamera(camera_input, Vec3(2), Vec3(0))
  32. #make the cameras share the same view matrix (notice, they still have different projection matrices)
  33. pcameraB.view = pcameraA.view
  34. #call the ugly Screen constructor
  35. screenA = Screen(screenAarea, root_screen, Screen[], root_screen.inputs, RenderObject[], root_screen.hidden, root_screen.hasfocus, pcameraA, ocameraA, root_screen.nativewindow)
  36. screenB = Screen(screenBarea, root_screen, Screen[], root_screen.inputs, RenderObject[], root_screen.hidden, root_screen.hasfocus, pcameraB, ocameraB, root_screen.nativewindow)
  37. push!(root_screen.children, screenA)
  38. push!(root_screen.children, screenB)
  39.  
  40. vizA = visualize(Float32[sin(i)sin(j) for i=0:0.1:5, j=0:0.1:5], primitive=SURFACE(), screen=screenA)
  41. vizB = visualize(rand(Float32, 10, 13), :zscale, primitive=CUBE(), screen=screenB)
  42.  
  43. push!(screenA.renderlist, vizA)
  44. push!(screenB.renderlist, vizB)
  45.  
  46. end
  47. main()
  48.  
  49. while Romeo.ROOT_SCREEN.inputs[:open].value
  50. glEnable(GL_SCISSOR_TEST)
  51. Romeo.renderloop(Romeo.ROOT_SCREEN)
  52. sleep(0.0001)
  53. end
  54. GLFW.Terminate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement