-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
128 lines (102 loc) · 3.53 KB
/
main.cpp
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
import MyClass;
#include <GLFW/glfw3.h>
#include <entt/entt.hpp>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <spdlog/spdlog.h>
#include <vulkan/vulkan.h>
#include "control/app.h"
import std;
struct Position {
float x;
float y;
};
struct Velocity {
float dx;
float dy;
};
int main() {
std::print("Hello, World!\n");
#ifdef NDEBUG
printf("Release configuration!\n");
#else
printf("Debug configuration!\n");
#endif
MyClass myClass;
myClass.sayHello();
// spdlog example
spdlog::info("This is an info message from spdlog.");
spdlog::warn("This is a warning message from spdlog.");
spdlog::error("This is an error message from spdlog.");
spdlog::debug("This is a debug message from spdlog.");
spdlog::critical("This is a critical message from spdlog.");
// glm example
// Create two vectors
glm::vec3 vec1(1.0f, 2.0f, 3.0f);
glm::vec3 vec2(4.0f, 5.0f, 6.0f);
// Vector addition
glm::vec3 vecSum = vec1 + vec2;
std::print("Vector Sum: ({}, {}, {})\n", vecSum.x, vecSum.y, vecSum.z);
// Vector dot product
float dotProduct = glm::dot(vec1, vec2);
std::print("Dot Product: {}\n", dotProduct);
// Vector cross product
glm::vec3 crossProduct = glm::cross(vec1, vec2);
std::print("Cross Product: ({}, {}, {})\n", crossProduct.x, crossProduct.y,
crossProduct.z);
// Matrix transformation
glm::mat4 transform = glm::mat4(1.0f);
transform = glm::translate(transform, glm::vec3(1.0f, 1.0f, 1.0f));
glm::vec4 transformedVec = transform * glm::vec4(vec1, 1.0f);
std::print("Transformed Vector: ({}, {}, {})\n", transformedVec.x,
transformedVec.y, transformedVec.z);
// entt example
entt::registry registry;
auto entity = registry.create();
registry.emplace<Position>(entity, 0.0f, 0.0f);
registry.emplace<Velocity>(entity, 1.0f, 1.0f);
auto &pos = registry.get<Position>(entity);
auto &vel = registry.get<Velocity>(entity);
pos.x += vel.dx;
pos.y += vel.dy;
std::print("Updated Position: ({}, {})\n", pos.x, pos.y);
// Initialize Vulkan
VkInstance instance;
VkApplicationInfo appInfo{};
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Vulkan Example";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "No Engine";
appInfo.engineVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.apiVersion = VK_API_VERSION_1_0;
VkInstanceCreateInfo createInfo{};
createInfo.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
createInfo.pApplicationInfo = &appInfo;
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
std::cerr << "Failed to create Vulkan instance!" << std::endl;
return -1;
}
// Enumerate physical devices (GPUs)
uint32_t deviceCount = 0;
vkEnumeratePhysicalDevices(instance, &deviceCount, nullptr);
if (deviceCount == 0) {
std::cerr << "Failed to find GPUs with Vulkan support!" << std::endl;
return -1;
}
std::vector<VkPhysicalDevice> devices(deviceCount);
vkEnumeratePhysicalDevices(instance, &deviceCount, devices.data());
std::cout << "Found " << deviceCount
<< " GPU(s) with Vulkan support:" << std::endl;
for (const auto &device : devices) {
VkPhysicalDeviceProperties deviceProperties;
vkGetPhysicalDeviceProperties(device, &deviceProperties);
std::cout << "\t" << deviceProperties.deviceName << std::endl;
}
// Clean up Vulkan instance
vkDestroyInstance(instance, nullptr);
App *myApp = new App(640, 480, true);
myApp->run();
delete myApp;
return 0;
}