source: opengl-game/opengl-game.cpp@ b6e60b4

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

In vulkangame and openglgame:

  • use int instead of usigned int for width and heights paremters
  • Fix a bug where GUI_FLAGS_WINDOW_FULLSCREEN was being incorrectly checked
  • Print the size of a window after it has been created
  • Property mode set to 100644
File size: 1.6 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(int width, int height, unsigned char guiFlags) {
20 if (initWindow(width, height, guiFlags) == RTWO_ERROR) {
21 return;
22 }
23
24 initOpenGL();
25 mainLoop();
26 cleanup();
27}
28
29bool OpenGLGame::initWindow(int width, int height, unsigned char guiFlags) {
30 gui = new GameGui_GLFW();
31
32 if (gui->init() == RTWO_ERROR) {
33 cout << "UI library could not be initialized!" << endl;
34 cout << gui->getError() << endl;
35 return RTWO_ERROR;
36 }
37 cout << "GUI init succeeded" << endl;
38
39 window = (GLFWwindow*) gui->createWindow("OpenGL Game", width, height, guiFlags & GUI_FLAGS_WINDOW_FULLSCREEN);
40 if (window == nullptr) {
41 cout << "Window could not be created!" << endl;
42 return RTWO_ERROR;
43 }
44
45 int actualWidth=0, actualHeight=0;
46 gui->getWindowSize(&actualWidth, &actualHeight);
47
48 cout << "Target window size: (" << width << ", " << height << ")" << endl;
49 cout << "Actual window size: (" << actualWidth << ", " << actualHeight << ")" << endl;
50
51 return RTWO_SUCCESS;
52}
53
54void OpenGLGame::initOpenGL() {
55}
56
57void OpenGLGame::mainLoop() {
58 while (!glfwWindowShouldClose(window)) {
59 glfwPollEvents();
60
61 if (GameGui_GLFW::s_keyState[GLFW_KEY_ESCAPE] == GLFW_PRESS) {
62 glfwSetWindowShouldClose(window, 1);
63 }
64
65 glfwSwapBuffers(window);
66 }
67}
68
69void OpenGLGame::cleanup() {
70 gui->destroyWindow();
71 gui->shutdown();
72 delete gui;
73}
Note: See TracBrowser for help on using the repository browser.