2016-09-27 16:23:58 +00:00
|
|
|
#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"
|
2016-09-27 16:23:58 +00:00
|
|
|
|
|
|
|
#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"
|
2016-09-27 16:23:58 +00:00
|
|
|
|
|
|
|
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;
|
2016-09-28 11:16:11 +00:00
|
|
|
//endofthejedi::RendererPolygon2d m_renderer;
|
|
|
|
endofthejedi::RendererPolygon3d m_renderer;
|
2016-09-28 11:00:40 +00:00
|
|
|
//endofthejedi::RendererRayTracer m_renderer;
|
2016-09-28 01:33:01 +00:00
|
|
|
|
2016-09-27 18:56:17 +00:00
|
|
|
protected:
|
2016-09-27 16:23:58 +00:00
|
|
|
void init() override {
|
2016-09-28 11:00:40 +00:00
|
|
|
std::cout<<"init" << std::endl;
|
|
|
|
|
2016-09-27 16:23:58 +00:00
|
|
|
glClearColor(0.5f, 0.6f, 0.7f, 1.0f);
|
|
|
|
resize();
|
|
|
|
|
|
|
|
glEnable(GL_DEPTH_TEST);
|
2016-09-28 11:00:40 +00:00
|
|
|
|
|
|
|
m_renderer.setup();
|
2016-09-27 16:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2016-09-27 16:23:58 +00:00
|
|
|
stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
2016-09-27 19:16:55 +00:00
|
|
|
|
2016-09-28 05:28:18 +00:00
|
|
|
m_renderer.render(m_game->state());
|
2016-09-27 16:23:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2016-09-27 16:23:58 +00:00
|
|
|
};
|