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(int r, int g, int b)
52 glClearColor(r/256, g/256, b/256, 1.0);
53 glClear(GL_COLOR_BUFFER_BIT);
58 SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, r, g, b));
62 /* --- FILL A RECT --- */
64 void fillrect(float x, float y, float w, float h, int r, int g, int b, int a)
70 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
71 glColor4ub(r, g, b,a);
85 SDL_Surface *temp = NULL;
94 temp = SDL_CreateRGBSurface(screen->flags, rect.w, rect.h, screen->format->BitsPerPixel,
95 screen->format->Rmask,
96 screen->format->Gmask,
97 screen->format->Bmask,
98 screen->format->Amask);
106 SDL_FillRect(temp, &src, SDL_MapRGB(screen->format, r, g, b));
108 SDL_SetAlpha(temp, SDL_SRCALPHA, a);
110 SDL_BlitSurface(temp,0,screen,&rect);
112 SDL_FreeSurface(temp);
115 SDL_FillRect(screen, &rect, SDL_MapRGB(screen->format, r, g, b));
124 /* --- UPDATE SCREEN --- */
126 void updatescreen(void)
128 if(use_gl) /*clearscreen(0,0,0);*/
129 SDL_GL_SwapBuffers();
131 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
134 void flipscreen(void)
137 SDL_GL_SwapBuffers();
142 /* --- LOAD AN IMAGE --- */
144 SDL_Surface * load_image(char * file, int use_alpha)
147 if(!faccessible(file))
149 if(!faccessible(st_dir,
152 SDL_Surface * temp, * surf;
154 temp = IMG_Load(file);
157 st_abort("Can't load", file);
159 surf = SDL_DisplayFormatAlpha(temp);
162 st_abort("Can't covert to display format", file);
164 if (use_alpha == IGNORE_ALPHA)
165 SDL_SetAlpha(surf, 0, 0);
167 SDL_FreeSurface(temp);
172 void update_rect(SDL_Surface *scr, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
175 SDL_UpdateRect(scr, x, y, w, h);
179 /* --- ERASE TEXT: --- */
181 void erasetext(char * text, int x, int y, texture_type * ptexture, int update, int shadowsize)
188 dest.w = strlen(text) * 16 + shadowsize;
191 if (dest.w > screen->w)
194 texture_draw_part(ptexture,dest.x,dest.y,dest.x,dest.y,dest.w,dest.h,update);
196 if (update == UPDATE)
197 update_rect(screen, dest.x, dest.y, dest.w, dest.h);
201 /* --- ERASE CENTERED TEXT: --- */
203 void erasecenteredtext(char * text, int y, texture_type * ptexture, int update, int shadowsize)
205 erasetext(text, screen->w / 2 - (strlen(text) * 8), y, ptexture, update, shadowsize);