Skip to content

Commit 4410607

Browse files
committed
Loot of changes.
1 parent b8e8156 commit 4410607

38 files changed

+704
-211
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ How to build and run:
33

44
```bash
55
cd path/to/directory/foss
6-
mkdir build && cd build
6+
mkdir build && cd build
77

88
cmake ..
99

resources/shaders/m3d.vert

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#version 330 core
22

3-
layout (location = 0) in vec3 position;
3+
layout (location = 0) in vec3 vertex;
44
layout (location = 1) in vec3 normal;
55

6-
uniform mat4 model;
6+
// uniform mat4 transform;
77
uniform mat4 projection;
88
uniform mat4 view;
99

1010

1111
void main() {
12-
gl_Position = projection * view * vec4(position, 1.0);
12+
gl_Position = projection * (view * vec4(vertex, 1.0));
1313
}
14+

sources/app/CEngine.cpp

Lines changed: 50 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#include "core/auxiliary/trace.hpp"
2323

24+
#include "core/geometry/CSimpleGeometry.hpp"
25+
2426
#include <glm/glm.hpp>
2527
#include <glm/gtc/matrix_transform.hpp>
2628

@@ -91,23 +93,18 @@ void setupOpenGlDebug()
9193

9294

9395
CEngine::CEngine()
94-
: mMainWindow(nullptr)
95-
, mChronometer(nullptr)
96+
: mResourceLoader(nullptr)
97+
, mMainWindow(nullptr)
9698
, mInputManager(nullptr)
99+
, m2dRenderSystem(nullptr)
100+
, m3dRenderSystem(nullptr)
97101
, mIsRunning(false)
98102
, mIsDebugMode(false)
99-
, m2dRenderSystem()
100-
, m3dRenderSystem()
101-
, mCamera()
102103
{
103104
}
104105

105106
CEngine::~CEngine()
106107
{
107-
delete m2dRenderSystem;
108-
delete m3dRenderSystem;
109-
delete mChronometer;
110-
delete mMainWindow;
111108
}
112109

113110
void CEngine::initialize()
@@ -121,7 +118,7 @@ void CEngine::initialize()
121118
mSettings.mDepthMask = false;
122119
mSettings.mDepthTest = true;
123120
mSettings.mPolygonOffsetFill = false;
124-
121+
125122
mSettings.mPolygonMode.mIndex = 2;
126123
mSettings.mPolygonMode.mItems = {GL_POINT, GL_LINE, GL_FILL};
127124
mSettings.mPolygonMode.mItemsNames = {"GL_POINT", "GL_LINE", "GL_FILL"};
@@ -133,49 +130,45 @@ void CEngine::initialize()
133130
void CEngine::initializeVideo()
134131
{
135132
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-
);
149133

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();
159154
}
160155

161156
void CEngine::initializeInput()
162157
{
163158
trc_debug(" - input");
164-
mInputManager = new CInputEventManager;
159+
mInputManager.reset(new CInputEventManager);
165160

166161
mInputManager->addListener(new CEngineListener(*this));
167162
mInputManager->addListener(new CCameraListener(&mCamera));
168163
}
169164

170165
void CEngine::run()
171166
{
172-
auto * vao = new CArrayObject();
173-
vao->bind();
167+
initialize();
174168
prepare();
175169
loop();
176170
finalize();
177-
vao->unbind();
178-
delete vao;
171+
179172
}
180173

181174
void CEngine::stop()
@@ -186,42 +179,41 @@ void CEngine::stop()
186179
void CEngine::prepare()
187180
{
188181
trc_debug("prepare: ");
189-
auto skyboxTexture = mResourceLoader->getCubeMap("resources/skybox/purple-nebula", 4096);
182+
auto skyboxTexture = mResourceLoader->getCubeMap("resources/skybox/purple-nebula", 1024);
190183

191184
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);
195186

196187
ImGui_ImplSdlGL3_Init(SDL_GetWindowFromID(mMainWindow->getId()));
197188

198189
ImGuiStyle& style = ImGui::GetStyle();
199190
style.WindowRounding = 0;
200191
style.Colors[ImGuiCol_WindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.30f);
201192

202-
m2dRenderSystem = new C2DRenderSystem();
203-
m3dRenderSystem = new C3DRenderSystem();
193+
m2dRenderSystem.reset(new C2DRenderSystem);
194+
m3dRenderSystem.reset(new C3DRenderSystem);
204195

205196
mWorld.addSystem(*m2dRenderSystem);
206197
mWorld.addSystem(*m3dRenderSystem);
207198

208199
CStaticModelLoader modelLoader(*mResourceLoader);
209200
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");;
210203

211204
anax::Entity sbx = mWorld.createEntity();
212205
auto &mc1 = sbx.addComponent<CMeshComponent>();
213206
auto &tc1 = sbx.addComponent<CTransform3DComponent>();
214207
mc1.mCategory = CMeshComponent::ECategory::eEnvironment;
215-
mc1.mModel = modelLoader.load("resources/models/cube/cube.obj");
216-
208+
mc1.mModel = cubeModel;
217209
sbx.activate();
218210

219211
anax::Entity rock = mWorld.createEntity();
220212
auto &mc2 = rock.addComponent<CMeshComponent>();
221213
auto &tc2 = rock.addComponent<CTransform3DComponent>();
222214

223215
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);
225217
tc2.mOrientation = glm::quat(glm::vec3(0.f, 0.f, 0.f));
226218

227219
mc2.mCategory = CMeshComponent::ECategory::eForeground;
@@ -236,7 +228,7 @@ void CEngine::prepare()
236228

237229
anax::Entity settingsWindow = mWorld.createEntity();
238230
auto & sw = settingsWindow.addComponent<CWindowComponent>();
239-
sw.mWindow = std::make_shared<CEngineSettingsWindow>(mSettings);
231+
sw.mWindow = std::make_shared<CEngineSettingsWindow>(mSettings, mCamera);
240232
settingsWindow.activate();
241233

242234

@@ -246,7 +238,7 @@ void CEngine::prepare()
246238

247239
modelMatrices = new glm::mat4[amount];
248240

249-
srand(SDL_GetTicks());
241+
srand(SDL_GetTicks());
250242

251243
float radius = 30.0;
252244
float offset = 20.f;
@@ -270,7 +262,7 @@ void CEngine::prepare()
270262

271263

272264
t.mPosition = glm::vec3(x, y, z);
273-
265+
274266
float scale = (rand() % 8) / 100.0f + 0.005;
275267
t.mScale = glm::vec3(scale);
276268

@@ -293,15 +285,13 @@ void CEngine::loop()
293285
setupOpenGlDebug();
294286
}
295287

296-
mChronometer = new CChronometer;
297-
298288
while (mIsRunning)
299289
{
300290
// EVENTS
301-
onEvent();
291+
onEvent();
302292

303293
// UPDATE
304-
onUpdate(mChronometer->getDelta());
294+
onUpdate(mChronometer.getDelta());
305295

306296
// CLEAR
307297
onClear();
@@ -313,13 +303,18 @@ void CEngine::loop()
313303
checkOpenGLErrors();
314304

315305
// SWAP BUFFERS
316-
mMainWindow->swapBuffers();
306+
onSwapBuffers();
317307

318308
// WAIT
319-
mChronometer->wait(16UL /* 1000 / 16 ≈ 60 FPS */);
309+
mChronometer.wait(16UL /* 1000 / 16 ≈ 60 FPS */);
320310
}
321311
}
322312

313+
void CEngine::onSwapBuffers()
314+
{
315+
mMainWindow->swapBuffers();
316+
}
317+
323318
void CEngine::finalize()
324319
{
325320
ImGui_ImplSdlGL3_Shutdown();

sources/app/CEngine.hpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "SEngineSettings.hpp"
1313

1414
#include <anax/anax.hpp>
15+
#include <memory>
1516
#include <vector>
1617

1718
class CResourceLoader;
@@ -23,37 +24,14 @@ class CEngine
2324
CEngine();
2425
~CEngine();
2526

26-
void initialize();
27-
28-
void initializeVideo();
29-
30-
void initializeInput();
31-
3227
void run();
3328
void stop();
3429

3530
private:
36-
CMainWindow * mMainWindow;
37-
38-
CChronometer * mChronometer;
39-
40-
CInputEventManager * mInputManager;
41-
42-
CResourceLoader * mResourceLoader;
43-
44-
CCamera mCamera;
45-
46-
anax::World mWorld;
47-
48-
C2DRenderSystem * m2dRenderSystem;
49-
C3DRenderSystem * m3dRenderSystem;
50-
51-
SEngineSettings mSettings;
52-
53-
bool mIsRunning;
54-
bool mIsDebugMode;
31+
void initialize();
32+
void initializeVideo();
33+
void initializeInput();
5534

56-
private:
5735
void prepare();
5836

5937
void loop();
@@ -67,7 +45,26 @@ class CEngine
6745
void onClear();
6846

6947
void onDraw();
48+
void onSwapBuffers();
49+
50+
private:
51+
CChronometer mChronometer;
52+
53+
CCamera mCamera;
7054

55+
anax::World mWorld;
56+
57+
SEngineSettings mSettings;
58+
59+
std::unique_ptr<CMainWindow> mMainWindow;
60+
std::unique_ptr<CInputEventManager> mInputManager;
61+
std::unique_ptr<CResourceLoader> mResourceLoader;
62+
std::unique_ptr<C2DRenderSystem> m2dRenderSystem;
63+
std::unique_ptr<C3DRenderSystem> m3dRenderSystem;
64+
65+
66+
bool mIsRunning;
67+
bool mIsDebugMode;
7168
};
7269

7370
#endif //FOSS_CENGINE_HPP

sources/app/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ target_link_libraries(foss.app
1717
core_resources
1818
core_textures
1919
core_renderers
20-
core_geometry
20+
core_geometry
2121
core_input
2222
core_scene
23-
core_gears
23+
core_gears
2424
core_window
2525

2626
anax
27-
imgui
27+
imgui
2828

2929
GL
3030
SDL2

sources/app/components/CTransform3DComponent.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <anax/Component.hpp>
88

99

10-
class CTransform3DComponent
10+
class CTransform3DComponent
1111
: public anax::Component
1212
, public CTransform3D
1313
{

0 commit comments

Comments
 (0)