src/context.c

changeset 88
6234b7ea48f3
parent 86
943bf9d7c6d6
equal deleted inserted replaced
87:874a02a683c5 88:6234b7ea48f3
29 #include "ascension/error.h" 29 #include "ascension/error.h"
30 #include "ascension/utils.h" 30 #include "ascension/utils.h"
31 31
32 #include <SDL2/SDL.h> 32 #include <SDL2/SDL.h>
33 #include <SDL2/SDL_ttf.h> 33 #include <SDL2/SDL_ttf.h>
34 #include <SDL2/SDL_image.h>
34 35
35 #include <time.h> 36 #include <time.h>
36 37
37 AscContext asc_context; 38 AscContext asc_context;
38 39
74 NULL, 75 NULL,
75 CX_BUFFER_AUTO_EXTEND 76 CX_BUFFER_AUTO_EXTEND
76 ); 77 );
77 78
78 // initialize SDL 79 // initialize SDL
80 const int supported_img_flags = IMG_INIT_PNG | IMG_INIT_JPG;
79 if (SDL_Init(SDL_INIT_VIDEO) < 0) { 81 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
80 asc_error(SDL_GetError()); 82 asc_error(SDL_GetError());
81 } else { 83 } else if (TTF_Init() < 0) {
82 if (TTF_Init() < 0) { 84 asc_error(TTF_GetError());
83 asc_error(TTF_GetError()); 85 } else if (IMG_Init(supported_img_flags) != supported_img_flags) {
84 } 86 asc_error(IMG_GetError());
85 } 87 }
86 SDL_ClearError(); 88 SDL_ClearError();
87 asc_context.total_nanos = asc_nanos(); 89 asc_context.total_nanos = asc_nanos();
88 asc_set_flag(asc_context.flags, ASC_FLAG_INITILIZED); 90 asc_set_flag(asc_context.flags, ASC_FLAG_INITILIZED);
89 asc_dprintf("Ascension context initialized."); 91 asc_dprintf("Ascension context initialized.");
97 99
98 // destroy the font cache 100 // destroy the font cache
99 asc_font_cache_destroy(); 101 asc_font_cache_destroy();
100 102
101 // quit SDL 103 // quit SDL
102 if (TTF_WasInit()) 104 IMG_Quit();
103 TTF_Quit(); 105 TTF_Quit();
104 SDL_Quit(); 106 SDL_Quit();
105 107
106 // destroy the error buffer 108 // destroy the error buffer
107 cxBufferDestroy(&asc_context.error_buffer); 109 cxBufferDestroy(&asc_context.error_buffer);
108 asc_context.flags = 0; 110 asc_context.flags = 0;

mercurial