[d02c25f] | 1 | #include "opengl-game.hpp"
|
---|
| 2 |
|
---|
| 3 | #include <iostream>
|
---|
| 4 |
|
---|
[5edbd58] | 5 | #include "consts.hpp"
|
---|
| 6 |
|
---|
[d8cb15e] | 7 | #include "game-gui-glfw.hpp"
|
---|
| 8 |
|
---|
[d02c25f] | 9 | using namespace std;
|
---|
| 10 |
|
---|
| 11 | OpenGLGame::OpenGLGame() {
|
---|
[d8cb15e] | 12 | gui = nullptr;
|
---|
| 13 | window = nullptr;
|
---|
[d02c25f] | 14 | }
|
---|
| 15 |
|
---|
| 16 | OpenGLGame::~OpenGLGame() {
|
---|
| 17 | }
|
---|
| 18 |
|
---|
[b6e60b4] | 19 | void OpenGLGame::run(int width, int height, unsigned char guiFlags) {
|
---|
[5edbd58] | 20 | if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
|
---|
[d8cb15e] | 21 | return;
|
---|
| 22 | }
|
---|
[b6e60b4] | 23 |
|
---|
[d8cb15e] | 24 | initOpenGL();
|
---|
| 25 | mainLoop();
|
---|
| 26 | cleanup();
|
---|
| 27 | }
|
---|
| 28 |
|
---|
[b6e60b4] | 29 | bool OpenGLGame::initWindow(int width, int height, unsigned char guiFlags) {
|
---|
[d8cb15e] | 30 | gui = new GameGui_GLFW();
|
---|
| 31 |
|
---|
[b6e60b4] | 32 | if (gui->init() == RTWO_ERROR) {
|
---|
[d8cb15e] | 33 | cout << "UI library could not be initialized!" << endl;
|
---|
[b6e60b4] | 34 | cout << gui->getError() << endl;
|
---|
[d8cb15e] | 35 | return RTWO_ERROR;
|
---|
| 36 | }
|
---|
| 37 | cout << "GUI init succeeded" << endl;
|
---|
| 38 |
|
---|
[b6e60b4] | 39 | window = (GLFWwindow*) gui->createWindow("OpenGL Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
|
---|
[d8cb15e] | 40 | if (window == nullptr) {
|
---|
| 41 | cout << "Window could not be created!" << endl;
|
---|
[ed7c953] | 42 | cout << gui->getError() << endl;
|
---|
[d8cb15e] | 43 | return RTWO_ERROR;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[b6e60b4] | 46 | int actualWidth=0, actualHeight=0;
|
---|
| 47 | gui->getWindowSize(&actualWidth, &actualHeight);
|
---|
| 48 |
|
---|
| 49 | cout << "Target window size: (" << width << ", " << height << ")" << endl;
|
---|
| 50 | cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
|
---|
| 51 |
|
---|
[d8cb15e] | 52 | return RTWO_SUCCESS;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | void OpenGLGame::initOpenGL() {
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | void OpenGLGame::mainLoop() {
|
---|
[7bf5433] | 59 | //MouseEvent e;
|
---|
| 60 |
|
---|
[d8cb15e] | 61 | while (!glfwWindowShouldClose(window)) {
|
---|
[7bf5433] | 62 | /*
|
---|
| 63 | gui->processEvents();
|
---|
| 64 |
|
---|
| 65 | if (gui->getKeyEvent(GLFW_KEY_ESCAPE) == RTWO_KEY_EVENT_PRESSED) {
|
---|
| 66 | glfwSetWindowShouldClose(window, 1);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | while (gui->pollMouseEvent(&e)) {
|
---|
| 70 | cout << "Mouse click detected at (" << e.x << ", " << e.y << ")" << endl;
|
---|
| 71 | }
|
---|
| 72 | */
|
---|
| 73 |
|
---|
[d8cb15e] | 74 | glfwPollEvents();
|
---|
| 75 |
|
---|
[1ce9afe] | 76 | if (GameGui_GLFW::s_keyState[GLFW_KEY_ESCAPE] == GLFW_PRESS) {
|
---|
| 77 | glfwSetWindowShouldClose(window, 1);
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[d8cb15e] | 80 | glfwSwapBuffers(window);
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 |
|
---|
| 84 | void OpenGLGame::cleanup() {
|
---|
[b6e60b4] | 85 | gui->destroyWindow();
|
---|
| 86 | gui->shutdown();
|
---|
[d8cb15e] | 87 | delete gui;
|
---|
[d02c25f] | 88 | } |
---|