I’m on ArchLinux (with X11, if that matters), just started learning SDL2. Everything compiles and no errors after running. It’s just that the bmp is not displayed. I literally have no idea why this is not working. This code is derived from Lazy Foo’s SDL2 tutorial. This is my code (c++):
#include <SDL2/SDL.h> #include <iostream> #define SCREEN_WIDTH 640 #define SCREEN_HEIGHT 480 SDL_Window *window; SDL_Surface *surface; SDL_Surface *bmp; void init() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { std::cerr << "SDL could not start! SDL error: " << SDL_GetError() << "\n"; exit(EXIT_FAILURE); } window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN ); if (window == NULL) { std::cerr << "Window could not be created! SDL_Error: " << SDL_GetError() << "\n"; exit(EXIT_FAILURE); } surface = SDL_GetWindowSurface(window); } void loadMedia() { bmp = SDL_LoadBMP("helloworld.bmp"); if (bmp == NULL) { std::cerr << "Unable to load image! SDL_Error: " << SDL_GetError() << "\n"; exit(EXIT_FAILURE); } } void end() { SDL_FreeSurface(bmp); bmp = NULL; SDL_DestroyWindow(window); window = NULL; SDL_Quit(); } int main(void) { init(); loadMedia(); SDL_BlitSurface(bmp, NULL, surface, NULL); SDL_UpdateWindowSurface(window); SDL_Delay(5000); end(); return 0; }