Mercurial > sdl-ios-xcode
comparison test/testshape.c @ 4802:f14a8c05f5bb
Minor bugfixes. testshape now draws a shaped window with bizarre, pixellated gashes of transparency across it, and in doing so seems to hog a system resource and slow the rest of the video system down.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 23:05:40 -0400 |
parents | 6d4be626225f |
children | a4c1df880690 |
comparison
equal
deleted
inserted
replaced
4801:506a9165491b | 4802:f14a8c05f5bb |
---|---|
25 SDL_Surface **pictures = malloc(sizeof(SDL_Surface*)*num_pictures); | 25 SDL_Surface **pictures = malloc(sizeof(SDL_Surface*)*num_pictures); |
26 int i = 0; | 26 int i = 0; |
27 for(i=0;i<num_pictures;i++) | 27 for(i=0;i<num_pictures;i++) |
28 pictures[i] = NULL; | 28 pictures[i] = NULL; |
29 for(i=0;i<num_pictures;i++) { | 29 for(i=0;i<num_pictures;i++) { |
30 SDL_Surface *original = SDL_LoadBMP(argv[i+1]); | 30 pictures[i] = SDL_LoadBMP(argv[i+1]); |
31 if(original == NULL) { | 31 if(pictures[i] == NULL) { |
32 int j = 0; | 32 int j = 0; |
33 for(j=0;j<num_pictures;j++) | 33 for(j=0;j<num_pictures;j++) |
34 if(pictures[j] != NULL) | 34 if(pictures[j] != NULL) |
35 SDL_FreeSurface(pictures[j]); | 35 SDL_FreeSurface(pictures[j]); |
36 free(pictures); | 36 free(pictures); |
37 SDL_VideoQuit(); | 37 SDL_VideoQuit(); |
38 printf("Could not load surface from named bitmap file.\n"); | 38 printf("Could not load surface from named bitmap file.\n"); |
39 exit(-3); | 39 exit(-3); |
40 } | 40 } |
41 //THIS CONVERSION ROUTINE IS FRAGILE! It relies in the fact that only certain portions of the format structure must be filled in to use it. | |
42 SDL_PixelFormat format = {NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
43 int bpp = 0; | |
44 SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&bpp,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask); | |
45 format.BitsPerPixel = bpp; | |
46 format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0); | |
47 pictures[i] = SDL_ConvertSurface(original,&format,0); | |
48 //We have no more need of the original now that we have our desired format. | |
49 SDL_FreeSurface(original); | |
50 if(pictures[i] == NULL) { | |
51 int j = 0; | |
52 for(j=0;j<num_pictures;j++) | |
53 if(pictures[j] != NULL) | |
54 SDL_FreeSurface(pictures[j]); | |
55 free(pictures); | |
56 SDL_VideoQuit(); | |
57 printf("Could not convert bitmap surface to desired format.\n"); | |
58 exit(-3); | |
59 } | |
60 | |
61 if(SDL_MUSTLOCK(pictures[i])) | |
62 SDL_LockSurface(pictures[i]); | |
63 | |
64 void* pixels = pictures[i]->pixels; | |
65 unsigned int pitch = pictures[i]->pitch; | |
66 int y =0,x = 0; | |
67 for(y=0;y<pictures[i]->h;y++) | |
68 for(x=0;x<pictures[i]->w;x++) { | |
69 Uint32* pixel = pixels + y * pitch + x * pictures[i]->format->BytesPerPixel; | |
70 Uint8 r = 0,g = 0,b = 0; | |
71 SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b); | |
72 //if(r == g == b == 0xff) | |
73 // *pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0); | |
74 } | |
75 | |
76 if(SDL_MUSTLOCK(pictures[i])) | |
77 SDL_UnlockSurface(pictures[i]); | |
78 } | 41 } |
79 | 42 |
80 SDL_Window *window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); | 43 SDL_Window *window = SDL_CreateShapedWindow("SDL_Shape test",SHAPED_WINDOW_X,SHAPED_WINDOW_Y,SHAPED_WINDOW_DIMENSION,SHAPED_WINDOW_DIMENSION,SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); |
81 if(window == NULL) { | 44 if(window == NULL) { |
82 for(i=0;i<num_pictures;i++) | 45 for(i=0;i<num_pictures;i++) |
121 SDL_Event event; | 84 SDL_Event event; |
122 int event_pending = 0,should_exit = 0; | 85 int event_pending = 0,should_exit = 0; |
123 event_pending = SDL_PollEvent(&event); | 86 event_pending = SDL_PollEvent(&event); |
124 unsigned int current_picture = 0; | 87 unsigned int current_picture = 0; |
125 SDL_WindowShapeMode mode = {ShapeModeDefault,1}; | 88 SDL_WindowShapeMode mode = {ShapeModeDefault,1}; |
126 SDL_SetWindowShape(window,pictures[current_picture],&mode); | |
127 int mouse_down = 0; | 89 int mouse_down = 0; |
128 Uint32 format,access; | 90 Uint32 format = 0,access = 0; |
129 SDL_Rect texture_dimensions = {0,0,0,0}; | 91 SDL_Rect texture_dimensions = {0,0,0,0}; |
130 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); | 92 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
131 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); | 93 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
94 SDL_SetWindowShape(window,pictures[current_picture],&mode); | |
132 while(should_exit == 0) { | 95 while(should_exit == 0) { |
133 event_pending = SDL_PollEvent(&event); | 96 event_pending = SDL_PollEvent(&event); |
134 if(event_pending == 1) { | 97 if(event_pending == 1) { |
135 if(event.type == SDL_MOUSEBUTTONDOWN) | 98 if(event.type == SDL_MOUSEBUTTONDOWN) |
136 mouse_down = 1; | 99 mouse_down = 1; |