KlassischeKeplerKriege/game/game_window.hpp

56 lines
1.4 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 09:50:35 +00:00
#include "renderer_polygon_2d/renderer_polygon_2d.hpp"
#include "renderer_polygon_3d/renderer_polygon_3d.hpp"
#include "renderer_ray_tracer/renderer_ray_tracer.hpp"
#include "game.hpp"
2016-09-28 05:57:10 +00:00
#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 {
2016-09-27 18:56:17 +00:00
private:
2016-09-28 05:28:18 +00:00
Game* m_game;
//endofthejedi::RendererPolygon2d m_renderer;
endofthejedi::RendererPolygon3d m_renderer;
//endofthejedi::RendererRayTracer 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);
m_renderer.setup();
}
void render(double time) override {
2016-09-28 05:28:18 +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 05:28:18 +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:
2016-09-28 05:28:18 +00:00
GameWindow(unsigned int width, unsigned int height, Game *ptr)
: endofthejedi::GLWindow(width, height) {
m_game = ptr;
}
};