Mercurial > sdl-ios-xcode
comparison test/testshape.c @ 4804:b33752266d8f
Boxed up the rendering loop and turned it into a redraw/update function. This makes things way more responsive, usable again.
author | Eli Gottlieb <eligottlieb@gmail.com> |
---|---|
date | Sun, 18 Jul 2010 23:51:47 -0400 |
parents | a4c1df880690 |
children | de3b3455f8ec |
comparison
equal
deleted
inserted
replaced
4803:a4c1df880690 | 4804:b33752266d8f |
---|---|
8 #include <SDL_keysym.h> | 8 #include <SDL_keysym.h> |
9 | 9 |
10 #define SHAPED_WINDOW_X 150 | 10 #define SHAPED_WINDOW_X 150 |
11 #define SHAPED_WINDOW_Y 150 | 11 #define SHAPED_WINDOW_Y 150 |
12 #define SHAPED_WINDOW_DIMENSION 640 | 12 #define SHAPED_WINDOW_DIMENSION 640 |
13 | |
14 void render(SDL_Window* window,SDL_Texture *texture,SDL_Rect texture_dimensions) { | |
15 SDL_SelectRenderer(window); | |
16 | |
17 //Clear render-target to blue. | |
18 SDL_SetRenderDrawColor(0x00,0x00,0xff,0xff); | |
19 SDL_RenderClear(); | |
20 | |
21 //Render the texture. | |
22 SDL_RenderCopy(texture,&texture_dimensions,&texture_dimensions); | |
23 | |
24 SDL_RenderPresent(); | |
25 } | |
13 | 26 |
14 int main(int argc,char** argv) { | 27 int main(int argc,char** argv) { |
15 if(argc < 2) { | 28 if(argc < 2) { |
16 printf("SDL_Shape requires at least one bitmap file as argument.\n"); | 29 printf("SDL_Shape requires at least one bitmap file as argument.\n"); |
17 exit(-1); | 30 exit(-1); |
91 Uint32 format = 0,access = 0; | 104 Uint32 format = 0,access = 0; |
92 SDL_Rect texture_dimensions = {0,0,0,0}; | 105 SDL_Rect texture_dimensions = {0,0,0,0}; |
93 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); | 106 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
94 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); | 107 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
95 SDL_SetWindowShape(window,pictures[current_picture],&mode); | 108 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
109 render(window,textures[current_picture],texture_dimensions); | |
96 while(should_exit == 0) { | 110 while(should_exit == 0) { |
97 event_pending = SDL_PollEvent(&event); | 111 event_pending = SDL_PollEvent(&event); |
98 if(event_pending == 1) { | 112 if(event_pending == 1) { |
99 if(event.type == SDL_KEYDOWN) { | 113 if(event.type == SDL_KEYDOWN) { |
100 button_down = 1; | 114 button_down = 1; |
107 if(current_picture >= num_pictures) | 121 if(current_picture >= num_pictures) |
108 current_picture = 0; | 122 current_picture = 0; |
109 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); | 123 SDL_QueryTexture(textures[current_picture],&format,&access,&texture_dimensions.w,&texture_dimensions.h); |
110 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); | 124 SDL_SetWindowSize(window,texture_dimensions.w,texture_dimensions.h); |
111 SDL_SetWindowShape(window,pictures[current_picture],&mode); | 125 SDL_SetWindowShape(window,pictures[current_picture],&mode); |
126 render(window,textures[current_picture],texture_dimensions); | |
127 | |
112 } | 128 } |
113 if(event.type == SDL_QUIT) | 129 if(event.type == SDL_QUIT) |
114 should_exit = 1; | 130 should_exit = 1; |
115 event_pending = 0; | 131 event_pending = 0; |
116 } | 132 } |
117 | |
118 SDL_SelectRenderer(window); | |
119 | |
120 //Clear render-target to blue. | |
121 SDL_SetRenderDrawColor(0x00,0x00,0xff,0xff); | |
122 SDL_RenderClear(); | |
123 | |
124 //Render the texture. | |
125 SDL_RenderCopy(textures[current_picture],&texture_dimensions,&texture_dimensions); | |
126 | |
127 SDL_RenderPresent(); | |
128 } | 133 } |
129 | 134 |
130 //Free the textures. | 135 //Free the textures. |
131 for(i=0;i<num_pictures;i++) | 136 for(i=0;i<num_pictures;i++) |
132 SDL_DestroyTexture(textures[i]); | 137 SDL_DestroyTexture(textures[i]); |