iOS: Restored older version of rectangles demo.
authorPhilipp Wiesemann <philipp.wiesemann@arcor.de>
Sun, 27 Mar 2016 22:25:13 +0200
changeset 10125d56e06ce0858
parent 10124 122b354111ac
child 10126 21cbbf2beb93
iOS: Restored older version of rectangles demo.

The demo did not draw rectangles like described in the demo README.
Xcode-iOS/Demos/src/rectangles.c
     1.1 --- a/Xcode-iOS/Demos/src/rectangles.c	Sun Mar 27 22:24:10 2016 +0200
     1.2 +++ b/Xcode-iOS/Demos/src/rectangles.c	Sun Mar 27 22:25:13 2016 +0200
     1.3 @@ -37,45 +37,50 @@
     1.4  int
     1.5  main(int argc, char *argv[])
     1.6  {
     1.7 -    if (SDL_Init(SDL_INIT_VIDEO/* | SDL_INIT_AUDIO */) < 0)
     1.8 -    {
     1.9 -        printf("Unable to initialize SDL");
    1.10 +
    1.11 +    SDL_Window *window;
    1.12 +    SDL_Renderer *renderer;
    1.13 +    int done;
    1.14 +    SDL_Event event;
    1.15 +
    1.16 +    /* initialize SDL */
    1.17 +    if (SDL_Init(SDL_INIT_VIDEO) < 0) {
    1.18 +        fatalError("Could not initialize SDL");
    1.19      }
    1.20 -    
    1.21 -    SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
    1.22 -    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
    1.23 -    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    1.24 -    
    1.25 -    int landscape = 1;
    1.26 -    int modes = SDL_GetNumDisplayModes(0);
    1.27 -    int sx = 0, sy = 0;
    1.28 -    for (int i = 0; i < modes; i++)
    1.29 -    {
    1.30 -        SDL_DisplayMode mode;
    1.31 -        SDL_GetDisplayMode(0, i, &mode);
    1.32 -        if (landscape ? mode.w > sx : mode.h > sy)
    1.33 -        {
    1.34 -            sx = mode.w;
    1.35 -            sy = mode.h;
    1.36 +
    1.37 +    /* seed random number generator */
    1.38 +    srand(time(NULL));
    1.39 +
    1.40 +    /* create window and renderer */
    1.41 +    window =
    1.42 +        SDL_CreateWindow(NULL, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
    1.43 +                         SDL_WINDOW_SHOWN);
    1.44 +    if (window == 0) {
    1.45 +        fatalError("Could not initialize Window");
    1.46 +    }
    1.47 +    renderer = SDL_CreateRenderer(window, -1, 0);
    1.48 +    if (!renderer) {
    1.49 +        fatalError("Could not create renderer");
    1.50 +    }
    1.51 +
    1.52 +    /* Fill screen with black */
    1.53 +    SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
    1.54 +    SDL_RenderClear(renderer);
    1.55 +
    1.56 +    /* Enter render loop, waiting for user to quit */
    1.57 +    done = 0;
    1.58 +    while (!done) {
    1.59 +        while (SDL_PollEvent(&event)) {
    1.60 +            if (event.type == SDL_QUIT) {
    1.61 +                done = 1;
    1.62 +            }
    1.63          }
    1.64 +        render(renderer);
    1.65 +        SDL_Delay(1);
    1.66      }
    1.67 -    
    1.68 -    printf("picked: %d %d\n", sx, sy);
    1.69 -    
    1.70 -    SDL_Window *_sdl_window = NULL;
    1.71 -    SDL_GLContext _sdl_context = NULL;
    1.72 -    
    1.73 -    _sdl_window = SDL_CreateWindow("fred",
    1.74 -                                   0, 0,
    1.75 -                                   sx, sy,
    1.76 -                                   SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
    1.77 -    
    1.78 -    SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeLeft LandscapeRight");
    1.79 -    
    1.80 -    int ax = 0, ay = 0;
    1.81 -    SDL_GetWindowSize(_sdl_window, &ax, &ay);
    1.82 -    
    1.83 -    printf("given: %d %d\n", ax, ay);
    1.84 +
    1.85 +    /* shutdown SDL */
    1.86 +    SDL_Quit();
    1.87  
    1.88      return 0;
    1.89  }