KlassischeKeplerKriege/game/game_window.hpp

74 lines
1.9 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();
2016-10-05 21:26:55 +00:00
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_DEPTH_TEST);
2016-10-05 21:26:55 +00:00
glEnable( GL_BLEND );
glEnable(GL_ALPHA_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
{
std::cout<<"resize()" << std::endl;
glViewport(0, 0, getwidth(), getheight());
// resize the game
m_game->resize(getwidth(), getheight());
// TODO: mark it and let the reinit() happen in the next so it happnens just once. while doing the resize
m_game->state()->init();
// resize the renderer
m_renderer.setWindowSize(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;
}
};