Updated the template code
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Feb 2011 19:15:00 -0800
changeset 5366 d032ec40e7c1
parent 5365 db3c6ebcc954
child 5367 71fe70373e58
Updated the template code
Xcode-iPhoneOS/Template/SDL iOS Application/main.c
Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/main.c
--- a/Xcode-iPhoneOS/Template/SDL iOS Application/main.c	Sun Feb 20 14:59:36 2011 -0800
+++ b/Xcode-iPhoneOS/Template/SDL iOS Application/main.c	Sun Feb 20 19:15:00 2011 -0800
@@ -17,10 +17,15 @@
 }
 
 void
-render(void)
+render(SDL_Renderer *renderer)
 {
 
     Uint8 r, g, b;
+
+    /* Clear the screen */
+    SDL_SetRenderDrawColor(0, 0, 0, 255);
+    SDL_SetRenderClear(renderer);
+
     /*  Come up with a random rectangle */
     SDL_Rect rect;
     rect.w = randomInt(64, 128);
@@ -32,45 +37,47 @@
     r = randomInt(50, 255);
     g = randomInt(50, 255);
     b = randomInt(50, 255);
-    SDL_SetRenderDrawColor(r, g, b, 255);
+    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
 
     /*  Fill the rectangle in the color */
-    SDL_RenderFillRect(&rect);
+    SDL_RenderFillRect(renderer, &rect);
 
     /* update screen */
-    SDL_RenderPresent();
-
+    SDL_RenderPresent(renderer);
 }
 
 int
 main(int argc, char *argv[])
 {
 
-    SDL_WindowID windowID;
+    SDL_Window *window;
+    SDL_Renderer *renderer;
     int done;
     SDL_Event event;
 
     /* initialize SDL */
     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
         printf("Could not initialize SDL\n");
+        return 1;
     }
 
     /* seed random number generator */
     srand(time(NULL));
 
     /* create window and renderer */
-    windowID =
+    window =
         SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
                          SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
-    if (windowID == 0) {
+    if (!window) {
         printf("Could not initialize Window\n");
-    }
-    if (SDL_CreateRenderer(windowID, -1, 0) != 0) {
-        printf("Could not create renderer\n");
+        return 1;
     }
 
-    /* Fill screen with black */
-    SDL_RenderClear();
+    renderer = SDL_CreateRenderer(window, -1, 0);
+    if (renderer) {
+        printf("Could not create renderer\n");
+        return 1;
+    }
 
     /* Enter render loop, waiting for user to quit */
     done = 0;
@@ -80,7 +87,7 @@
                 done = 1;
             }
         }
-        render();
+        render(renderer);
         SDL_Delay(1);
     }
 
--- a/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/main.c	Sun Feb 20 14:59:36 2011 -0800
+++ b/Xcode/TemplatesForXcodeSnowLeopard/SDL OpenGL Application/main.c	Sun Feb 20 19:15:00 2011 -0800
@@ -75,12 +75,12 @@
     // Create window
     gScreen = SDL_SetVideoMode (640, 480, 0, flags);
     if (gScreen == NULL) {
-		
+        
         fprintf (stderr, "Couldn't set 640x480 OpenGL video mode: %s\n",
                  SDL_GetError());
-		SDL_Quit();
-		exit(2);
-	}
+        SDL_Quit();
+        exit(2);
+    }
 }
 
 static void initGL ()
@@ -100,29 +100,29 @@
     SDL_Event event;
     int done = 0;
     int fps = 24;
-	int delay = 1000/fps;
+    int delay = 1000/fps;
     int thenTicks = -1;
     int nowTicks;
     
     while ( !done ) {
 
-		/* Check for events */
-		while ( SDL_PollEvent (&event) ) {
-			switch (event.type) {
+        /* Check for events */
+        while ( SDL_PollEvent (&event) ) {
+            switch (event.type) {
 
-				case SDL_MOUSEMOTION:
-					break;
-				case SDL_MOUSEBUTTONDOWN:
-					break;
-				case SDL_KEYDOWN:
-					/* Any keypress quits the app... */
-				case SDL_QUIT:
-					done = 1;
-					break;
-				default:
-					break;
-			}
-		}
+                case SDL_MOUSEMOTION:
+                    break;
+                case SDL_MOUSEBUTTONDOWN:
+                    break;
+                case SDL_KEYDOWN:
+                    /* Any keypress quits the app... */
+                case SDL_QUIT:
+                    done = 1;
+                    break;
+                default:
+                    break;
+            }
+        }
     
         // Draw at 24 hz
         //     This approach is not normally recommended - it is better to
@@ -144,18 +144,18 @@
         }
 
         SDL_Delay (delay);
-	}
+    }
 }
 
 int main(int argc, char *argv[])
 {
-	// Init SDL video subsystem
-	if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
-		
+    // Init SDL video subsystem
+    if ( SDL_Init (SDL_INIT_VIDEO) < 0 ) {
+        
         fprintf(stderr, "Couldn't initialize SDL: %s\n",
-			SDL_GetError());
-		exit(1);
-	}
+            SDL_GetError());
+        exit(1);
+    }
 
     // Set GL context attributes
     initAttributes ();
@@ -173,7 +173,7 @@
     mainLoop ();
     
     // Cleanup
-	SDL_Quit();
-	
+    SDL_Quit();
+
     return 0;
 }