3 #define GLFW_INCLUDE_VULKAN
4 #include <GLFW/glfw3.h>
11 /* static glfw callbacks */
14 clb_key(GLFWwindow *win, int key, int scancode, int action, int mods);
17 clb_reshape(GLFWwindow *win, int width, int height);
19 /* static functions */
31 /* static variables */
33 static GLFWwindow *win;
35 static int win_w = 800;
36 static int win_h = 600;
38 static struct vk_ctx vk_core;
39 static struct vk_swapchain vk_swap;
41 int main(int argc, char** argv)
49 /* reshape window once just in case */
51 glfwGetWindowSize(win, &win_w, &win_h);
52 clb_reshape(win, win_w, win_h);
56 while(!glfwWindowShouldClose(win)) {
64 /* static functions */
72 fprintf(stderr, "Failed to initialize GLFW.\n");
76 if (glfwVulkanSupported() != GLFW_TRUE) {
77 fprintf(stderr, "Vulkan is not supported on this device.\n");
81 /* initialize Vulkan context */
83 if (!vk_init_ctx_for_rendering(&vk_core)) {
84 fprintf(stderr, "Failed to initialize Vulkan context.\n");
88 memset(&vk_swap, 0, sizeof vk_swap);
92 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
93 win = glfwCreateWindow(win_w, win_h, "helloworld rt", 0, 0);
96 fprintf(stderr, "Failed to create GLFW window\n");
100 /* create (Xcb) surface */
102 glfwGetFramebufferSize(win, &win_h, &win_h);
103 if (glfwCreateWindowSurface(vk_core.inst, win, 0, &vk_swap.surface)
105 fprintf(stderr, "Failed to create XCB surface.\n");
109 /* create Vulkan swapchain */
115 /* create semaphores? */
117 /* create renderer */
119 /* set GLFW callbacks */
121 glfwSetKeyCallback(win, clb_key);
122 glfwSetWindowSizeCallback(win, clb_reshape);
125 glfwSetCursorPosCallback(win, clb_motion);
126 glfwSetMouseButtonCallback(win, clb_mouse);
140 vk_cleanup_ctx(&vk_core);
147 clb_key(GLFWwindow *win, int key, int scancode,
148 int action, int mods)
150 if (action == GLFW_PRESS) {
152 case GLFW_KEY_ESCAPE:
153 glfwSetWindowShouldClose(win, GLFW_TRUE);
160 clb_reshape(GLFWwindow *win, int width, int height)