diff --git a/samples/basic/cube/CubeSample.cc b/samples/basic/cube/CubeSample.cc index 420944650149505f9843e682a17bdb4a255e364a..864e3ba1bbe79d65bf47b07ae3bad3b76fc6f70f 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 cb4d75d6f78e8aaf7cd5204cc7e939ae1f7fb964..71b0c55788741979255b6318f8d6a5cbe0093f9a 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; };