]> git.tdb.fi Git - libs/gltk.git/blobdiff - source/root.cpp
Use a Camera rather than direct matrix manipulation
[libs/gltk.git] / source / root.cpp
index de2472797199108870d8b045679d53019ad815a8..f4bad55beb546dfa91ee0dd9d960a7a0451b2fed 100644 (file)
@@ -35,6 +35,9 @@ void Root::init(Graphics::Window *window)
        lbl_tooltip = 0;
        tooltip_target = 0;
 
+       camera.set_orthographic(geom.w, geom.h);
+       update_camera();
+
        update_style();
 
        if(mouse)
@@ -109,11 +112,9 @@ void Root::tick()
 
 void Root::render() const
 {
-       GL::MatrixStack::projection() = GL::Matrix::ortho_bottomleft(geom.w, geom.h);
-       GL::MatrixStack::modelview() = GL::Matrix();
        GL::Bind bind_blend(GL::Blend::alpha());
 
-       GL::Renderer renderer(0);
+       GL::Renderer renderer(&camera);
        Widget::render(renderer);
 }
 
@@ -231,6 +232,19 @@ void Root::get_pointer(int &x, int &y)
        y = (mouse->get_axis_value(1)*0.5+0.5)*geom.h;
 }
 
+void Root::update_camera()
+{
+       camera.set_position(GL::Vector3(geom.w/2.0f, geom.h/2.0f, geom.h/2.0f));
+       camera.set_depth_clip(geom.h*0.1f, geom.h*0.9f);
+       camera.set_orthographic(geom.w, geom.h);
+}
+
+void Root::on_geometry_change()
+{
+       Panel::on_geometry_change();
+       update_camera();
+}
+
 void Root::on_child_added(Widget &wdg)
 {
        if(&wdg!=lbl_tooltip)