Mercurial > sdl-ios-xcode
comparison test/testshape.c @ 4800:6d4be626225f
Same place as before, but optimizing a bit to try to isolate the spot in the program that locks things up.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 22:17:52 -0400 |
parents | a0e096916474 |
children | f14a8c05f5bb |
comparison
equal
deleted
inserted
replaced
4799:a0e096916474 | 4800:6d4be626225f |
---|---|
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. | 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}; | 42 SDL_PixelFormat format = {NULL,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; |
43 SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&format.BitsPerPixel,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask); | 43 int bpp = 0; |
44 SDL_PixelFormatEnumToMasks(SDL_PIXELFORMAT_RGBA8888,&bpp,&format.Rmask,&format.Gmask,&format.Bmask,&format.Amask); | |
45 format.BitsPerPixel = bpp; | |
44 format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0); | 46 format.BytesPerPixel = format.BitsPerPixel / 8 + (format.BitsPerPixel % 8 > 0 ? 1 : 0); |
45 pictures[i] = SDL_ConvertSurface(original,&format,0); | 47 pictures[i] = SDL_ConvertSurface(original,&format,0); |
46 //We have no more need of the original now that we have our desired format. | 48 //We have no more need of the original now that we have our desired format. |
47 SDL_FreeSurface(original); | 49 SDL_FreeSurface(original); |
48 if(pictures[i] == NULL) { | 50 if(pictures[i] == NULL) { |
62 void* pixels = pictures[i]->pixels; | 64 void* pixels = pictures[i]->pixels; |
63 unsigned int pitch = pictures[i]->pitch; | 65 unsigned int pitch = pictures[i]->pitch; |
64 int y =0,x = 0; | 66 int y =0,x = 0; |
65 for(y=0;y<pictures[i]->h;y++) | 67 for(y=0;y<pictures[i]->h;y++) |
66 for(x=0;x<pictures[i]->w;x++) { | 68 for(x=0;x<pictures[i]->w;x++) { |
67 Uint32* pixel = pixels+y*pitch+x*pictures[i]->format->BytesPerPixel; | 69 Uint32* pixel = pixels + y * pitch + x * pictures[i]->format->BytesPerPixel; |
68 Uint8 r = 0,g = 0,b = 0; | 70 Uint8 r = 0,g = 0,b = 0; |
69 SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b); | 71 SDL_GetRGB(*pixel,pictures[i]->format,&r,&g,&b); |
70 if(r == g == b == 0x00) | 72 //if(r == g == b == 0xff) |
71 *pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0); | 73 // *pixel = SDL_MapRGBA(pictures[i]->format,r,g,b,0); |
72 } | 74 } |
73 | 75 |
74 if(SDL_MUSTLOCK(pictures[i])) | 76 if(SDL_MUSTLOCK(pictures[i])) |
75 SDL_UnlockSurface(pictures[i]); | 77 SDL_UnlockSurface(pictures[i]); |
76 } | 78 } |
115 exit(-6); | 117 exit(-6); |
116 } | 118 } |
117 } | 119 } |
118 | 120 |
119 SDL_Event event; | 121 SDL_Event event; |
120 int event_pending = 0; | 122 int event_pending = 0,should_exit = 0; |
121 event_pending = SDL_PollEvent(&event); | 123 event_pending = SDL_PollEvent(&event); |
122 unsigned int current_picture = 0; | 124 unsigned int current_picture = 0; |
123 SDL_WindowShapeMode mode = {ShapeModeDefault,1}; | 125 SDL_WindowShapeMode mode = {ShapeModeDefault,1}; |
124 SDL_SetWindowShape(window,pictures[current_picture],&mode); | 126 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
125 int mouse_down = 0; | 127 int mouse_down = 0; |
126 Uint32 format,access; | 128 Uint32 format,access; |
127 SDL_Rect texture_dimensions = {0,0,0,0}; | 129 SDL_Rect texture_dimensions = {0,0,0,0}; |
128 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); | 130 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
129 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); | 131 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
130 while(event.type != SDL_QUIT) { | 132 while(should_exit == 0) { |
131 if(event.type == SDL_MOUSEBUTTONDOWN) | 133 event_pending = SDL_PollEvent(&event); |
132 mouse_down = 1; | 134 if(event_pending == 1) { |
133 if(mouse_down && event.type == SDL_MOUSEBUTTONUP) { | 135 if(event.type == SDL_MOUSEBUTTONDOWN) |
134 mouse_down = 0; | 136 mouse_down = 1; |
135 current_picture += 1; | 137 if(mouse_down && event.type == SDL_MOUSEBUTTONUP) { |
136 if(current_picture >= num_pictures) | 138 mouse_down = 0; |
137 current_picture = 0; | 139 current_picture += 1; |
138 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); | 140 if(current_picture >= num_pictures) |
139 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); | 141 current_picture = 0; |
140 SDL_SetWindowShape(window,pictures[current_picture],&mode); | 142 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
143 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); | |
144 SDL_SetWindowShape(window,pictures[current_picture],&mode); | |
145 } | |
146 if(event.type == SDL_QUIT) | |
147 should_exit = 1; | |
148 event_pending = 0; | |
141 } | 149 } |
142 | 150 |
143 SDL_SelectRenderer(window); | 151 SDL_SelectRenderer(window); |
144 | 152 |
145 //Clear render-target to blue. | 153 //Clear render-target to blue. |
148 | 156 |
149 //Render the texture. | 157 //Render the texture. |
150 SDL_RenderCopy(textures[current_picture],&texture_dimensions,&texture_dimensions); | 158 SDL_RenderCopy(textures[current_picture],&texture_dimensions,&texture_dimensions); |
151 | 159 |
152 SDL_RenderPresent(); | 160 SDL_RenderPresent(); |
153 event_pending = SDL_PollEvent(&event); | |
154 } | 161 } |
155 | 162 |
156 //Free the textures. | 163 //Free the textures. |
157 for(i=0;i<num_pictures;i++) | 164 for(i=0;i<num_pictures;i++) |
158 SDL_DestroyTexture(textures[i]); | 165 SDL_DestroyTexture(textures[i]); |