1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include <stdio.h>
#include <stdlib.h>
#include "graphics.h"
#include "window.h"
#include "common.h"
window_t window;
graphics_t graphics;
int _create_surface(VkInstance instance, VkSurfaceKHR *surface);
vertex_t vertices[] = {
{{0.0f, -0.5f}, {1.0f, 0.0f, 0.0f}},
{{0.5f, 0.5f}, {0.0f, 1.0f, 0.0f}},
{{-0.5f, 0.5f}, {0.0f, 0.0f, 1.0f}}
};
int main(void)
{
int ret = 1;
if(SDL_Init(0)) {
err("SDL_Init: failed");
goto f1;
}
// populate window info
struct window_info win_info = {0};
win_info.title = "Test App";
win_info.flags = SDL_WINDOW_RESIZABLE;
win_info.w = 640;
win_info.h = 480;
// create window
window = window_create(&win_info);
if(!window) {
err("window_create: failed");
goto f2;
}
// get extensions
unsigned int ext_count = 0;
window_extension_info(window, &ext_count, NULL);
char **extensions = xcalloc(ext_count, sizeof(char *));
window_extension_info(window, &ext_count, (const char **)extensions);
// populate the device info
struct graphics_info grph_info = {0};
grph_info.name = "Test App";
grph_info.version = MAKE_VERSION(1, 0, 0);
grph_info.ext_count = ext_count;
grph_info.extensions = (const char * const *)extensions;
grph_info.vertices = vertices;
grph_info.nvertices = ARR_SIZE(vertices);
grph_info.surface_func = _create_surface;
// create the device
graphics = graphics_create(&grph_info);
if(!graphics) {
err("device_create: failed");
if(extensions) free(extensions);
goto f3;
}
if(extensions) free(extensions);
int running = 1;
while(running) {
SDL_Event windowEvent;
while(SDL_PollEvent(&windowEvent))
if(windowEvent.type == SDL_QUIT) {
running = 0;
break;
}
graphics_draw_frame(graphics);
}
ret = 0;
graphics_destroy(graphics);
f3: window_destroy(window);
f2: SDL_Quit();
f1: return ret;
}
int _create_surface(VkInstance instance, VkSurfaceKHR *surface)
{
return window_create_surface(window, instance, surface);
}
|