#include <SDL2/SDL.h> #include <SDL2/SDL_image.h> #include <stdio.h> int main(int argc,…
Jump to turn (6)
- User
#include <SDL2/SDL.h> #include <SDL2/SDL_image.h> #include <stdio.h>
int main(int argc, char* args[]) {
// Initialize SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf(“SDL could not initialize! SDL_Error: %s\n”, SDL_GetError()); return 1; }
// Create window SDL_Window* window = SDL_CreateWindow(“Hello World!”, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN); if (window == NULL) { printf(“Window could not be created! SDL_Error: %s\n”, SDL_GetError()); return 1; }
// Get window surface SDL_Surface* screenSurface = SDL_GetWindowSurface(window);
// Load image const char imagePath = “res/logo.png”; SDL_Surface loadedImage = IMG_Load(imagePath); if (loadedImage == NULL) { printf(“Unable to load image %s! SDL Error: %s\n”, imagePath, SDL_GetError()); return 1; }
// Convert surface to screen format SDL_Surface* imageSurface = SDL_ConvertSurface(loadedImage, screenSurface->format, 0); SDL_FreeSurface(loadedImage); // Free original loaded image if (imageSurface == NULL) { printf(“Unable to convert image surface! SDL Error: %s\n”, SDL_GetError()); return 1; }