1

I'm learning SDL and tried to set up a window with a red background. Followed this code but got the result that is different from an expected one.

#include <stdio.h>
#include "SDL2/SDL.h"

int main(int argc, char const *argv[]) {

    if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        SDL_Log(SDL_GetError());
        return -1;
    }

    SDL_Window* wnd = SDL_CreateWindow("Test", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 300, 300, SDL_WINDOW_OPENGL);
    SDL_Renderer* renderer = SDL_CreateRenderer(wnd, 0, SDL_RENDERER_ACCELERATED);

    SDL_SetRenderDrawColor(renderer, 255, 255, 255 , 255);
    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);

    SDL_Delay(6000);

    SDL_Quit();
    return 0;
}

a Transparent window

Simo
  • 955
  • 8
  • 18
Fensi322
  • 61
  • 5

1 Answers1

1

Process the OS event queue via a SDL_WaitEvent()/SDL_PollEvent()/SDL_PumpEvents() loop instead of a big 'ole main-thread-blocking SDL_Delay().

genpfault
  • 51,148
  • 11
  • 85
  • 139