Доброго времени суток. Вопрос в том, каким образом можно отобразить какой либо примитив с помощью библиотек GLFW и Vulkan.
#include "Window.hpp"
using namespace Maschinarium::Graphics;
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/vec4.hpp>
#include <glm/mat4x4.hpp>
#include <iostream>
VulkanWindow::VulkanWindow(uint width, uint height)
{
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
this->__Window = glfwCreateWindow(width, height, "Vulkan window", nullptr, nullptr);
set_width(width); set_height(height);
uint32_t extensionCount = 0;
vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr);
std::cout << "EXTENSIONS: " << extensionCount << " extensions supported\n";
if (glfwVulkanSupported())
{
// Vulkan is available, at least for compute
std::cout << "Vulkan is available (supported). Initializing.\n";
__initializeVulkan();
SetVulkanSupported(true);
SetVulkanInitialized(true);
}
BlockSetters();
}
void VulkanWindow::__initializeVulkan()
{
VkApplicationInfo appInfo;
appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
appInfo.pApplicationName = "Hello World!";
appInfo.applicationVersion = VK_MAKE_VERSION(1, 0, 0);
appInfo.pEngineName = "noname";
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;
unsigned int glfwExtensionCount = 0;
const char **glfwExtensions;
glfwExtensions = glfwGetRequiredInstanceExtensions( & glfwExtensionCount );
createInfo.enabledExtensionCount = glfwExtensionCount;
createInfo.ppEnabledExtensionNames = glfwExtensions;
createInfo.enabledLayerCount = 0;
if (vkCreateInstance( & createInfo, nullptr, &__VulkanInstance) != VK_SUCCESS)
{
throw std::runtime_error( "Failed to create Vulkan Instance!" );
}
std::cout << "Vulkan instance created successfull!\n";
std::vector<VkExtensionProperties> extensions( glfwExtensionCount );
vkEnumerateInstanceExtensionProperties(nullptr, & glfwExtensionCount, extensions.data() );
std::cout << "Available extensions: \n";
for (const auto& extension : extensions )
{
std::cout << "\t" << extension.extensionName << std::endl;
}
}
VulkanWindow::~VulkanWindow()
{
vkDestroyInstance(__VulkanInstance, nullptr);
glfwDestroyWindow(__Window);
glfwTerminate();
}
void VulkanWindow::performEvents() const
{
//glfwMakeContextCurrent(__Window);
//glViewport(0, 0, get_width(), get_height());
while(!glfwWindowShouldClose(__Window))
{
glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT);
// glBegin(GL_QUADS);
// glColor3f(1.0, 1.0, 1.0);
// glVertex3fv(GLfloat{1.0f,1.0f,1.0f});
// glVertex3fv(GLfloat{1.0f,0.0f,1.0f});
// glVertex3fv(GLfloat{1.0f,0.0f,0.0f});
// glEnd();
glfwSwapBuffers(__Window);
glfwPollEvents();
}
}
Выводит чёрный экран, а должен вывести зелёный.