4 Super Tux - Screen Functions
7 bill@newbreedsoftware.com
8 http://www.newbreedsoftware.com/supertux/
10 April 11, 2000 - April 22, 2000
19 #include <SDL_image.h>
23 #include <sys/types.h>
33 /* --- LOAD AND DISPLAY AN IMAGE --- */
35 void load_and_display_image(char * file)
39 img = load_image(file, IGNORE_ALPHA);
40 SDL_BlitSurface(img, NULL, screen, NULL);
45 /* --- CLEAR SCREEN --- */
47 void clearscreen(float r, float g, float b)
52 glClearColor(r/256, g/256, b/256, 1.0);
53 glClear(GL_COLOR_BUFFER_BIT);
57 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
61 /* --- FILL A RECT --- */
63 void fillrect(float x, float y, float w, float h, float r, float g, float b)
85 SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
92 /* --- UPDATE SCREEN --- */
94 void updatescreen(void)
96 if(use_gl) /*clearscreen(0,0,0);*/
99 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
102 void flipscreen(void)
105 SDL_GL_SwapBuffers();
110 /* --- LOAD AN IMAGE --- */
112 SDL_Surface * load_image(char * file, int use_alpha)
115 if(!faccessible(file))
117 if(!faccessible(st_dir,
120 SDL_Surface * temp, * surf;
122 temp = IMG_Load(file);
125 st_abort("Can't load", file);
127 surf = SDL_DisplayFormatAlpha(temp);
130 st_abort("Can't covert to display format", file);
132 if (use_alpha == IGNORE_ALPHA)
133 SDL_SetAlpha(surf, 0, 0);
135 SDL_FreeSurface(temp);
140 void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
143 SDL_UpdateRect(scr, x, y, w, h);
147 /* --- ERASE TEXT: --- */
149 void erasetext(char * text, int x, int y, texture_type * ptexture, int update, int shadowsize)
156 dest.w = strlen(text) * 16 + shadowsize;
159 if (dest.w > screen->w)
162 texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h,update);
164 if (update == UPDATE)
165 update_rect(screen, dest.x, dest.y, dest.w, dest.h);
169 /* --- ERASE CENTERED TEXT: --- */
171 void erasecenteredtext(char * text, int y, texture_type * ptexture, int update, int shadowsize)
173 erasetext(text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize);