Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <SDL2/SDL.h>
- #include <SDL2/SDL_image.h>
- #include <SDL2/SDL_ttf.h>
- bool init(const char* name, int height, int width, SDL_Window* &window, SDL_Renderer* &renderer, TTF_Font* &font)
- {
- bool success = true;
- if(SDL_Init(SDL_INIT_VIDEO) < 0)
- {
- printf("SDL could not initialize! SDL Error: %s\n", SDL_GetError());
- success = false;
- }else{
- if(!SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"))
- {
- printf("Warning: Linear texture filtering not enabled!");
- }
- window = SDL_CreateWindow(name, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_SHOWN);
- if(window == nullptr)
- {
- printf("Window could not be created! SDL Error: %s\n", SDL_GetError());
- success = false;
- }else{
- renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
- if(renderer == nullptr)
- {
- printf("Renderer could not be created! SDL Error: %s\n", SDL_GetError());
- success = false;
- }else{
- SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255);
- int imgFlags = IMG_INIT_PNG;
- if(!(IMG_Init(imgFlags) & imgFlags))
- {
- printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
- success = false;
- }
- if (TTF_Init() < 0)
- {
- printf("SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError());
- success = false;
- }else{
- font = TTF_OpenFont("assets/fonts/burbank.ttf", 25);
- if (font == nullptr)
- printf("Font could not be loaded! SDL_ttf Error: %s\n", TTF_GetError());
- success = false;
- }
- }
- }
- }
- return success;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement