21
21
22
22
#include " core/auxiliary/trace.hpp"
23
23
24
+ #include " core/geometry/CSimpleGeometry.hpp"
25
+
24
26
#include < glm/glm.hpp>
25
27
#include < glm/gtc/matrix_transform.hpp>
26
28
@@ -91,23 +93,18 @@ void setupOpenGlDebug()
91
93
92
94
93
95
CEngine::CEngine ()
94
- : mMainWindow (nullptr )
95
- , mChronometer (nullptr )
96
+ : mResourceLoader (nullptr )
97
+ , mMainWindow (nullptr )
96
98
, mInputManager(nullptr )
99
+ , m2dRenderSystem(nullptr )
100
+ , m3dRenderSystem(nullptr )
97
101
, mIsRunning(false )
98
102
, mIsDebugMode(false )
99
- , m2dRenderSystem()
100
- , m3dRenderSystem()
101
- , mCamera()
102
103
{
103
104
}
104
105
105
106
CEngine::~CEngine ()
106
107
{
107
- delete m2dRenderSystem;
108
- delete m3dRenderSystem;
109
- delete mChronometer ;
110
- delete mMainWindow ;
111
108
}
112
109
113
110
void CEngine::initialize ()
@@ -121,7 +118,7 @@ void CEngine::initialize()
121
118
mSettings .mDepthMask = false ;
122
119
mSettings .mDepthTest = true ;
123
120
mSettings .mPolygonOffsetFill = false ;
124
-
121
+
125
122
mSettings .mPolygonMode .mIndex = 2 ;
126
123
mSettings .mPolygonMode .mItems = {GL_POINT, GL_LINE, GL_FILL};
127
124
mSettings .mPolygonMode .mItemsNames = {" GL_POINT" , " GL_LINE" , " GL_FILL" };
@@ -133,49 +130,45 @@ void CEngine::initialize()
133
130
void CEngine::initializeVideo ()
134
131
{
135
132
trc_debug (" - video" );
136
- mMainWindow = new CMainWindow (
137
- " F.O.S.S. (0.1.2)" ,
138
- {1366 , 768 },
139
- SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN
140
- );
141
-
142
- CMainWindow::setGlAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
143
- CMainWindow::setGlAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 3 );
144
-
145
- CMainWindow::setGlAttribute (
146
- SDL_GL_CONTEXT_PROFILE_MASK,
147
- SDL_GL_CONTEXT_PROFILE_CORE
148
- );
149
133
150
- CMainWindow::setGlAttribute (SDL_GL_DOUBLEBUFFER, 1 );
151
- CMainWindow::setGlAttribute (SDL_GL_DOUBLEBUFFER, 1 );
152
- CMainWindow::setGlAttribute (SDL_GL_STENCIL_SIZE, 8 );
153
- CMainWindow::setGlAttribute (SDL_GL_DEPTH_SIZE, 24 );
154
-
155
- CMainWindow::setGlAttribute (SDL_GL_MULTISAMPLEBUFFERS, 1 );
156
- CMainWindow::setGlAttribute (SDL_GL_MULTISAMPLESAMPLES, 4 );
157
-
158
- mMainWindow ->createGlContext ();
134
+ mMainWindow .reset (new CMainWindow);
135
+
136
+ mMainWindow ->setSize ({1920 , 1080 });
137
+ mMainWindow ->setTitle (" F.O.S.S (0.3.5)" );
138
+ mMainWindow ->setFlags (SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
139
+
140
+ std::map<SDL_GLattr, int > attributes = {
141
+ {SDL_GL_CONTEXT_MAJOR_VERSION, 3 },
142
+ {SDL_GL_CONTEXT_MINOR_VERSION, 3 },
143
+ {SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE},
144
+ {SDL_GL_DOUBLEBUFFER, 1 },
145
+ {SDL_GL_DOUBLEBUFFER, 1 },
146
+ {SDL_GL_STENCIL_SIZE, 8 },
147
+ {SDL_GL_DEPTH_SIZE, 24 },
148
+ {SDL_GL_MULTISAMPLEBUFFERS, 1 },
149
+ {SDL_GL_MULTISAMPLESAMPLES, 4 }
150
+ };
151
+
152
+ mMainWindow ->setAttributes (attributes);
153
+ mMainWindow ->create ();
159
154
}
160
155
161
156
void CEngine::initializeInput ()
162
157
{
163
158
trc_debug (" - input" );
164
- mInputManager = new CInputEventManager;
159
+ mInputManager . reset ( new CInputEventManager) ;
165
160
166
161
mInputManager ->addListener (new CEngineListener (*this ));
167
162
mInputManager ->addListener (new CCameraListener (&mCamera ));
168
163
}
169
164
170
165
void CEngine::run ()
171
166
{
172
- auto * vao = new CArrayObject ();
173
- vao->bind ();
167
+ initialize ();
174
168
prepare ();
175
169
loop ();
176
170
finalize ();
177
- vao->unbind ();
178
- delete vao;
171
+
179
172
}
180
173
181
174
void CEngine::stop ()
@@ -186,42 +179,41 @@ void CEngine::stop()
186
179
void CEngine::prepare ()
187
180
{
188
181
trc_debug (" prepare: " );
189
- auto skyboxTexture = mResourceLoader ->getCubeMap (" resources/skybox/purple-nebula" , 4096 );
182
+ auto skyboxTexture = mResourceLoader ->getCubeMap (" resources/skybox/purple-nebula" , 1024 );
190
183
191
184
CRegistry::set (" camera" , &mCamera );
192
-
193
- CRegistry::set (" texture/purple-nebula/4096" , skyboxTexture);
194
- CRegistry::set (" texture/skybox" , skyboxTexture);
185
+ CRegistry::set (" texture/skybox" , skyboxTexture);
195
186
196
187
ImGui_ImplSdlGL3_Init (SDL_GetWindowFromID (mMainWindow ->getId ()));
197
188
198
189
ImGuiStyle& style = ImGui::GetStyle ();
199
190
style.WindowRounding = 0 ;
200
191
style.Colors [ImGuiCol_WindowBg] = ImVec4 (0 .00f , 0 .00f , 0 .00f , 0 .30f );
201
192
202
- m2dRenderSystem = new C2DRenderSystem ( );
203
- m3dRenderSystem = new C3DRenderSystem ( );
193
+ m2dRenderSystem. reset ( new C2DRenderSystem);
194
+ m3dRenderSystem. reset ( new C3DRenderSystem);
204
195
205
196
mWorld .addSystem (*m2dRenderSystem);
206
197
mWorld .addSystem (*m3dRenderSystem);
207
198
208
199
CStaticModelLoader modelLoader (*mResourceLoader );
209
200
auto rockModel = modelLoader.load (" resources/models/rock/rock.obj" );
201
+ auto cubeModel = modelLoader.load (" resources/models/cube/cube.obj" );;
202
+ auto sphereModel = modelLoader.load (" resources/models/sphere/sphere.obj" );;
210
203
211
204
anax::Entity sbx = mWorld .createEntity ();
212
205
auto &mc1 = sbx.addComponent <CMeshComponent>();
213
206
auto &tc1 = sbx.addComponent <CTransform3DComponent>();
214
207
mc1.mCategory = CMeshComponent::ECategory::eEnvironment;
215
- mc1.mModel = modelLoader.load (" resources/models/cube/cube.obj" );
216
-
208
+ mc1.mModel = cubeModel;
217
209
sbx.activate ();
218
210
219
211
anax::Entity rock = mWorld .createEntity ();
220
212
auto &mc2 = rock.addComponent <CMeshComponent>();
221
213
auto &tc2 = rock.addComponent <CTransform3DComponent>();
222
214
223
215
tc2.mScale = glm::vec3 (0 .1f );
224
- tc2.mPosition = glm::vec3 (1 .f , 1 .f , 1 .f );
216
+ tc2.mPosition = glm::vec3 (1 .f , 1 .f , 10 .f );
225
217
tc2.mOrientation = glm::quat (glm::vec3 (0 .f , 0 .f , 0 .f ));
226
218
227
219
mc2.mCategory = CMeshComponent::ECategory::eForeground;
@@ -236,7 +228,7 @@ void CEngine::prepare()
236
228
237
229
anax::Entity settingsWindow = mWorld .createEntity ();
238
230
auto & sw = settingsWindow.addComponent <CWindowComponent>();
239
- sw.mWindow = std::make_shared<CEngineSettingsWindow>(mSettings );
231
+ sw.mWindow = std::make_shared<CEngineSettingsWindow>(mSettings , mCamera );
240
232
settingsWindow.activate ();
241
233
242
234
@@ -246,7 +238,7 @@ void CEngine::prepare()
246
238
247
239
modelMatrices = new glm::mat4[amount];
248
240
249
- srand (SDL_GetTicks ());
241
+ srand (SDL_GetTicks ());
250
242
251
243
float radius = 30.0 ;
252
244
float offset = 20 .f ;
@@ -270,7 +262,7 @@ void CEngine::prepare()
270
262
271
263
272
264
t.mPosition = glm::vec3 (x, y, z);
273
-
265
+
274
266
float scale = (rand () % 8 ) / 100 .0f + 0.005 ;
275
267
t.mScale = glm::vec3 (scale);
276
268
@@ -293,15 +285,13 @@ void CEngine::loop()
293
285
setupOpenGlDebug ();
294
286
}
295
287
296
- mChronometer = new CChronometer;
297
-
298
288
while (mIsRunning )
299
289
{
300
290
// EVENTS
301
- onEvent ();
291
+ onEvent ();
302
292
303
293
// UPDATE
304
- onUpdate (mChronometer -> getDelta ());
294
+ onUpdate (mChronometer . getDelta ());
305
295
306
296
// CLEAR
307
297
onClear ();
@@ -313,13 +303,18 @@ void CEngine::loop()
313
303
checkOpenGLErrors ();
314
304
315
305
// SWAP BUFFERS
316
- mMainWindow -> swapBuffers ();
306
+ onSwapBuffers ();
317
307
318
308
// WAIT
319
- mChronometer -> wait (16UL /* 1000 / 16 ≈ 60 FPS */ );
309
+ mChronometer . wait (16UL /* 1000 / 16 ≈ 60 FPS */ );
320
310
}
321
311
}
322
312
313
+ void CEngine::onSwapBuffers ()
314
+ {
315
+ mMainWindow ->swapBuffers ();
316
+ }
317
+
323
318
void CEngine::finalize ()
324
319
{
325
320
ImGui_ImplSdlGL3_Shutdown ();
0 commit comments