Skip to content
Snippets Groups Projects
Commit 5fd57a6a authored by Jonathan Kunstwald's avatar Jonathan Kunstwald
Browse files

Update cube sample to modern conventions, imgui, tg

parent 4f971804
Branches
No related tags found
No related merge requests found
#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)
{
if (mAnimate)
mRuntime += elapsedSeconds;
auto time = mAnimate ? mRuntime : 0.0f;
auto cam = getCamera();
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();
}
......@@ -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;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment