forked from KhronosGroup/Vulkan-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
102 lines (86 loc) · 2.71 KB
/
main.cpp
File metadata and controls
102 lines (86 loc) · 2.71 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
#include "engine.h"
#include "transform_component.h"
#include "camera_component.h"
#include "scene_loading.h"
#include <iostream>
#include <stdexcept>
#include <thread>
// Constants
constexpr int WINDOW_WIDTH = 800;
constexpr int WINDOW_HEIGHT = 600;
#if defined(NDEBUG)
constexpr bool ENABLE_VALIDATION_LAYERS = false;
#else
constexpr bool ENABLE_VALIDATION_LAYERS = true;
#endif
/**
* @brief Set up a simple scene with a camera and some objects.
* @param engine The engine to set up the scene in.
*/
void SetupScene(Engine* engine) {
// Create a camera entity
Entity* cameraEntity = engine->CreateEntity("Camera");
if (!cameraEntity) {
throw std::runtime_error("Failed to create camera entity");
}
// Add a transform component to the camera
auto* cameraTransform = cameraEntity->AddComponent<TransformComponent>();
cameraTransform->SetPosition(glm::vec3(0.0f, 0.0f, 3.0f));
// Add a camera component to the camera entity
auto* camera = cameraEntity->AddComponent<CameraComponent>();
camera->SetAspectRatio(static_cast<float>(WINDOW_WIDTH) / static_cast<float>(WINDOW_HEIGHT));
// Set the camera as the active camera
engine->SetActiveCamera(camera);
// Kick off GLTF model loading on a background thread so the main loop can start and render the UI/progress bar
if (auto* renderer = engine->GetRenderer()) {
renderer->SetLoading(true);
}
std::thread([engine]{
LoadGLTFModel(engine, "../Assets/bistro/bistro.gltf");
}).detach();
}
#if defined(PLATFORM_ANDROID)
/**
* @brief Android entry point.
* @param app The Android app.
*/
void android_main(android_app* app) {
try {
// Create the engine
Engine engine;
// Initialize the engine
if (!engine.InitializeAndroid(app, "Simple Engine", ENABLE_VALIDATION_LAYERS)) {
throw std::runtime_error("Failed to initialize engine");
}
// Set up the scene
SetupScene(&engine);
// Run the engine
engine.RunAndroid();
} catch (const std::exception& e) {
LOGE("Exception: %s", e.what());
}
}
#else
/**
* @brief Desktop entry point.
* @return The exit code.
*/
int main(int, char*[]) {
try {
// Create the engine
Engine engine;
// Initialize the engine
if (!engine.Initialize("Simple Engine", WINDOW_WIDTH, WINDOW_HEIGHT, ENABLE_VALIDATION_LAYERS)) {
throw std::runtime_error("Failed to initialize engine");
}
// Set up the scene
SetupScene(&engine);
// Run the engine
engine.Run();
return 0;
} catch (const std::exception& e) {
std::cerr << "Exception: " << e.what() << std::endl;
return 1;
}
}
#endif