Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdint>
- #include <cstdlib>
- #include <string>
- #include <iostream>
- #include <SDL.h>
- #include <stdint.h>
- static void draw(SDL_Window *gWindow, SDL_Surface *globalImage,
- SDL_Surface *globalScreenSurface) {
- if (EXIT_SUCCESS != SDL_BlitSurface(globalImage, nullptr, globalScreenSurface, nullptr)) {
- std::cerr << "SDL_BlitSurface() failed. Reason: " << SDL_GetError() << std::endl;
- }
- if (EXIT_SUCCESS != SDL_UpdateWindowSurface(gWindow)) {
- std::cerr << "SDL_UpdateWindowSurface() failed. Reason: " << SDL_GetError()
- << std::endl;
- }
- SDL_Delay(5000);
- }
- static int32_t loadResources(SDL_Surface *globalImage) {
- const std::string filePath = "../resources/hello.bmp";
- globalImage = SDL_LoadBMP(filePath.c_str());
- if (globalImage == nullptr) {
- std::cerr << "SDL_LoadBMP() failed. Reason: " << SDL_GetError() << std::endl;
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- static int32_t init(SDL_Window *gWindow, SDL_Surface *globalScreenSurface,
- SDL_Surface *globalImage) {
- if (EXIT_SUCCESS != SDL_Init(SDL_INIT_VIDEO)) {
- std::cerr << "SDL_Init() failed. Reason: " << SDL_GetError() << std::endl;
- return EXIT_FAILURE;
- }
- const std::string windowName = "First window";
- const int windowHeight = 800;
- const int windowWidth = 600;
- gWindow = SDL_CreateWindow(windowName.c_str(),
- SDL_WINDOWPOS_UNDEFINED,
- SDL_WINDOWPOS_UNDEFINED, windowHeight, windowWidth, SDL_WINDOW_SHOWN);
- if (gWindow == nullptr) {
- std::cerr << "SDL_CreateWindow() failed. Reason: " << SDL_GetError() << std::endl;
- }
- globalScreenSurface = SDL_GetWindowSurface(gWindow);
- if (globalScreenSurface == nullptr) {
- std::cerr << "SDL_GetWindowSurface() failed. Reason: " << SDL_GetError() << std::endl;
- }
- if (EXIT_SUCCESS != loadResources(globalImage)) {
- std::cerr << "loadResources() failed." << std::endl;
- return EXIT_FAILURE;
- }
- return EXIT_SUCCESS;
- }
- void deinit(SDL_Surface *globalImage, SDL_Window *gWindow) {
- SDL_FreeSurface(globalImage);
- if (gWindow != nullptr) {
- SDL_DestroyWindow(gWindow);
- gWindow = nullptr;
- }
- SDL_Quit();
- }
- int32_t main([[maybe_unused]]int32_t argc, [[maybe_unused]]char *argv[]) {
- SDL_Window *gWindow = nullptr;
- SDL_Surface *globalScreenSurface = nullptr;
- SDL_Surface *globalImage = nullptr;
- if (EXIT_SUCCESS != init(gWindow, globalScreenSurface, globalImage)) {
- std::cerr << "init() failed" << std::endl;
- return EXIT_FAILURE;
- }
- draw(gWindow, globalScreenSurface, globalImage);
- deinit(globalImage, gWindow);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement