Window with own structure

This commit is contained in:
2026-02-20 02:05:56 +00:00
parent eb79d538de
commit 294edcdcff
10 changed files with 93 additions and 42 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
README

View File

@@ -1,13 +1,13 @@
CFLAGS = -std=c++17 -O2
LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
VulkanTest: main.cpp
g++ $(CFLAGS) -o VulkanTest main.cpp $(LDFLAGS)
VulkanTest: *.cpp *.hpp
g++ $(CFLAGS) -o a.out *.cpp $(LDFLAGS)
.PHONY: test clean
test: VulkanTest
./VulkanTest
test: a.out
./a.out
clean:
rm -f VulkanTest
rm -f a.out

Binary file not shown.

BIN
a.out Executable file

Binary file not shown.

22
cve_window.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include "cve_window.hpp"
namespace cve {
CveWindow::CveWindow(int w, int h, std::string name) : width{w},
height{h}, windowName{name} {
initWindow();
}
CveWindow::~CveWindow() {
glfwDestroyWindow(window);
glfwTerminate();
}
void CveWindow::initWindow() {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
window = glfwCreateWindow(width, height,
windowName.c_str(), nullptr, nullptr);
}
}

28
cve_window.hpp Normal file
View File

@@ -0,0 +1,28 @@
#pragma once
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <string>
namespace cve {
class CveWindow {
public:
CveWindow(int w, int h, std::string name);
~CveWindow();
CveWindow(const CveWindow &) = delete;
CveWindow &operator=(const CveWindow &) = delete;
bool shouldClose() { return glfwWindowShouldClose(window); };
private:
void initWindow();
const int width;
const int height;
std::string windowName;
GLFWwindow *window;
};
}

9
first_app.cpp Normal file
View File

@@ -0,0 +1,9 @@
#include "first_app.hpp"
namespace cve {
void FirstApp::run() {
while (!cveWindow.shouldClose()) {
glfwPollEvents();
}
}
}

15
first_app.hpp Normal file
View File

@@ -0,0 +1,15 @@
#pragma once
#include "cve_window.hpp"
namespace cve {
class FirstApp {
public:
static constexpr int WIDTH = 800;
static constexpr int HEIGHT = 600;
void run();
private:
CveWindow cveWindow{WIDTH, HEIGHT, "Hello Vulkan!"};
};
}

View File

@@ -1,8 +0,0 @@
#include <stdio.h>
using namespace std;
int main() {
printf("Hello, World!\n");
return 0;
}

View File

@@ -1,35 +1,19 @@
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include "first_app.hpp"
// std
#include <cstdlib>
#include <iostream>
#include <stdexcept>
int main() {
glfwInit();
cve::FirstApp app{};
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
GLFWwindow* window = glfwCreateWindow(800, 600, "Vulkan window", nullptr, nullptr);
try {
app.run();
} catch (const std::exception &e) {
std::cerr << e.what() << '\n';
return EXIT_FAILURE;
}
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << extensionCount << " extensions supported\n";
glm::mat4 matrix;
glm::vec4 vec;
auto test = matrix * vec;
while(!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
glfwDestroyWindow(window);
glfwTerminate();
return 0;
return EXIT_SUCCESS;
}