From 5fd57a6a5345742092f1065d6e0302c62bfe9c17 Mon Sep 17 00:00:00 2001
From: Jonathan Kunstwald <jonathan.kunstwald@rwth-aachen.de>
Date: Mon, 26 Aug 2019 15:39:50 +0200
Subject: [PATCH] Update cube sample to modern conventions, imgui, tg

---
 samples/basic/cube/CubeSample.cc | 42 +++++++++++++++++---------------
 samples/basic/cube/CubeSample.hh |  3 ++-
 2 files changed, 24 insertions(+), 21 deletions(-)

diff --git a/samples/basic/cube/CubeSample.cc b/samples/basic/cube/CubeSample.cc
index 4209446..864e3ba 100644
--- a/samples/basic/cube/CubeSample.cc
+++ b/samples/basic/cube/CubeSample.cc
@@ -1,49 +1,51 @@
 #include "CubeSample.hh"
 
-#include <glow/objects/Program.hh>
-#include <glow/objects/Shader.hh>
-#include <glow/objects/VertexArray.hh>
+#include <imgui/imgui.h>
+
+#include <typed-geometry/tg.hh>
 
 #include <glow/common/scoped_gl.hh>
 #include <glow/common/str_utils.hh>
+#include <glow/objects/Program.hh>
+#include <glow/objects/Shader.hh>
+#include <glow/objects/VertexArray.hh>
 
 #include <glow-extras/geometry/Cube.hh>
 
-#include <AntTweakBar.h>
-
 using namespace glow;
-using namespace glow::camera;
 
 void CubeSample::init()
 {
-    setGui(GlfwApp::Gui::AntTweakBar);
     GlfwApp::init(); // call to base!
 
     mShader = Program::createFromFile(util::pathOf(__FILE__) + "/shader");
     mCube = geometry::Cube<>().generate();
 
-    auto cam = getCamera();
-    cam->setLookAt({2, 5, 4}, {0, 0, 0});
-
-    TwAddVarRW(tweakbar(), "Animate", TW_TYPE_BOOLCPP, &mAnimate, "");
+    getCamera()->setLookAt({2, 5, 4}, {0, 0, 0});
 }
 
 void CubeSample::render(float elapsedSeconds)
 {
-    mRuntime += elapsedSeconds;
-    auto time = mAnimate ? mRuntime : 0.0f;
-
-    auto cam = getCamera();
+    if (mAnimate)
+        mRuntime += elapsedSeconds;
 
     GLOW_SCOPED(clearColor, 0, 0, 0, 1);
-    GLOW_SCOPED(enable, GL_DEPTH_TEST);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
 
+    GLOW_SCOPED(enable, GL_DEPTH_TEST);
+
     auto shader = mShader->use();
-    shader.setUniform("uRuntime", time);
-    shader.setUniform("uView", cam->getViewMatrix());
-    shader.setUniform("uProj", cam->getProjectionMatrix());
-    shader.setUniform("uModel", glm::rotate(time, glm::vec3{0, 1, 0}));
+    shader["uRuntime"] = mRuntime;
+    shader["uView"] = getCamera()->getViewMatrix();
+    shader["uProj"] = getCamera()->getProjectionMatrix();
+    shader["uModel"] = tg::rotation_around(tg::dir3{0, 1, 0}, tg::radians(mRuntime));
 
     mCube->bind().draw();
 }
+
+void CubeSample::onGui()
+{
+    ImGui::Begin("Cube Sample");
+    ImGui::Checkbox("Animate", &mAnimate);
+    ImGui::End();
+}
diff --git a/samples/basic/cube/CubeSample.hh b/samples/basic/cube/CubeSample.hh
index cb4d75d..71b0c55 100644
--- a/samples/basic/cube/CubeSample.hh
+++ b/samples/basic/cube/CubeSample.hh
@@ -9,7 +9,7 @@
 class CubeSample : public glow::glfw::GlfwApp
 {
 public:
-    CubeSample() : GlfwApp(Gui::AntTweakBar) {}
+    CubeSample() : GlfwApp(Gui::ImGui) {}
 
 private:
     glow::SharedProgram mShader;
@@ -21,4 +21,5 @@ private:
 protected:
     void init() override;
     void render(float elapsedSeconds) override;
+    void onGui() override;
 };
-- 
GitLab