Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • vulkan2021/vkcv-framework
1 result
Show changes
Commits on Source (8)
.project
.cproject
.vs/
.vscode/
.idea/
.editorconfig
......
......@@ -2,4 +2,8 @@
set(vkcv_sources
${vkcv_source}/vkcv/Context.hpp
${vkcv_source}/vkcv/Context.cpp
${vkcv_source}/vkcv/Window.hpp
${vkcv_source}/vkcv/Window.cpp
${vkcv_source}/vkcv/CoreManager.hpp
${vkcv_source}/vkcv/CoreManager.cpp
)
#include <iostream>
#include <vkcv/Context.hpp>
#include <vkcv/Window.hpp>
int main(int argc, const char** argv) {
const char* applicationName = "First Triangle";
vkcv::Window window = vkcv::Window::create(
applicationName,
800,
600,
false
);
vkcv::Context context = vkcv::Context::create(
"First Triangle",
applicationName,
VK_MAKE_VERSION(0, 0, 1)
);
......@@ -23,5 +31,8 @@ int main(int argc, const char** argv) {
default: std::cout << "Unknown GPU vendor?! Either you're on an exotic system or your driver is broken..." << std::endl;
}
while (window.isWindowOpen()) {
window.pollEvents();
}
return 0;
}
#define GLFW_INCLUDE_VULKAN
#include "CoreManager.hpp"
namespace vkcv {
int glfwCounter = 0;
void initGLFW() {
if (glfwCounter == 0) {
int glfwSuccess = glfwInit();
if (glfwSuccess == GLFW_FALSE) {
throw std::runtime_error("Could not initialize GLFW");
}
}
glfwCounter++;
}
void terminateGLFW() {
if (glfwCounter == 1) {
glfwTerminate();
}
glfwCounter--;
}
}
\ No newline at end of file
#ifndef VKCV_COREMANAGER_HPP
#define VKCV_COREMANAGER_HPP
#include <GLFW/glfw3.h>
#include <stdexcept>
namespace vkcv {
/**
* initialize GLFW if not initialized
*/
void initGLFW();
/**
* terminate GLFW
*/
void terminateGLFW();
}
#endif //VKCV_COREMANAGER_HPP
#include "Window.hpp"
#include "CoreManager.hpp"
namespace vkcv {
Window::Window(GLFWwindow *window)
: m_window(window) {
}
Window::~Window() {
glfwDestroyWindow(m_window);
vkcv::terminateGLFW();
}
Window Window::create(const char *windowTitle, int width, int height, bool resizable) {
vkcv::initGLFW();
width = std::max(width, 1);
height = std::max(height, 1);
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, resizable ? GLFW_TRUE : GLFW_FALSE);
GLFWwindow *window;
window = glfwCreateWindow(width, height, windowTitle, nullptr, nullptr);
return Window(window);
}
bool Window::isWindowOpen() const {
return !glfwWindowShouldClose(m_window);
}
void Window::pollEvents() {
glfwPollEvents();
}
GLFWwindow *Window::getWindow() const {
return m_window;
}
int Window::getWidth() const {
int width;
glfwGetWindowSize(m_window, &width, nullptr);
return width;
}
int Window::getHeight() const {
int height;
glfwGetWindowSize(m_window, nullptr, &height);
return height;
}
}
\ No newline at end of file
#pragma once
#include <vulkan/vulkan.hpp>
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
namespace vkcv {
class Window final {
private:
explicit Window(GLFWwindow *window);
GLFWwindow *m_window;
public:
static Window create(const char *windowTitle, int width = -1, int height = -1, bool resizable = false);
[[nodiscard]]
bool isWindowOpen() const;
static void pollEvents();
[[nodiscard]]
GLFWwindow *getWindow() const;
[[nodiscard]]
int getWidth() const;
[[nodiscard]]
int getHeight() const;
Window &operator=(const Window &other) = delete;
Window &operator=(Window &&other) = default;
virtual ~Window();
};
}
\ No newline at end of file