Search code examples
c++sdlrect

SDL rect not appearing


I am trying to get an SDL_Rect to appear on screen with a texture from a bitmap. I run this program and the screen is simply white, with no image.

#include "SDL.h"

int main(int argc, char** args) {

    SDL_Init(SDL_INIT_EVERYTHING);

    SDL_Window* window = NULL;
    
    window = SDL_CreateWindow("window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 1280, 720, SDL_WINDOW_SHOWN);

    SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, 0);

    SDL_Surface* surface = SDL_LoadBMP("car.bmp");

    SDL_Texture* texture = SDL_CreateTextureFromSurface(renderer, surface);

    SDL_Rect rect;

    rect.x = 0;
    rect.y = 0;
    rect.w = 1280;
    rect.h = 720;

    SDL_RenderCopy(renderer, texture, NULL, &rect);

    SDL_Delay(2000);

    SDL_DestroyWindow(window);

    SDL_Quit();

    return 0;

}

Solution

  • I got it working, I simply had to add SDL_RenderPresent().