summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..90985be
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,88 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "device.h"
+#include "window.h"
+#include "common.h"
+
+// TODO: rename device.c/.h
+// TODO: fix fail gotos
+
+window_t window;
+device_t device;
+
+int _create_surface(VkInstance instance, VkSurfaceKHR *surface);
+
+int main(void)
+{
+ int ret = 1;
+
+ if(SDL_Init(0)) {
+ err("SDL_Init: failed");
+ goto sf;
+ }
+
+ // populate window info
+ struct window_info win_info = {0};
+ win_info.title = "Test App";
+ win_info.w = 1200;
+ win_info.h = 800;
+
+ // create window
+ window = window_create(&win_info);
+ if(!window) {
+ err("window_create: failed");
+ goto wf;
+ }
+
+ // get extensions
+ unsigned int ext_count = 0;
+ window_extension_info(window, &ext_count, NULL);
+
+ // populate the device info
+ struct device_info dev_info = {0};
+ dev_info.name = "Test App";
+ dev_info.version = MAKE_VERSION(1, 0, 0);
+
+ if(ext_count == 0){
+ dev_info.ext_count = 0;
+ dev_info.extensions = NULL;
+ } else {
+ char **extensions = xcalloc(ext_count, sizeof(char *));
+ window_extension_info(window, &ext_count, (const char **)extensions);
+
+ dev_info.ext_count = ext_count;
+ dev_info.extensions = (const char * const *)extensions;
+ }
+
+ dev_info.surface_func = _create_surface;
+
+ // create the device
+ device = device_create(&dev_info);
+ if(!device) {
+ err("device_create: failed");
+ goto df;
+ }
+
+ int running = 1;
+ while(running) {
+ SDL_Event windowEvent;
+ while(SDL_PollEvent(&windowEvent))
+ if(windowEvent.type == SDL_QUIT) {
+ running = 0;
+ break;
+ }
+ }
+
+ ret = 0;
+df: device_destroy(device);
+wf: window_destroy(window);
+sf: SDL_Quit();
+ return ret;
+}
+
+int _create_surface(VkInstance instance, VkSurfaceKHR *surface)
+{
+ return window_create_surface(window, instance, surface);
+}