Added more stuff

main
noah metz 2024-01-07 03:04:12 -07:00
parent ffbc2d641e
commit 675480af21
2 changed files with 108 additions and 3 deletions

@ -1,5 +1,5 @@
CFLAGS = -I/opt/homebrew/include -O2 -Wall -Wextra CFLAGS = -I/usr/local/include -O2 -Wall -Wextra
LDFLAGS = -L/opt/homebrew/lib -lglfw -lvulkan -ldl LDFLAGS = -L/usr/local/lib -lglfw -lvulkan -ldl -Xlinker -rpath -Xlinker /usr/local/lib
CC = gcc CC = gcc
SOURCES = $(wildcard src/*.c) SOURCES = $(wildcard src/*.c)

@ -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;
} }