1
- #include <string.h>
2
- #include <stdlib.h>
3
- #include <stdio.h>
4
- #include <string.h>
1
+ #include " Demo.h"
5
2
3
+ #include < cstring>
4
+ #include < cstdlib>
5
+ #include < cstdio>
6
+ #include < cstring>
7
+ #include < fenv.h>
8
+
9
+ #include " tgl/tgl.h"
10
+
11
+ extern " C" {
6
12
#include " util/log.h"
7
13
#include " util/version.h"
8
14
#include " util/opt.h"
9
- #include "asset/node.h"
10
15
#include " graphics/graphics.h"
16
+ }
17
+
18
+ enum ArgType {
19
+ NO_ARG,
20
+ REQUIRED,
21
+ OPTIONAL
22
+ };
11
23
12
24
const struct {
13
- enum {
14
- NO_ARG ,
15
- REQUIRED ,
16
- OPTIONAL
17
- } arg ;
25
+ ArgType arg;
18
26
char s;
19
27
const char *l, *h;
20
28
} help[] = {
@@ -23,30 +31,26 @@ const struct {
23
31
{REQUIRED, ' d' , " data" , " Adds a directory to look for data files" },
24
32
{REQUIRED, ' s' , " shaders" , " Adds a directory to look for GLSL shaders" },
25
33
{REQUIRED, ' f' , " shader" , " ShaderToy demo: Select shader to load" },
34
+ {NO_ARG, 0 , " fpe" , " Enable trapping on floating point exceptions" },
26
35
{NO_ARG, 0 , NULL , NULL }
27
36
};
28
37
29
- ilA_fs demo_fs ;
30
- const char * demo_shader ;
31
-
32
- void demo_start ();
33
-
34
- int main (int argc , char * * argv )
38
+ void demoLoad (int argc, char **argv)
35
39
{
36
40
size_t i;
37
41
il_opts opts = il_opt_parse (argc, argv);
38
- il_modopts * main_opts = il_opts_lookup (& opts , "" );
42
+ il_modopts *main_opts = il_opts_lookup (&opts, const_cast < char *>( " " ) );
39
43
40
44
ilA_adddir (&demo_fs, " assets" , -1 );
41
45
42
46
for (i = 0 ; main_opts && i < main_opts->args .length ; i++) {
43
47
il_opt *opt = &main_opts->args .data [i];
44
48
char *arg = strndup (opt->arg .str , opt->arg .len );
45
- #define option (s , l ) if (il_string_cmp(opt->name, il_string_new(s)) || il_string_cmp(opt->name, il_string_new(l)))
49
+ #define option (s, l ) if (il_string_cmp(opt->name, il_string_new(const_cast <char *>(s))) || \
50
+ il_string_cmp (opt->name , il_string_new (const_cast <char *>(l))))
46
51
option (" h" , " help" ) {
47
52
printf (" IntenseLogic %s\n " , il_version);
48
53
printf (" Usage: %s [OPTIONS]\n\n " , argv[0 ]);
49
- printf ("Each module may have its own options, see relavent documentation for those.\n\n" );
50
54
printf (" Options:\n " );
51
55
for (i = 0 ; help[i].l ; i++) {
52
56
static const char *const arg_strs[] = {
@@ -67,13 +71,13 @@ int main(int argc, char **argv)
67
71
help[i].h
68
72
);
69
73
}
70
- return 0 ;
74
+ exit ( 0 ) ;
71
75
}
72
76
option (" v" , " version" ) {
73
77
printf (" IntenseLogic %s\n " , il_version);
74
78
printf (" Commit: %s\n " , il_commit);
75
79
printf (" Built: %s\n " , il_build_date);
76
- return 0 ;
80
+ exit ( 0 ) ;
77
81
}
78
82
option (" d" , " data" ) {
79
83
ilA_adddir (&demo_fs, arg, -1 );
@@ -85,6 +89,10 @@ int main(int argc, char **argv)
85
89
demo_shader = arg;
86
90
continue ; // don't free arg
87
91
}
92
+ option (" " , " fpe" ) {
93
+ feenableexcept (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW);
94
+ il_log (" Floating point exceptions enabled" );
95
+ }
88
96
free (arg);
89
97
}
90
98
@@ -97,8 +105,43 @@ int main(int argc, char **argv)
97
105
il_log (" Built %s" , il_build_date);
98
106
99
107
il_load_ilgraphics ();
100
- demo_start ();
101
- ilG_quit ();
108
+ }
109
+
110
+ Window createWindow (const char *title, unsigned msaa)
111
+ {
112
+ Window window;
113
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
114
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_MINOR_VERSION, 2 );
115
+ SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8 );
116
+ SDL_GL_SetAttribute (SDL_GL_GREEN_SIZE, 8 );
117
+ SDL_GL_SetAttribute (SDL_GL_BLUE_SIZE, 8 );
118
+ SDL_GL_SetAttribute (SDL_GL_MULTISAMPLEBUFFERS, msaa != 0 );
119
+ if (msaa) {
120
+ SDL_GL_SetAttribute (SDL_GL_MULTISAMPLESAMPLES, msaa);
121
+ }
122
+ SDL_GL_SetAttribute (SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
123
+ window.window = SDL_CreateWindow (
124
+ title,
125
+ SDL_WINDOWPOS_UNDEFINED,
126
+ SDL_WINDOWPOS_UNDEFINED,
127
+ 800 , 600 ,
128
+ SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
129
+ if (!window.window ) {
130
+ il_error (" SDL_CreateWindow: %s" , SDL_GetError ());
131
+ exit (1 );
132
+ }
133
+ window.context = SDL_GL_CreateContext (window.window );
134
+ if (!window.context ) {
135
+ il_error (" SDL_GL_CreateContext: %s" , SDL_GetError ());
136
+ exit (1 );
137
+ }
138
+ if (epoxy_gl_version () < 32 ) {
139
+ il_error (" Expected GL 3.2, got %u" , epoxy_gl_version ());
140
+ exit (1 );
141
+ }
102
142
103
- return 0 ;
143
+ return window ;
104
144
}
145
+
146
+ ilA_fs demo_fs;
147
+ const char *demo_shader;
0 commit comments