// VulkanTutorial.cpp: 定义应用程序的入口点。 // #include "VulkanTutorial.h" GLFWwindow* HelloTriangleApplication::initWindow(int Width, int Height) { glfwInit(); glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); auto window = glfwCreateWindow(Width, Height, "vulkan", nullptr, nullptr); return window; } void HelloTriangleApplication::createInstance() { VkApplicationInfo appInfo = {}; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; appInfo.pApplicationName = "Hello Triangle"; 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; uint32_t glfwExtentionCount = 0; const char** glfwExtensions; glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtentionCount); createInfo.enabledExtensionCount = glfwExtentionCount; createInfo.ppEnabledExtensionNames = glfwExtensions; createInfo.enabledLayerCount = 0; if (vkCreateInstance(&createInfo, nullptr, &instance)!=VK_SUCCESS) { throw std::runtime_error("failed to create instance"); } uint32_t extensionCount = 0; vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, nullptr); std::vector extensions(extensionCount); vkEnumerateInstanceExtensionProperties(nullptr, &extensionCount, extensions.data()); std::cout << "available extensions :" << std::endl; for (const auto& extension : extensions) { std::cout << "\t" << extension.extensionName << " version:" << extension.specVersion << std::endl; } } void HelloTriangleApplication::initVulkan() { createInstance(); } void HelloTriangleApplication::mainLoop(GLFWwindow* window){ while (!glfwWindowShouldClose(window)) { glfwPollEvents(); } } void HelloTriangleApplication::cleanup(GLFWwindow* window) { vkDestroyInstance(instance, nullptr); glfwDestroyWindow(window); glfwTerminate(); } int main() { HelloTriangleApplication app; int Width = 800; int Height = 600; try { app.run(Width,Height); } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return EXIT_FAILURE; } return EXIT_SUCCESS; }