diff Xcode-iPhoneOS/Demos/src/happy.c @ 5211:78db79f5a4e2

Updated the iPhone demos for the new API
author Sam Lantinga <slouken@libsdl.org>
date Sun, 06 Feb 2011 09:02:10 -0800
parents 64ce267332c6
children 25ad4a50d34f
line wrap: on
line diff
--- a/Xcode-iPhoneOS/Demos/src/happy.c	Sun Feb 06 08:57:29 2011 -0800
+++ b/Xcode-iPhoneOS/Demos/src/happy.c	Sun Feb 06 09:02:10 2011 -0800
@@ -36,7 +36,7 @@
 }
 
 void
-render(void)
+render(SDL_Renderer *renderer)
 {
 
     int i;
@@ -58,8 +58,8 @@
     dstRect.h = HAPPY_FACE_SIZE;
 
     /* fill background in with black */
-    SDL_SetRenderDrawColor(0, 0, 0, 255);
-    SDL_RenderFill(NULL);
+    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
+    SDL_RenderClear(renderer);
 
     /*
        loop through all the happy faces:
@@ -86,10 +86,10 @@
         }
         dstRect.x = faces[i].x;
         dstRect.y = faces[i].y;
-        SDL_RenderCopy(texture, &srcRect, &dstRect);
+        SDL_RenderCopy(renderer, texture, &srcRect, &dstRect);
     }
     /* update screen */
-    SDL_RenderPresent();
+    SDL_RenderPresent(renderer);
 
 }
 
@@ -97,13 +97,9 @@
 	loads the happyface graphic into a texture
 */
 void
-initializeTexture()
+initializeTexture(SDL_Renderer *renderer)
 {
     SDL_Surface *bmp_surface;
-    SDL_Surface *bmp_surface_rgba;
-    int format = SDL_PIXELFORMAT_ABGR8888;      /* desired texture format */
-    Uint32 Rmask, Gmask, Bmask, Amask;  /* masks for desired format */
-    int bpp;                    /* bits per pixel for desired format */
     /* load the bmp */
     bmp_surface = SDL_LoadBMP("icon.bmp");
     if (bmp_surface == NULL) {
@@ -112,26 +108,15 @@
     /* set white to transparent on the happyface */
     SDL_SetColorKey(bmp_surface, 1,
                     SDL_MapRGB(bmp_surface->format, 255, 255, 255));
-    SDL_PixelFormatEnumToMasks(format, &bpp, &Rmask, &Gmask, &Bmask, &Amask);
-    /*
-       create a new RGBA surface and blit the bmp to it
-       this is an extra step, but it seems to be necessary
-       is this a bug?
-     */
-    bmp_surface_rgba =
-        SDL_CreateRGBSurface(0, bmp_surface->w, bmp_surface->h, bpp, Rmask,
-                             Gmask, Bmask, Amask);
-    SDL_BlitSurface(bmp_surface, NULL, bmp_surface_rgba, NULL);
 
     /* convert RGBA surface to texture */
-    texture = SDL_CreateTextureFromSurface(format, bmp_surface_rgba);
+    texture = SDL_CreateTextureFromSurface(renderer, bmp_surface);
     if (texture == 0) {
         fatalError("could not create texture");
     }
     SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
 
     /* free up allocated memory */
-    SDL_FreeSurface(bmp_surface_rgba);
     SDL_FreeSurface(bmp_surface);
 }
 
@@ -140,6 +125,7 @@
 {
 
     SDL_Window *window;
+	SDL_Renderer *renderer;
     Uint32 startFrame;
     Uint32 endFrame;
     Uint32 delay;
@@ -153,9 +139,11 @@
                                 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
                                 SDL_WINDOW_BORDERLESS);
 
-    SDL_CreateRenderer(window, -1, 0);
+    //SDL_SetHint(SDL_HINT_RENDER_DRIVER, "opengles2");
+	
+    renderer = SDL_CreateRenderer(window, -1, 0);
 
-    initializeTexture();
+    initializeTexture(renderer);
     initializeHappyFaces();
 
     /* main loop */
@@ -168,7 +156,7 @@
                 done = 1;
             }
         }
-        render();
+        render(renderer);
         endFrame = SDL_GetTicks();
 
         /* figure out how much time we have left, and then sleep */