source: opengl-game/opengl-game.cpp@ 5edbd58

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

For both openglgame and vulkangame, pass in the window width and height and a fullscreen flag to the run() function

  • Property mode set to 100644
File size: 1.2 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);
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 glfwSwapBuffers(window);
55 }
56}
57
58void OpenGLGame::cleanup() {
59 gui->DestroyWindow();
60 gui->Shutdown();
61 delete gui;
62}
Note: See TracBrowser for help on using the repository browser.