Added more stuff
parent
ffbc2d641e
commit
675480af21
@ -1,7 +1,112 @@
|
|||||||
|
#include "vulkan/vulkan_core.h"
|
||||||
#define GLFW_INCLUDE_VULKAN
|
#define GLFW_INCLUDE_VULKAN
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#include <cglm/mat4.h>
|
||||||
|
#include <cglm/vec4.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
void glfw_error(int error, const char* description) {
|
||||||
|
fprintf(stderr, "GLFW_ERR: 0x%02x - %s\n", error, description);
|
||||||
|
}
|
||||||
|
|
||||||
|
GLFWwindow* init_window(int width, int height) {
|
||||||
|
glfwInit();
|
||||||
|
glfwSetErrorCallback(glfw_error);
|
||||||
|
|
||||||
|
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
|
||||||
|
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
|
||||||
|
GLFWwindow* window = glfwCreateWindow(width, height, "Vulkan window", 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
return window;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkInstance create_instance() {
|
||||||
|
VkInstance instance;
|
||||||
|
|
||||||
|
VkApplicationInfo app_info;
|
||||||
|
app_info.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO;
|
||||||
|
app_info.pApplicationName = "spacegame";
|
||||||
|
app_info.applicationVersion = VK_MAKE_VERSION(0, 0, 1);
|
||||||
|
app_info.pEngineName = "spacegame";
|
||||||
|
app_info.engineVersion = VK_MAKE_VERSION(0, 0, 1);
|
||||||
|
app_info.apiVersion = VK_API_VERSION_1_3;
|
||||||
|
|
||||||
|
VkInstanceCreateInfo instance_info;
|
||||||
|
instance_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
|
||||||
|
instance_info.pApplicationInfo = &app_info;
|
||||||
|
|
||||||
|
uint32_t glfwExtensionCount = 0;
|
||||||
|
const char** glfwExtensions;
|
||||||
|
|
||||||
|
glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
|
||||||
|
|
||||||
|
uint32_t extensionCount = 0;
|
||||||
|
vkEnumerateInstanceExtensionProperties(0, &extensionCount, 0);
|
||||||
|
|
||||||
|
VkExtensionProperties* extensions = (VkExtensionProperties*)(malloc(sizeof(VkExtensionProperties)*extensionCount));
|
||||||
|
vkEnumerateInstanceExtensionProperties(0, &extensionCount, extensions);
|
||||||
|
|
||||||
|
for(uint32_t i = 0; i < extensionCount; i++) {
|
||||||
|
fprintf(stderr, "Supported Extension: %s\n", extensions[i].extensionName);
|
||||||
|
}
|
||||||
|
|
||||||
|
free(extensions);
|
||||||
|
|
||||||
|
instance_info.enabledExtensionCount = glfwExtensionCount;
|
||||||
|
instance_info.ppEnabledExtensionNames = glfwExtensions;
|
||||||
|
instance_info.enabledLayerCount = 0;
|
||||||
|
|
||||||
|
VkResult result = vkCreateInstance(&instance_info, 0, &instance);
|
||||||
|
if(result != VK_SUCCESS) {
|
||||||
|
fprintf(stderr, "vkCreateInstance: 0x%02x\n", result);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
int init_vulkan() {
|
||||||
|
VkInstance instance = create_instance();
|
||||||
|
if(instance == 0) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
vkDestroyInstance(instance, 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void main_loop(GLFWwindow* window) {
|
||||||
|
while(!glfwWindowShouldClose(window)) {
|
||||||
|
glfwPollEvents();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanup(GLFWwindow* window) {
|
||||||
|
glfwDestroyWindow(window);
|
||||||
|
|
||||||
|
glfwTerminate();
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
GLFWwindow* window = init_window(800, 600);
|
||||||
|
if(window == 0) {
|
||||||
|
fprintf(stderr, "failed to initialize glfw window\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int result = init_vulkan();
|
||||||
|
if (result != 0) {
|
||||||
|
fprintf(stderr, "failed to initialize vulkan: err %d\n", result);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
main_loop(window);
|
||||||
|
|
||||||
|
cleanup(window);
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue