SDL is always generating transparent screen. c++

Asked

Viewed 34 times

0

created and compiled a program in SDL, I do not know the reason, but it always returns a transparent screen, when the expected is a white screen.

Resultado do SDL

I’m using the following code:

#include <SDL.h>

int main(int argc, char *argv[]) 
{
    SDL_Window *window;
    SDL_Surface *screenSurface;
    
    SDL_Init(SDL_INIT_VIDEO);
    
    window = SDL_CreateWindow("Tutorial", 100, 50, 320, 480, SDL_WINDOW_SHOWN);
    screenSurface = SDL_GetWindowSurface(window);
    
    SDL_Delay(5000);
    
    SDL_FreeSurface(screenSurface);
    SDL_DestroyWindow(window);
    SDL_Quit();
    
    return 0;

}

And I’m compiling with this command on the cmd:

g++ "C:\Users\DANI\Documents\Learn\SDL\Test.cpp" -o Test.exe -I "C:\MinGW\include\SDL2" -mwindows -lmingw32 -lSDL2main -lSDL2

1 answer

0

To draw in the window we have to use Sdl_renderer. Sdl_renderclear fills the background.

#include <SDL.h>

int main(int argc, char* argv[])
{
    SDL_Window* window;
    SDL_Surface* screenSurface;

    SDL_Init(SDL_INIT_VIDEO);

    window = SDL_CreateWindow("Tutorial", 100, 50, 320, 480, SDL_WINDOW_SHOWN);
    screenSurface = SDL_GetWindowSurface(window);

    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
    SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
    SDL_RenderClear(renderer);
    SDL_RenderPresent(renderer);

    SDL_Delay(5000);

    SDL_FreeSurface(screenSurface);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.