Mercurial > sdl-ios-xcode
comparison test/testalpha.c @ 691:609543e2b3a1
Date: Fri, 15 Aug 2003 09:13:59 +0300
From: "Mike Gorchak"
Subject: Patches for tests and QNX6
1) graywin - added support for the gray gradient in the 15/16 bpp modes. Added SDL_VIDEOEXPOSE event handling.
2) testalpha - added support for the gray gradient in the 15/16 bpp modes.
3) testbitmap - added support for the gray gradient in the 8/15/16 bpp modes.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 23 Aug 2003 23:18:49 +0000 |
parents | 74212992fb08 |
children | 05c551e5bc64 |
comparison
equal
deleted
inserted
replaced
690:b87d8d4c205d | 691:609543e2b3a1 |
---|---|
277 const SDL_VideoInfo *info; | 277 const SDL_VideoInfo *info; |
278 SDL_Surface *screen; | 278 SDL_Surface *screen; |
279 Uint8 video_bpp; | 279 Uint8 video_bpp; |
280 Uint32 videoflags; | 280 Uint32 videoflags; |
281 Uint8 *buffer; | 281 Uint8 *buffer; |
282 int i, done; | 282 int i, k, done; |
283 SDL_Event event; | 283 SDL_Event event; |
284 SDL_Surface *light; | 284 SDL_Surface *light; |
285 int mouse_pressed; | 285 int mouse_pressed; |
286 Uint32 ticks, lastticks; | 286 Uint32 ticks, lastticks; |
287 Uint16 *buffer16; | |
288 Uint16 color; | |
289 Uint8 gradient; | |
290 | |
287 | 291 |
288 /* Initialize SDL */ | 292 /* Initialize SDL */ |
289 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { | 293 if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { |
290 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); | 294 fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); |
291 exit(1); | 295 exit(1); |
296 info = SDL_GetVideoInfo(); | 300 info = SDL_GetVideoInfo(); |
297 if ( info->vfmt->BitsPerPixel > 8 ) { | 301 if ( info->vfmt->BitsPerPixel > 8 ) { |
298 video_bpp = info->vfmt->BitsPerPixel; | 302 video_bpp = info->vfmt->BitsPerPixel; |
299 } else { | 303 } else { |
300 video_bpp = 16; | 304 video_bpp = 16; |
305 fprintf(stderr, "forced 16 bpp mode\n"); | |
301 } | 306 } |
302 videoflags = SDL_SWSURFACE; | 307 videoflags = SDL_SWSURFACE; |
303 while ( argc > 1 ) { | 308 while ( argc > 1 ) { |
304 --argc; | 309 --argc; |
305 if ( strcmp(argv[argc-1], "-bpp") == 0 ) { | 310 if ( strcmp(argv[argc-1], "-bpp") == 0 ) { |
306 video_bpp = atoi(argv[argc]); | 311 video_bpp = atoi(argv[argc]); |
312 if (video_bpp<=8) { | |
313 video_bpp=16; | |
314 fprintf(stderr, "forced 16 bpp mode\n"); | |
315 } | |
307 --argc; | 316 --argc; |
308 } else | 317 } else |
309 if ( strcmp(argv[argc], "-hw") == 0 ) { | 318 if ( strcmp(argv[argc], "-hw") == 0 ) { |
310 videoflags |= SDL_HWSURFACE; | 319 videoflags |= SDL_HWSURFACE; |
311 } else | 320 } else |
334 fprintf(stderr, "Couldn't lock the display surface: %s\n", | 343 fprintf(stderr, "Couldn't lock the display surface: %s\n", |
335 SDL_GetError()); | 344 SDL_GetError()); |
336 exit(2); | 345 exit(2); |
337 } | 346 } |
338 buffer=(Uint8 *)screen->pixels; | 347 buffer=(Uint8 *)screen->pixels; |
339 for ( i=0; i<screen->h; ++i ) { | 348 if (screen->format->BytesPerPixel!=2) { |
340 memset(buffer,(i*255)/screen->h, screen->pitch); | 349 for ( i=0; i<screen->h; ++i ) { |
341 buffer += screen->pitch; | 350 memset(buffer,(i*255)/screen->h, screen->pitch); |
342 } | 351 buffer += screen->pitch; |
352 } | |
353 } | |
354 else | |
355 { | |
356 for ( i=0; i<screen->h; ++i ) { | |
357 gradient=((i*255)/screen->h); | |
358 color = SDL_MapRGB(screen->format, gradient, gradient, gradient); | |
359 buffer16=(Uint16*)buffer; | |
360 for (k=0; k<screen->w; k++) | |
361 { | |
362 *(buffer16+k)=color; | |
363 } | |
364 buffer += screen->pitch; | |
365 } | |
366 } | |
367 | |
343 SDL_UnlockSurface(screen); | 368 SDL_UnlockSurface(screen); |
344 SDL_UpdateRect(screen, 0, 0, 0, 0); | 369 SDL_UpdateRect(screen, 0, 0, 0, 0); |
345 | 370 |
346 /* Create the light */ | 371 /* Create the light */ |
347 light = CreateLight(screen, 82); | 372 light = CreateLight(screen, 82); |