49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include "opengl.hpp"
|
|
#include "renderer.hpp"
|
|
#include "renderer_simple.hpp"
|
|
#include "renderer_shader.hpp"
|
|
|
|
#include "game.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;
|
|
}
|
|
};
|