-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
129 lines (98 loc) · 3.19 KB
/
Main.cpp
File metadata and controls
129 lines (98 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "precomp.h"
#include <chrono>
#include "Graphics.h"
#include "game.h"
#include "InputManager.h"
#ifdef PLATFORM_WINDOWS
#include "GraphicsWindows.h"
#include "imgui_impl_glfw.h"
#elif PLATFORM_LINUX
#include "GraphicsLinux.h"
#include <filesystem>
#endif
#include "Settings.h"
#include "Scope.h"
#include "Texture.h"
int main()
{
Framework::InputManager& inputManager = Framework::InputManager::Inst();
#ifdef PLATFORM_WINDOWS
LOGMESSAGE("Platform is windows");
std::unique_ptr<Graphics> graphics = std::make_unique<GraphicsWindows>();
#elif PLATFORM_LINUX
LOGMESSAGE("Platform is linux");
std::unique_ptr<Graphics> graphics = std::make_unique<GraphicsLinux>();
#else
static_assert(false && "Platform is undefined!");
#endif // PLATFORM_WINDOWS
graphics->Init(sScreenWidth, sScreenHeight);
inputManager.Init(graphics.get());
#ifdef PLATFORM_LINUX
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO();
io.DisplaySize = { sScreenWidth, sScreenHeight };
ImGui_ImplOpenGL3_Init("#version 300 es");
#elif PLATFORM_WINDOWS
// Initialize imgui
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO io = ImGui::GetIO(); (void)io;
ImGui_ImplGlfw_InitForOpenGL(static_cast<GraphicsWindows*>(graphics.get())->mWindow, true);
ImGui_ImplOpenGL3_Init("#version 130");
#endif // PLATFORM_LINUX
CheckGL();
float deltaTime;
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
std::chrono::high_resolution_clock::time_point t2{};
glClearColor(.5f, .5f, 1.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glDisable(GL_BLEND);
{
Framework::Settings& settings = Framework::Settings::Inst();
Framework::Data::Scope settingsScope = settings.GetSettings();
int currentMaxSize;
Framework::Data::Variable& textureSizeVar = settingsScope.GetVariable("maxTextureSize");
textureSizeVar >> currentMaxSize;
int deviceTextureSizeLimit = Framework::Texture::GetMaxTextureSizeForDevice();
currentMaxSize = std::min(deviceTextureSizeLimit, currentMaxSize);
textureSizeVar << currentMaxSize;
settings.SetSettings(settingsScope);
ImGui::GetIO().Fonts->TexDesiredWidth = deviceTextureSizeLimit;
}
Framework::Game* game = new Framework::Game;
game->Init();
bool gameRunning = true;
while (gameRunning)
{
game->EarlyTick();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
inputManager.NewFrame();
graphics->NewFrame();
t2 = std::chrono::high_resolution_clock::now();
deltaTime = (std::chrono::duration_cast<std::chrono::duration<float>>(t2 - t1)).count();
t1 = t2;
gameRunning = game->Tick(deltaTime);
graphics->Render();
}
game->Shutdown();
delete game;
graphics->Exit();
}
// OpenGL helper functions
void _CheckGL( const char* f, int l )
{
GLenum error = glGetError();
if (error != GL_NO_ERROR)
{
const char* errStr = "UNKNOWN ERROR";
if (error == 0x500) errStr = "INVALID ENUM";
else if (error == 0x502) errStr = "INVALID OPERATION";
else if (error == 0x501) errStr = "INVALID VALUE";
else if (error == 0x506) errStr = "INVALID FRAMEBUFFER OPERATION";
std::cerr << "GL error " << error << "; " << errStr << "\n" << f << "\n" << l << std::endl;
assert(false);
}
}