Visual Studio 2022:Vulkan 环境配置

  1. (前置)安装VulkanSDK,并确认安装目录,此后记为%VulkanDir%(例如:C:/VulkanSDK/1.3.261.1)
  2. Visual Studio中新建C++项目,进入“项目”>>“[项目名]属性”,上方两个选项设置为“所有配置”“所有平台”
  3. C/C++ >> 常规 >> 附加包含目录:添加%VulkanDir%/Include(替换%VulkanDir%为实际目录,下同)
  4. 链接器 >> 常规 >> 附加库目录:添加%VulkanDir%/Lib
  5. 链接器 >> 输入 >> 附加依赖项:添加vulkan-1.lib
  6. GLM和GLFW库:通过vcpkg安装更方便,Vulkan也可通过vcpkg安装,但未尝试过

测试代码

#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 <iostream>

int main()
{
    glfwInit();

    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" << std::endl;

    // 测试GLM
    glm::mat4 matrix(1.0f);
    glm::vec4 vec(0.0f, 1.0f, 0.0f, 0.0f);
    auto test = matrix * vec;

    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();
    }

    glfwDestroyWindow(window);

    glfwTerminate();

    return 0;
}
posted @ 2023-11-30 23:34  Stehsaer  阅读(336)  评论(0编辑  收藏  举报