Window with own structure
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
README
|
||||
10
Makefile
10
Makefile
@@ -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
|
||||
|
||||
BIN
VulkanTest
BIN
VulkanTest
Binary file not shown.
22
cve_window.cpp
Normal file
22
cve_window.cpp
Normal 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
28
cve_window.hpp
Normal 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
9
first_app.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include "first_app.hpp"
|
||||
|
||||
namespace cve {
|
||||
void FirstApp::run() {
|
||||
while (!cveWindow.shouldClose()) {
|
||||
glfwPollEvents();
|
||||
}
|
||||
}
|
||||
}
|
||||
15
first_app.hpp
Normal file
15
first_app.hpp
Normal 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!"};
|
||||
};
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#include <stdio.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main() {
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
38
main.cpp
38
main.cpp
@@ -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);
|
||||
|
||||
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();
|
||||
try {
|
||||
app.run();
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
glfwDestroyWindow(window);
|
||||
|
||||
glfwTerminate();
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user