source: opengl-game/opengl-game.cpp@ 1ce9afe

feature/imgui-sdl points-test
Last change on this file since 1ce9afe was 1ce9afe, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Add a fullscreen flag to GameGui::CreateWindow and implement fullscreen functionality and the ability to detect key presses in openglgame

  • Property mode set to 100644
File size: 1.4 KB
Line 
1#include "opengl-game.hpp"
2
3#include <iostream>
4
5#include "consts.hpp"
6
7#include "game-gui-glfw.hpp"
8
9using namespace std;
10
11OpenGLGame::OpenGLGame() {
12 gui = nullptr;
13 window = nullptr;
14}
15
16OpenGLGame::~OpenGLGame() {
17}
18
19void OpenGLGame::run(unsigned int width, unsigned int height, unsigned char guiFlags) {
20 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
21 return;
22 }
23 initOpenGL();
24 mainLoop();
25 cleanup();
26}
27
28bool OpenGLGame::initWindow(unsigned int width, unsigned int height, unsigned char guiFlags) {
29 gui = new GameGui_GLFW();
30
31 if (gui->Init() == RTWO_ERROR) {
32 cout << "UI library could not be initialized!" << endl;
33 cout << gui->GetError() << endl;
34 return RTWO_ERROR;
35 }
36 cout << "GUI init succeeded" << endl;
37
38 window = (GLFWwindow*) gui->CreateWindow("OpenGL Game", width, height, guiFlags | GUI_FLAGS_WINDOW_FULLSCREEN);
39 if (window == nullptr) {
40 cout << "Window could not be created!" << endl;
41 return RTWO_ERROR;
42 }
43
44 return RTWO_SUCCESS;
45}
46
47void OpenGLGame::initOpenGL() {
48}
49
50void OpenGLGame::mainLoop() {
51 while (!glfwWindowShouldClose(window)) {
52 glfwPollEvents();
53
54 if (GameGui_GLFW::s_keyState[GLFW_KEY_ESCAPE] == GLFW_PRESS) {
55 glfwSetWindowShouldClose(window, 1);
56 }
57
58 glfwSwapBuffers(window);
59 }
60}
61
62void OpenGLGame::cleanup() {
63 gui->DestroyWindow();
64 gui->Shutdown();
65 delete gui;
66}
Note: See TracBrowser for help on using the repository browser.