-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
157 lines (123 loc) · 2.18 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#include "main.h"
void strtoupper(char *str)
{
while (*str)
{
*str = (char) toupper(*str);
str++;
}
}
void l( char * str )
{
static FILE * fp;
if(!fp)
fp = fopen( "log.txt", "w" );
if( fp )
{
fprintf( fp, "%s", str );
fflush( fp );
}
}
void p( const char * format, ... )
{
char buf[0x4000];
va_list args;
va_start( args, format );
vsnprintf( buf, 0x4000, format, args );
va_end( args );
#ifdef WIN32
OutputDebugString( buf );
#else
fputs( buf, stderr );
#endif
l( buf );
}
BOOL sdl_print_info( void )
{
SDL_version ver;
SDL_VERSION(&ver);
p("SDL compile-time version: %u.%u.%u\n", ver.major, ver.minor, ver.patch);
ver = *SDL_Linked_Version();
p("SDL runtime version: %u.%u.%u\n", ver.major, ver.minor, ver.patch);
if( SDL_Init( SDL_INIT_VIDEO ) < 0 || !SDL_GetVideoInfo() )
{
p("Failed to initialize sdl: %s\n",SDL_GetError());
return FALSE;
}
return TRUE;
}
typedef struct {
int w;
int h;
} video_mode_t;
BOOL enumerate_video_mode( Uint32 flags, video_mode_t * mode )
{
SDL_Rect** modes = SDL_ListModes(NULL, flags);
if (modes == (SDL_Rect**)0)
{
p("No video modes available for given format!\n");
return FALSE;
}
if (modes != (SDL_Rect**)-1)
{
mode->w = modes[0]->w;
mode->h = modes[0]->h;
}
else
{
mode->w = 640;
mode->h = 480;
}
return TRUE;
}
BOOL sdl_init( void )
{
video_mode_t mode;
SDL_Surface * screen;
Uint32 flags = SDL_ANYFORMAT;// | SDL_FULLSCREEN;
sdl_print_info();
sdl_timer_init();
if(!enumerate_video_mode( flags, &mode ))
return FALSE;
screen = SDL_SetVideoMode( mode.w, mode.h, 24, flags );
if(!screen)
{
p("main_sdl: failed to create video surface: %s\n",SDL_GetError());
return FALSE;
}
return TRUE;
}
//px_timer_t main_timer;
int main( int argc, char* argv[] )
{
/*
int loops = 0;
timer_clear(&main_timer);
timer_run(&main_timer);
*/
#ifdef WIN32
if(!dx_init())
return FALSE;
#endif
if(!sdl_init())
return FALSE;
while(1)
{
/*
loops++;
if(timer_peek( &main_timer ) > 1.0f)
{
float fps = loops / timer_run( &main_timer );
loops = 0;
p("fps: %f\n",fps);
}
*/
#ifdef WIN32
dx_read_mouse();
#endif
if(!sdl_handle_events())
break;
}
SDL_Quit();
return 0;
}