KlassischeKeplerKriege/game/game_window.hpp

48 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2016-09-27 17:01:21 +00:00
#include "opengl.hpp"
#include "renderer.hpp"
2016-09-28 05:03:29 +00:00
#include "renderer_simple.hpp"
#include "renderer_shader.hpp"
#include "game.hpp"
class GameWindow : public endofthejedi::GLWindow {
2016-09-27 18:56:17 +00:00
private:
2016-09-28 01:33:01 +00:00
Game m_game;
2016-09-28 05:03:29 +00:00
endofthejedi::RendererSimple m_renderer;
2016-09-28 01:33:01 +00:00
2016-09-27 18:56:17 +00:00
protected:
void init() override {
glClearColor(0.5f, 0.6f, 0.7f, 1.0f);
resize();
glEnable(GL_DEPTH_TEST);
}
void render(double time) override {
2016-09-27 18:56:17 +00:00
// static bool once = false;
// if (!once) {
// once = true;
// for (int i=0; i<1000; i++) {
// m_game.cycle(time);
// }
//}
2016-09-27 18:56:17 +00:00
if (!m_game.cycle(static_cast<float>(time / 1000000000.0))) {
std::cout << "stopping the game..." << std::endl;
stop();
}
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
2016-09-28 01:33:01 +00:00
m_renderer.render(m_game.state());
}
void resize() override { glViewport(0, 0, getwidth(), getheight()); }
2016-09-27 18:56:17 +00:00
public:
GameWindow(unsigned int width, unsigned int height)
: endofthejedi::GLWindow(width, height) {}
};