feature/imgui-sdl
points-test
Last change
on this file since 7fc5e27 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
|
Rev | Line | |
---|
[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 |
|
---|
[5edbd58] | 19 | void OpenGLGame::run(unsigned int width, unsigned int height, unsigned char guiFlags) {
|
---|
| 20 | if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
|
---|
[d8cb15e] | 21 | return;
|
---|
| 22 | }
|
---|
| 23 | initOpenGL();
|
---|
| 24 | mainLoop();
|
---|
| 25 | cleanup();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
[5edbd58] | 28 | bool OpenGLGame::initWindow(unsigned int width, unsigned int height, unsigned char guiFlags) {
|
---|
[d8cb15e] | 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 |
|
---|
[1ce9afe] | 38 | window = (GLFWwindow*) gui->CreateWindow("OpenGL Game", width, height, guiFlags | GUI_FLAGS_WINDOW_FULLSCREEN);
|
---|
[d8cb15e] | 39 | if (window == nullptr) {
|
---|
| 40 | cout << "Window could not be created!" << endl;
|
---|
| 41 | return RTWO_ERROR;
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | return RTWO_SUCCESS;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
| 47 | void OpenGLGame::initOpenGL() {
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | void OpenGLGame::mainLoop() {
|
---|
| 51 | while (!glfwWindowShouldClose(window)) {
|
---|
| 52 | glfwPollEvents();
|
---|
| 53 |
|
---|
[1ce9afe] | 54 | if (GameGui_GLFW::s_keyState[GLFW_KEY_ESCAPE] == GLFW_PRESS) {
|
---|
| 55 | glfwSetWindowShouldClose(window, 1);
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[d8cb15e] | 58 | glfwSwapBuffers(window);
|
---|
| 59 | }
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | void OpenGLGame::cleanup() {
|
---|
| 63 | gui->DestroyWindow();
|
---|
| 64 | gui->Shutdown();
|
---|
| 65 | delete gui;
|
---|
[d02c25f] | 66 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.