comparison Xcode-iPhoneOS/Demos/src/happy.c @ 3685:64ce267332c6

Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 21 Jan 2010 06:21:52 +0000
parents 20326ba2bda2
children 78db79f5a4e2
comparison
equal deleted inserted replaced
3684:cc564f08884f 3685:64ce267332c6
9 9
10 #define NUM_HAPPY_FACES 100 /* number of faces to draw */ 10 #define NUM_HAPPY_FACES 100 /* number of faces to draw */
11 #define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */ 11 #define MILLESECONDS_PER_FRAME 16 /* about 60 frames per second */
12 #define HAPPY_FACE_SIZE 32 /* width and height of happyface (pixels) */ 12 #define HAPPY_FACE_SIZE 32 /* width and height of happyface (pixels) */
13 13
14 static SDL_TextureID texture_id = 0; /* reference to texture holding happyface */ 14 static SDL_Texture *texture = 0; /* reference to texture holding happyface */
15 15
16 static struct 16 static struct
17 { 17 {
18 float x, y; /* position of happyface */ 18 float x, y; /* position of happyface */
19 float xvel, yvel; /* velocity of happyface */ 19 float xvel, yvel; /* velocity of happyface */
84 faces[i].y = miny; 84 faces[i].y = miny;
85 faces[i].yvel = -faces[i].yvel; 85 faces[i].yvel = -faces[i].yvel;
86 } 86 }
87 dstRect.x = faces[i].x; 87 dstRect.x = faces[i].x;
88 dstRect.y = faces[i].y; 88 dstRect.y = faces[i].y;
89 SDL_RenderCopy(texture_id, &srcRect, &dstRect); 89 SDL_RenderCopy(texture, &srcRect, &dstRect);
90 } 90 }
91 /* update screen */ 91 /* update screen */
92 SDL_RenderPresent(); 92 SDL_RenderPresent();
93 93
94 } 94 }
122 SDL_CreateRGBSurface(0, bmp_surface->w, bmp_surface->h, bpp, Rmask, 122 SDL_CreateRGBSurface(0, bmp_surface->w, bmp_surface->h, bpp, Rmask,
123 Gmask, Bmask, Amask); 123 Gmask, Bmask, Amask);
124 SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL); 124 SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);
125 125
126 /* convert RGBA surface to texture */ 126 /* convert RGBA surface to texture */
127 texture_id = SDL_CreateTextureFromSurface(format, bmp_surface_rgba); 127 texture = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
128 if (texture_id == 0) { 128 if (texture == 0) {
129 fatalError("could not create texture"); 129 fatalError("could not create texture");
130 } 130 }
131 SDL_SetTextureBlendMode(texture_id, SDL_BLENDMODE_BLEND); 131 SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
132 132
133 /* free up allocated memory */ 133 /* free up allocated memory */
134 SDL_FreeSurface(bmp_surface_rgba); 134 SDL_FreeSurface(bmp_surface_rgba);
135 SDL_FreeSurface(bmp_surface); 135 SDL_FreeSurface(bmp_surface);
136 } 136 }
137 137
138 int 138 int
139 main(int argc, char *argv[]) 139 main(int argc, char *argv[])
140 { 140 {
141 141
142 SDL_WindowID windowID; 142 SDL_Window *window;
143 Uint32 startFrame; 143 Uint32 startFrame;
144 Uint32 endFrame; 144 Uint32 endFrame;
145 Uint32 delay; 145 Uint32 delay;
146 int done; 146 int done;
147 147
148 /* initialize SDL */ 148 /* initialize SDL */
149 if (SDL_Init(SDL_INIT_VIDEO) < 0) { 149 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
150 fatalError("Could not initialize SDL"); 150 fatalError("Could not initialize SDL");
151 } 151 }
152 windowID = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 152 window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
153 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | 153 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
154 SDL_WINDOW_BORDERLESS); 154 SDL_WINDOW_BORDERLESS);
155 155
156 SDL_CreateRenderer(windowID, -1, 0); 156 SDL_CreateRenderer(window, -1, 0);
157 157
158 initializeTexture(); 158 initializeTexture();
159 initializeHappyFaces(); 159 initializeHappyFaces();
160 160
161 /* main loop */ 161 /* main loop */
180 } 180 }
181 SDL_Delay(delay); 181 SDL_Delay(delay);
182 } 182 }
183 183
184 /* cleanup */ 184 /* cleanup */
185 SDL_DestroyTexture(texture_id); 185 SDL_DestroyTexture(texture);
186 /* shutdown SDL */ 186 /* shutdown SDL */
187 SDL_Quit(); 187 SDL_Quit();
188 188
189 return 0; 189 return 0;
190 190