From: Mikko Rasa Date: Thu, 13 Nov 2014 21:09:33 +0000 (+0200) Subject: Use a Camera rather than direct matrix manipulation X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2b1a962fba03a01d641f5b6e2b8d75c6e71e2d40;p=libs%2Fgltk.git Use a Camera rather than direct matrix manipulation --- diff --git a/source/root.cpp b/source/root.cpp index de24727..f4bad55 100644 --- a/source/root.cpp +++ b/source/root.cpp @@ -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) diff --git a/source/root.h b/source/root.h index a74065d..b79bca3 100644 --- a/source/root.h +++ b/source/root.h @@ -2,6 +2,7 @@ #define MSP_GLTK_ROOT_H_ #include +#include #include #include #include @@ -32,6 +33,7 @@ private: int pointer_y; Time::TimeStamp tooltip_timeout; Widget *tooltip_target; + Msp::GL::Camera camera; public: /** Creates a Root widget for a window. The geometry is set to match the @@ -64,7 +66,9 @@ private: bool character_event(StringCodec::unichar); void get_pointer(int &, int &); + void update_camera(); + virtual void on_geometry_change(); virtual void on_child_added(Widget &); };