-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
64 lines (54 loc) · 1.09 KB
/
main.c
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
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
#include "image.h"
#include "app.h"
static void usage(int code, const char *name)
{
printf("usage: %s [-f] [-i IMAGE]\n", name);
exit(code);
}
int main(int argc, char **argv)
{
GLFWmonitor *mon = NULL;
struct application *app;
int c;
app = app_alloc();
app->width = W_WIDTH;
app->height = W_HEIGHT;
app->name = W_NAME;
app->image_name = DEFAULT_IMAGE;
app->fullscreen = 0;
while((c = getopt(argc, argv, "fi:")) != -1) {
switch(c) {
case 'f':
app->fullscreen = 1;
break;
case 'i':
if(file_is_png(optarg))
app->image_name = optarg;
else {
fprintf(stderr, "Specified image is not a PNG. Quitting...\n");
exit(-1);
}
break;
case '?':
usage(-1, app->name);
break;
default:
usage(-1, app->name);
}
}
app_init();
if(app->fullscreen)
mon = glfwGetPrimaryMonitor();
app->window = glfwCreateWindow(app->width, app->height, app->name,
mon, NULL);
if(!app->window) {
fprintf(stderr, "Failed to create window!\n");
return -1;
}
app_loop(app);
app_destroy(app);
return 0;
}