KlassischeKeplerKriege/game/game_window.hpp
2016-09-28 07:57:10 +02:00

57 lines
1.3 KiB
C++

#pragma once
#include "opengl.hpp"
#include "renderer.hpp"
#include "renderer_simple.hpp"
#include "renderer_shader.hpp"
#include "game.hpp"
#include "state/trace.hpp"
#include "state/object.hpp"
#include "state/missile.hpp"
#include "state/player.hpp"
#include "state/planet.hpp"
#include "state/ship.hpp"
#include "state/explosion.hpp"
class GameWindow : public endofthejedi::GLWindow {
private:
Game* m_game;
endofthejedi::RendererSimple m_renderer;
protected:
void init() override {
glClearColor(0.5f, 0.6f, 0.7f, 1.0f);
resize();
glEnable(GL_DEPTH_TEST);
}
void render(double time) override {
// static bool once = false;
// if (!once) {
// once = true;
// for (int i=0; i<1000; i++) {
// m_game->cycle(time);
// }
//}
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);
m_renderer.render(m_game->state());
}
void resize() override { glViewport(0, 0, getwidth(), getheight()); }
public:
GameWindow(unsigned int width, unsigned int height, Game *ptr)
: endofthejedi::GLWindow(width, height) {
m_game = ptr;
}
};