I've been trying to have a bitmap image displayed on screen but I can't figure out why it's not displaying it for the life of me. Here's the code:
#include <iostream>
#include <SDL.h>
bool init(SDL_Window *window, SDL_Surface *surface) {
bool success {true};
if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) {
std::cout << "Could not initialize video: " << SDL_GetError() << "\n";
success = false;
}
window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0);
if (window == NULL) {
std::cout << "Could not create window: " << SDL_GetError() << "\n";
success = false;
}
surface = SDL_GetWindowSurface(window);
return success;
}
bool loadMedia(SDL_Surface *image) {
bool success {true};
image = SDL_LoadBMP("C:\\Users\\Admin\\Documents\\Files\\Programming\\C++\\game\\Untitled.bmp");
if (image == NULL) {
std::cout << "Could not load image: " << SDL_GetError() << "\n";
success = false;
}
return success;
}
void close(SDL_Window *window, SDL_Surface *surface, SDL_Surface *image) {
SDL_FreeSurface(surface);
surface = nullptr;
SDL_FreeSurface(image);
image = nullptr;
SDL_DestroyWindow(window);
window = nullptr;
SDL_Quit();
}
int main(int argc, char *argv[]) {
bool quit {false};
SDL_Event event;
SDL_Window *window {nullptr};
SDL_Surface *surface {nullptr};
SDL_Surface *image {nullptr};
if (!init(window, surface)) {
std::cout << "Initialization failed\n";
return 1;
}
if (!loadMedia(image)) {
std::cout << "Loading media failed\n";
return 1;
}
SDL_BlitSurface(image, NULL, surface, NULL);
SDL_UpdateWindowSurface(window);
while (!quit) {
SDL_WaitEvent(&event);
switch (event.type) {
case SDL_QUIT:
quit = true;
break;
default: break;
}
}
close(window, surface, image);
return 0;
}
The file structure is like so:
-game/
-image.bmp
-main.cpp
-main.exe
-Makefile
Makefile is like so:
all : main.cpp
g++ main.cpp -IC:\SDL2\include\SDL2 -LC:\SDL2\lib -w -lmingw32 -lSDL2main -lSDL2 -o main
SDL version 2.0.14 64-bit
mingw 64-bit
Windows 10 64-bit
I don't even know how much more information is necessary.
I have tried using events, not using events, using an absolute path, making the variables global, different file formats, trying to display it using a renderer and a texture, putting everything in main, making the image the same size as the screen, using ImageMagick convert as per the suggestion of an answer on some other thread on here, disabling the console window with the -Wl,-subsystem,windows compiler flag, but nothing I did has worked. Any help here?