1,准备
需要下载三个包,分别是glm,glfw,vulkan
glm,https://github.com/g-truc/glm
glfw,https://www.glfw.org/download.html
vulkan,https://vulkan.lunarg.com/sdk/home
运行vulkan,安装sdk
glm和glfw解压 -> vulkan目录的Third-Party。
2,VS2015创建项目
文件 -> 新建 -> 控制台应用程序。选择,Release x64
2.1 VC++目录 -> 包含目录
C:\VulkanSDK\1.1.106.0\Include
C:\VulkanSDK\1.1.106.0\Third-Party\glm
C:\VulkanSDK\1.1.106.0\Third-Party\glfw.bin.WIN64\include
2.2 VC++目录 -> 库目录
C:\VulkanSDK\1.1.106.0\Lib
C:\VulkanSDK\1.1.106.0\Third-Party\glfw.bin.WIN64\lib-vc2015
2.3 链接器 -> 输入 -> 附加依赖项
glfw3.lib
vulkan-1.lib
2.4 添加代码
#define GLFW_INCLUDE_VULKAN
#include <GLFW/glfw3.h>
#include <iostream>
#include <stdexcept>
#include <cstdlib>
const int WIDTH = 800;
const int HEIGHT = 600;
class HelloTriangleApplication {
public:
void run() {
initWindow();
initVulkan();
mainLoop();
cleanup();
}
private:
GLFWwindow* window;
VkInstance instance;
void initWindow() {
glfwInit();
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
window = glfwCreateWindow(WIDTH, HEIGHT, "Vulkan", nullptr, nullptr);
}
void initVulkan() {
createInstance();
}
void mainLoop() {
while (!glfwWindowShouldClose(window)) {
glfwPollEvents();
}
}
void cleanup() {
vkDestroyInstance(instance, nullptr);
glfwDestroyWindow(window);
glfwTerminate();
}
void 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 glfwExtensionCount = 0;
const char** glfwExtensions;
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
createInfo.enabledExtensionCount = glfwExtensionCount;
createInfo.ppEnabledExtensionNames = glfwExtensions;
createInfo.enabledLayerCount = 0;
if (vkCreateInstance(&createInfo, nullptr, &instance) != VK_SUCCESS) {
throw std::runtime_error("failed to create instance!");
}
}
};
int main()
{
HelloTriangleApplication app;
try {
app.run();
}
catch(const std::exception& e){
std::cerr << e.what() << std::endl;
return EXIT_FAILURE;
}
return EXIT_FAILURE;
}
运行以上程序,出现界面,安装成功。
3,学习资料
https://vulkan-tutorial.com/Development_environment
win10 opengl es 环境搭建