comparison render_sdl.c @ 799:0b692b5d154b

Merge
author Michael Pavone <pavone@retrodev.com>
date Sun, 26 Jul 2015 13:25:31 -0700
parents 062a2199daf6 724bbec47f86
children ec23202df6a6
comparison
equal deleted inserted replaced
798:062a2199daf6 799:0b692b5d154b
218 { 218 {
219 render_close_audio(); 219 render_close_audio();
220 #ifdef DISABLE_OPENGL 220 #ifdef DISABLE_OPENGL
221 SDL_DestroyTexture(main_texture); 221 SDL_DestroyTexture(main_texture);
222 #endif 222 #endif
223 SDL_Quit();
224 } 223 }
225 224
226 void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen) 225 void render_init(int width, int height, char * title, uint32_t fps, uint8_t fullscreen)
227 { 226 {
228 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) { 227 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK) < 0) {
229 fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError()); 228 fatal_error("Unable to init SDL: %s\n", SDL_GetError());
230 exit(1); 229 }
231 } 230 atexit(SDL_Quit);
232 printf("width: %d, height: %d\n", width, height); 231 printf("width: %d, height: %d\n", width, height);
233 232
234 uint32_t flags = 0; 233 uint32_t flags = 0;
235 234
236 if (fullscreen) { 235 if (fullscreen) {
253 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); 252 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5);
254 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0); 253 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
255 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 254 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
256 main_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); 255 main_window = SDL_CreateWindow(title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags);
257 if (!main_window) { 256 if (!main_window) {
258 fprintf(stderr, "Unable to create SDL window: %s\n", SDL_GetError()); 257 fatal_error("Unable to create SDL window: %s\n", SDL_GetError());
259 SDL_Quit();
260 exit(1);
261 } 258 }
262 main_context = SDL_GL_CreateContext(main_window); 259 main_context = SDL_GL_CreateContext(main_window);
263 GLenum res = glewInit(); 260 GLenum res = glewInit();
264 if (res != GLEW_OK) { 261 if (res != GLEW_OK) {
265 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res); 262 fprintf(stderr, "Initialization of GLEW failed with code %d\n", res);
266 SDL_DestroyWindow(main_window);
267 } 263 }
268 264
269 if (GLEW_VERSION_2_0) { 265 if (GLEW_VERSION_2_0) {
270 render_gl = 1; 266 render_gl = 1;
271 } 267 }
359 desired.samples = samples*2; 355 desired.samples = samples*2;
360 desired.callback = audio_callback; 356 desired.callback = audio_callback;
361 desired.userdata = NULL; 357 desired.userdata = NULL;
362 358
363 if (SDL_OpenAudio(&desired, &actual) < 0) { 359 if (SDL_OpenAudio(&desired, &actual) < 0) {
364 fprintf(stderr, "Unable to open SDL audio: %s\n", SDL_GetError()); 360 fatal_error("Unable to open SDL audio: %s\n", SDL_GetError());
365 SDL_Quit();
366 exit(1);
367 } 361 }
368 buffer_samples = actual.samples; 362 buffer_samples = actual.samples;
369 sample_rate = actual.freq; 363 sample_rate = actual.freq;
370 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples); 364 printf("Initialized audio at frequency %d with a %d sample buffer\n", actual.freq, actual.samples);
371 SDL_PauseAudio(0); 365 SDL_PauseAudio(0);
638 uint32_t render_sample_rate() 632 uint32_t render_sample_rate()
639 { 633 {
640 return sample_rate; 634 return sample_rate;
641 } 635 }
642 636
643 637 void render_errorbox(char *title, char *message)
638 {
639 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL);
640 }
641
642 void render_warnbox(char *title, char *message)
643 {
644 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_WARNING, title, message, NULL);
645 }
646
647 void render_infobox(char *title, char *message)
648 {
649 SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_INFORMATION, title, message, NULL);
650 }
651