Fixed the fireworks demo
authorSam Lantinga <slouken@libsdl.org>
Sun, 20 Feb 2011 14:59:36 -0800
changeset 5365db3c6ebcc954
parent 5364 fec676157db5
child 5366 d032ec40e7c1
Fixed the fireworks demo
Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj
Xcode-iPhoneOS/Demos/src/fireworks.c
     1.1 --- a/Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj	Sun Feb 20 14:22:27 2011 -0800
     1.2 +++ b/Xcode-iPhoneOS/Demos/DemosiPhoneOS.xcodeproj/project.pbxproj	Sun Feb 20 14:59:36 2011 -0800
     1.3 @@ -1059,11 +1059,7 @@
     1.4  				GCC_PREFIX_HEADER = "";
     1.5  				INFOPLIST_FILE = Info.plist;
     1.6  				INSTALL_PATH = "$(HOME)/Applications";
     1.7 -				LIBRARY_SEARCH_PATHS = (
     1.8 -					"$(inherited)",
     1.9 -					"\\\"$(SRCROOT)\\\"",
    1.10 -					"\"$(SRCROOT)/../SDL/build/Debug-iphoneos\"",
    1.11 -				);
    1.12 +				LIBRARY_SEARCH_PATHS = "$(inherited)";
    1.13  				PREBINDING = NO;
    1.14  				PRODUCT_NAME = Fireworks;
    1.15  				SDKROOT = iphoneos;
    1.16 @@ -1082,11 +1078,7 @@
    1.17  				GCC_PREFIX_HEADER = "";
    1.18  				INFOPLIST_FILE = Info.plist;
    1.19  				INSTALL_PATH = "$(HOME)/Applications";
    1.20 -				LIBRARY_SEARCH_PATHS = (
    1.21 -					"$(inherited)",
    1.22 -					"\\\"$(SRCROOT)\\\"",
    1.23 -					"\"$(SRCROOT)/../SDL/build/Debug-iphoneos\"",
    1.24 -				);
    1.25 +				LIBRARY_SEARCH_PATHS = "$(inherited)";
    1.26  				PREBINDING = NO;
    1.27  				PRODUCT_NAME = Fireworks;
    1.28  				SDKROOT = iphoneos;
     2.1 --- a/Xcode-iPhoneOS/Demos/src/fireworks.c	Sun Feb 20 14:22:27 2011 -0800
     2.2 +++ b/Xcode-iPhoneOS/Demos/src/fireworks.c	Sun Feb 20 14:59:36 2011 -0800
     2.3 @@ -45,6 +45,7 @@
     2.4  } particles[MAX_PARTICLES];     /* this array holds all our particles */
     2.5  
     2.6  static int num_active_particles;        /* how many members of the particle array are actually being drawn / animated? */
     2.7 +static int screen_w, screen_h;
     2.8  
     2.9  /* function declarations */
    2.10  void spawnTrailFromEmitter(struct particle *emitter);
    2.11 @@ -82,11 +83,11 @@
    2.12          /* is the particle actually active, or is it marked for deletion? */
    2.13          if (curr->isActive) {
    2.14              /* is the particle off the screen? */
    2.15 -            if (curr->y > SCREEN_HEIGHT)
    2.16 +            if (curr->y > screen_h)
    2.17                  curr->isActive = 0;
    2.18              else if (curr->y < 0)
    2.19                  curr->isActive = 0;
    2.20 -            if (curr->x > SCREEN_WIDTH)
    2.21 +            if (curr->x > screen_w)
    2.22                  curr->isActive = 0;
    2.23              else if (curr->x < 0)
    2.24                  curr->isActive = 0;
    2.25 @@ -290,12 +291,12 @@
    2.26          break;
    2.27      }
    2.28      p->color[3] = 255;
    2.29 -    /* set position to (x, SCREEN_HEIGHT) */
    2.30 +    /* set position to (x, screen_h) */
    2.31      p->x = x;
    2.32 -    p->y = SCREEN_HEIGHT;
    2.33 +    p->y = screen_h;
    2.34      /* set velocity so that terminal point is (x,y) */
    2.35      p->xvel = 0;
    2.36 -    p->yvel = -sqrt(2 * ACCEL * (SCREEN_HEIGHT - y));
    2.37 +    p->yvel = -sqrt(2 * ACCEL * (screen_h - y));
    2.38      /* set other attributes */
    2.39      p->size = 10;
    2.40      p->type = emitter;
    2.41 @@ -361,6 +362,8 @@
    2.42  main(int argc, char *argv[])
    2.43  {
    2.44      SDL_Window *window;         /* main window */
    2.45 +    SDL_GLContext context;
    2.46 +    int w, h;
    2.47      Uint32 startFrame;          /* time frame began to process */
    2.48      Uint32 endFrame;            /* time frame ended processing */
    2.49      Uint32 delay;               /* time to pause waiting to draw next frame */
    2.50 @@ -388,7 +391,7 @@
    2.51      window = SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
    2.52                                  SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN |
    2.53                                  SDL_WINDOW_BORDERLESS);
    2.54 -    SDL_CreateRenderer(window, 0, 0);
    2.55 +    context = SDL_GL_CreateContext(window);
    2.56  
    2.57      /* load the particle texture */
    2.58      initializeTexture();
    2.59 @@ -400,6 +403,22 @@
    2.60          SDL_GL_ExtensionSupported("GL_OES_point_size_array");
    2.61  
    2.62      /* set up some OpenGL state */
    2.63 +    glDisable(GL_DEPTH_TEST);
    2.64 +    glDisable(GL_CULL_FACE);
    2.65 +
    2.66 +    glMatrixMode(GL_MODELVIEW);
    2.67 +    glLoadIdentity();
    2.68 +
    2.69 +    SDL_GetWindowSize(window, &screen_w, &screen_h);
    2.70 +    glViewport(0, 0, screen_w, screen_h);
    2.71 +
    2.72 +    glMatrixMode(GL_PROJECTION);
    2.73 +    glLoadIdentity();
    2.74 +    glOrthof((GLfloat) 0,
    2.75 +             (GLfloat) screen_w,
    2.76 +             (GLfloat) screen_h,
    2.77 +             (GLfloat) 0, 0.0, 1.0);
    2.78 +
    2.79      glEnable(GL_TEXTURE_2D);
    2.80      glEnable(GL_BLEND);
    2.81      glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    2.82 @@ -434,7 +453,7 @@
    2.83          }
    2.84          stepParticles();
    2.85          drawParticles();
    2.86 -		SDL_GL_SwapWindow(window);
    2.87 +        SDL_GL_SwapWindow(window);
    2.88          endFrame = SDL_GetTicks();
    2.89  
    2.90          /* figure out how much time we have left, and then sleep */