cscg22-gearboy

CSCG 2022 Challenge 'Gearboy'
git clone https://git.sinitax.com/sinitax/cscg22-gearboy
Log | Files | Refs | sfeed.txt

rectangles.c (1923B)


      1/*
      2 *  rectangles.c
      3 *  written by Holmes Futrell
      4 *  use however you want
      5*/
      6
      7#include "SDL.h"
      8#include <time.h>
      9#include "common.h"
     10
     11void
     12render(SDL_Renderer *renderer)
     13{
     14
     15    Uint8 r, g, b;
     16    /*  Come up with a random rectangle */
     17    SDL_Rect rect;
     18    rect.w = randomInt(64, 128);
     19    rect.h = randomInt(64, 128);
     20    rect.x = randomInt(0, SCREEN_WIDTH);
     21    rect.y = randomInt(0, SCREEN_HEIGHT);
     22
     23    /* Come up with a random color */
     24    r = randomInt(50, 255);
     25    g = randomInt(50, 255);
     26    b = randomInt(50, 255);
     27
     28    /*  Fill the rectangle in the color */
     29    SDL_SetRenderDrawColor(renderer, r, g, b, 255);
     30    SDL_RenderFillRect(renderer, &rect);
     31
     32    /* update screen */
     33    SDL_RenderPresent(renderer);
     34
     35}
     36
     37int
     38main(int argc, char *argv[])
     39{
     40    if (SDL_Init(SDL_INIT_VIDEO/* | SDL_INIT_AUDIO */) < 0)
     41    {
     42        printf("Unable to initialize SDL");
     43    }
     44    
     45    SDL_LogSetAllPriority(SDL_LOG_PRIORITY_WARN);
     46    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
     47    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
     48    
     49    int landscape = 1;
     50    int modes = SDL_GetNumDisplayModes(0);
     51    int sx = 0, sy = 0;
     52    for (int i = 0; i < modes; i++)
     53    {
     54        SDL_DisplayMode mode;
     55        SDL_GetDisplayMode(0, i, &mode);
     56        if (landscape ? mode.w > sx : mode.h > sy)
     57        {
     58            sx = mode.w;
     59            sy = mode.h;
     60        }
     61    }
     62    
     63    printf("picked: %d %d\n", sx, sy);
     64    
     65    SDL_Window *_sdl_window = NULL;
     66    SDL_GLContext _sdl_context = NULL;
     67    
     68    _sdl_window = SDL_CreateWindow("fred",
     69                                   0, 0,
     70                                   sx, sy,
     71                                   SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
     72    
     73    SDL_SetHint("SDL_HINT_ORIENTATIONS", "LandscapeLeft LandscapeRight");
     74    
     75    int ax = 0, ay = 0;
     76    SDL_GetWindowSize(_sdl_window, &ax, &ay);
     77    
     78    printf("given: %d %d\n", ax, ay);
     79
     80    return 0;
     81}