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@…>, 6 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
RevLine 
[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]9using namespace std;
10
11OpenGLGame::OpenGLGame() {
[d8cb15e]12 gui = nullptr;
13 window = nullptr;
[d02c25f]14}
15
16OpenGLGame::~OpenGLGame() {
17}
18
[5edbd58]19void 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]28bool 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
[5edbd58]38 window = (GLFWwindow*) gui->CreateWindow("OpenGL Game", width, height);
[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
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;
[d02c25f]62}
Note: See TracBrowser for help on using the repository browser.