My code doesn't display anything. All I get is a window with no image.
#include <iostream>
#include <stdio.h>
#include <SDL2/SDL.h>
using namespace std;
SDL_Window *gWindow=NULL;
SDL_Surface *gScreenSurface=NULL;
SDL_Surface *gHelloWorld=NULL;
const int SCREEN_WIDTH=640, SCREEN_HEIGHT=480;
bool init(){
bool success = true;
if(SDL_Init (SDL_INIT_VIDEO) < 0 ) {
printf("SDL could not initialize! SDL_Error : %s \n", SDL_GetError() );
success=false;
}
else{
gWindow = SDL_CreateWindow ( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL ){
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
success=false;
}
else {
gScreenSurface = SDL_GetWindowSurface (gWindow);
}
}
return success;
}
bool loadMedia(){
bool success=true;
gHelloWorld = SDL_LoadBMP ( "hello_world.bmp" );
if (gHelloWorld == NULL ){
printf( "Unable to load image %s! SDL Error: %s\n", "hello_world.bmp", SDL_GetError() );
success=false;
}
return success;
}
void close(){
SDL_FreeSurface( gHelloWorld );
gHelloWorld=NULL;
SDL_DestroyWindow( gWindow );
gWindow=NULL;
SDL_Quit();
}
int main(int argc, char* args[]){
if(!init()){
printf( "failed to initialize!\n" );
}
else {
if( !loadMedia() ) {
printf ("failed to laod media! \n");
}
else {
SDL_BlitSurface( gHelloWorld, NULL, SDL_GetWindowSurface(gWindow), NULL );
SDL_UpdateWindowSurface ( gWindow );
SDL_Delay (2000);
}
}
close();
I expect it to show me a bmp image which is in the path specified here in the loadBMP() function but all I get is an empty transparent window.
I am using KDE Konsole, if that has to do something with this.
KDE eh? Plasma composites by default; try disabling compositing or add a proper event-handling loop so your process has a chance to handle repaint events.
Related
This is my code:
#include <SDL2/SDL.h>
#include <stdio.h>
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
int main(int argc, char* args[])
{
SDL_Window* window = NULL;
SDL_Surface* screenSurface = NULL;
if (SDL_Init(SDL_INIT_VIDEO ) < 0 )
{
printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
}
else
{
window = SDL_CreateWindow("Title", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if (window == NULL)
{
printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
}
else
{
screenSurface = SDL_GetWindowSurface(window);
SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF ));
SDL_UpdateWindowSurface(window);
SDL_Event e; bool quit = false; while( quit == false ){ while( SDL_PollEvent( &e ) ){ if( e.type == SDL_QUIT ) quit = true; } }
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
}
}
The program builds all fine no errors no warnings no nothing. But when it comes to running it. My window pc says This app can't run on your pc. Does anyone know how to fix this?
The build system i am using is gcc mingw.
COMMAND:
g++ Test.cpp -I"include" -L"lib" -Wall -lmingw32 -lSDL2main -lSDL2 -mwindows -o Test.exe
I'm using SDL2, following LazyFoo's tutorial. I've reached the loading TTF Fonts part and I've seemingly followed everything he did, except adding two extra TTF_Font and SDL_Renderer parameters
bool LTexture::loadFromRenderedText(TTF_Font *&gFont, std::string textureText, SDL_Color textColor, SDL_Renderer *&gRenderer)
{
//Get rid of preexisting texture
free();
//Render text surface
SDL_Surface* textSurface = TTF_RenderText_Solid( gFont, textureText.c_str(), textColor );
if( textSurface == NULL )
{
printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
}
else
{
//Create texture from surface pixels
mTexture = SDL_CreateTextureFromSurface( gRenderer, textSurface );
if( mTexture == NULL )
{
printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
}
else
{
//Get image dimensions
mWidth = textSurface->w;
mHeight = textSurface->h;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
return 1;
}
This is the function, and this is where it's called:
gFont = TTF_OpenFont( "Font/comicSans.ttf", 28 );
if( gFont == NULL )
{
printf( "Failed to load COMIC_SANS font! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
else
{
//Render text
SDL_Color textColor = { 0, 0, 0 };
if( !gTextTexture.loadFromRenderedText(gFont, "Hello I am hot", textColor, gRenderer));
{
printf( "Failed to render text texture!\n" );
success = false;
}
}
if succes is false, the program prints "Failed loading media"
This is the output I get from running the program, notice how there are no actual SDL or TTF errors, only the one that appears when loadFromRendereredText returns false, which it doesn't, as I have set it to return 1:
Failed to render text texture!
Failed to load media!
The only actual difference from my files and LazyFoo's files are that my LTexture class is in a separate file than main, and that's why for some reason I couldn't use gFont and gRenderer (global variables)
Any idea what might be causing this?
FULL CODE:
main.cpp:
/*This source code copyrighted by Lazy Foo' Productions (2004-2019)
and may not be redistributed without written permission.*/
//Using SDL and standard IO
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <stdio.h>
#include <string>
#include "LTexture.h"
bool init();
bool loadMedia();
void close();
//The window we'll be rendering to
SDL_Window* gWindow = NULL;
SDL_Renderer* gRenderer = NULL;
//The surface contained by the window
SDL_Surface* gScreenSurface = NULL;
TTF_Font *gFont = NULL;
LTexture gTextTexture;
//Screen dimension constants
const int SCREEN_WIDTH = 500;
const int SCREEN_HEIGHT = 500;
int main(int argc, char* args[])
{
//Start up SDL and create window
if( !init() )
{
printf( "Failed to initialize!\n" );
}
else
{
//Load media
if( !loadMedia() )
{
printf( "Failed to load media!\n" );
}
else
{
//Main loop flag
bool quit = false;
//Event handler
SDL_Event event;
//While application is running
while( !quit )
{
//Handle events on queue
while( SDL_PollEvent( &event ) != 0 )
{
//User requests quit
if( event.type == SDL_QUIT )
{
quit = true;
}
}
//Clear screen
SDL_SetRenderDrawColor(gRenderer, 0xFF, 0xFF, 0xFF, 0xFF);
SDL_RenderClear( gRenderer );
gTextTexture.render(gRenderer, (SCREEN_WIDTH - gTextTexture.getWidth()) / 2, (SCREEN_HEIGHT - gTextTexture.getHeight()) / 2);
//Update screen
SDL_RenderPresent( gRenderer );
}
}
}
//Free resources and close SDL
close();
return 0;
}
bool init()
{
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create window
gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
if( gWindow == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Initialize renderer color
SDL_SetRenderDrawColor( gRenderer, 0xFF, 0xFF, 0xFF, 0xFF );
//Initialize PNG loading
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;
}
//Initialize SDL_ttf
if( TTF_Init() == -1 )
{
printf( "SDL_ttf could not initialize! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
}
}
}
return success;
}
bool loadMedia()
{
//Loading success flag
bool success = true;
//Open the font
gFont = TTF_OpenFont( "Font/comicSans.ttf", 28 );
if( gFont == NULL )
{
printf( "Failed to load COMIC_SANS font! SDL_ttf Error: %s\n", TTF_GetError() );
success = false;
}
else
{
//Render text
SDL_Color textColor = { 0, 0, 0 };
if( !gTextTexture.loadFromRenderedText(gFont, "Hello I am hot", textColor, gRenderer));
{
printf( "Failed to render text texture!\n" );
success = false;
}
}
return success;
}
void close()
{
//Free loaded images
gTextTexture.free();
//Destroy window
SDL_DestroyRenderer( gRenderer );
SDL_DestroyWindow( gWindow );
TTF_CloseFont(gFont);
gWindow = NULL;
gRenderer = NULL;
gFont = NULL;
//Quit SDL subsystems
TTF_Quit();
IMG_Quit();
SDL_Quit();
}
LTexture.h:
#ifndef LTEXTURE_INCLUDED
#define LTEXTURE_INCLUDED
#include <SDL.h>
#include <SDL_image.h>
#include <SDL_ttf.h>
#include <stdio.h>
#include <string>
//Texture wrapper class
class LTexture
{
public:
//Initializes variables
LTexture();
//Deallocates memory
~LTexture();
//Loads image at specified path
bool loadFromFile( std::string path, SDL_Renderer *&gRenderer);
//Loads image from string text
bool loadFromRenderedText(TTF_Font *&gFont, std::string textureText, SDL_Color textColor, SDL_Renderer *&gRenderer);
//Deallocates texture
void free();
//Set color modulation
void setColor( Uint8 red, Uint8 green, Uint8 blue );
//Set blending
void setBlendMode( SDL_BlendMode blending );
//Set alpha modulation
void setAlpha( Uint8 alpha );
//Renders texture at given point
void render(SDL_Renderer *&gRenderer, int x, int y, SDL_Rect *clip = NULL, double angle = 0.0, SDL_Point* center = NULL, SDL_RendererFlip flip = SDL_FLIP_NONE );
//Gets image dimensions
int getWidth(){return mWidth;}
int getHeight(){return mHeight;}
private:
//The actual hardware texture
SDL_Texture* mTexture;
//Image dimensions
int mWidth;
int mHeight;
};
#endif // LTEXTURE_INCLUDED
LTexture.cpp:
#include "LTexture.h"
LTexture::LTexture()
{
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
LTexture::~LTexture()
{
//Deallocate resources
free();
}
bool LTexture::loadFromFile(std::string path, SDL_Renderer *&gRenderer)
{
free();
SDL_Texture* newTexture = NULL;
SDL_Surface *loadedSurface = IMG_Load(path.c_str());
if(loadedSurface == NULL)
{
printf("Unable to load image %s! SDL_image Error: %s\n", path.c_str(), IMG_GetError());
}
else
{
//Color key image
SDL_SetColorKey( loadedSurface, SDL_TRUE, SDL_MapRGB( loadedSurface->format, 0, 0xFF, 0xFF ) );
newTexture = SDL_CreateTextureFromSurface(gRenderer, loadedSurface);
if(newTexture == NULL)
{
printf( "Unable to create texture from %s! SDL Error: %s\n", path.c_str(), SDL_GetError() );
}
else
{
mWidth = loadedSurface->w;
mHeight = loadedSurface->h;
}
SDL_FreeSurface( loadedSurface );
}
mTexture = newTexture;
return mTexture != NULL;
}
bool LTexture::loadFromRenderedText(TTF_Font *&gFont, std::string textureText, SDL_Color textColor, SDL_Renderer *&gRenderer)
{
//Get rid of preexisting texture
free();
//Render text surface
SDL_Surface* textSurface = TTF_RenderText_Solid( gFont, textureText.c_str(), textColor );
if( textSurface == NULL )
{
printf( "Unable to render text surface! SDL_ttf Error: %s\n", TTF_GetError() );
}
else
{
//Create texture from surface pixels
mTexture = SDL_CreateTextureFromSurface( gRenderer, textSurface );
if( mTexture == NULL )
{
printf( "Unable to create texture from rendered text! SDL Error: %s\n", SDL_GetError() );
}
else
{
//Get image dimensions
mWidth = textSurface->w;
mHeight = textSurface->h;
}
//Get rid of old surface
SDL_FreeSurface( textSurface );
}
return 1;
}
void LTexture::free()
{
if(mTexture != NULL){
SDL_DestroyTexture(mTexture);
mTexture = NULL;
mWidth = 0;
mHeight = 0;
}
}
void LTexture::setColor( Uint8 red, Uint8 green, Uint8 blue )
{
//Modulate texture
SDL_SetTextureColorMod( mTexture, red, green, blue );
}
void LTexture::setBlendMode( SDL_BlendMode blending )
{
//Set blending function
SDL_SetTextureBlendMode( mTexture, blending );
}
void LTexture::setAlpha( Uint8 alpha )
{
//Modulate texture alpha
SDL_SetTextureAlphaMod( mTexture, alpha );
}
void LTexture::render(SDL_Renderer *&gRenderer, int x, int y, SDL_Rect *clip, double angle, SDL_Point *center, SDL_RendererFlip flip)
{
//Set rendering space and render to screen
SDL_Rect renderQuad = { x, y, mWidth, mHeight };
if( clip != NULL )
{
renderQuad.w = clip->w;
renderQuad.h = clip->h;
}
SDL_RenderCopyEx( gRenderer, mTexture, clip, &renderQuad, angle, center, flip );
}
The problem is the semicolon at the end of your if statement.
if( !gTextTexture.loadFromRenderedText(gFont, "Hello I am hot", textColor, gRenderer));
{
printf( "Failed to render text texture!\n" );
success = false;
}
That semicolon will create an empty statement for that if block, it will cause your
{
printf( "Failed to render text texture!\n" );
success = false;
}
to always execute. It's like this,
if(.....)
;
{
....
}
Unfortunately I do not get a picture but only a white screen. I am currently learning c ++ and sdl.
error message:
SDL_image Error: Couldn't open test.jpg
I am using Visual Studio on a Windows 10 computer.
#include <SDL.h>
#include <SDL_image.h>
#include <iostream>
#include <windows.h>
#include <string>
using namespace std;;
string ExePath() {
char buffer[MAX_PATH];
GetModuleFileName(NULL, buffer, MAX_PATH);
string::size_type pos = string(buffer).find_last_of("\\/");
return string(buffer).substr(0, pos);
}
int main(int argc, char* args[]) {
cout << "my directory is " << ExePath() << "\n";
if (SDL_Init(SDL_INIT_EVERYTHING) != 0) {
std::cout << "SDL load fail" << std::endl;
return -1;
}
SDL_Window* window = SDL_CreateWindow("Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 500, 500, SDL_WINDOW_SHOWN);
if (window == NULL) {
std::cout << "Window load fail." << std::endl;
return -1;
}
SDL_Renderer* renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if (renderer == NULL) {
std::cout << "Renderer load fail." << std::endl;
return -1;
}
SDL_Texture* background = IMG_LoadTexture(renderer, "test.jpg");
if (background == NULL) {
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
SDL_Delay(5000);
return -1;
}
SDL_Rect pos;
pos.x = 20;
pos.y = 30;
pos.w = 460;
pos.h = 300;
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, background, NULL, &pos);
SDL_RenderPresent(renderer);
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
atexit(SDL_Quit);
return 0;
}
I have already tried the absolute path. The picture is also in the correct folder. Smaller pictures, jpeg, png. I do not know.
SDL Image is a separate library. You should initialize it befor using it. Something like this:
////...
int imgFlags = IMG_INIT_JPG; // or IMG_INIT_PNG;
// not sure about the imgFlags parameter, read the docs.
if( !( IMG_Init( imgFlags ) & imgFlags ) )
{
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
}
/// the rest is the same...
SDL_Texture* background = IMG_LoadTexture(renderer, "test.jpg");
if (background == NULL) {
printf("SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError());
SDL_Delay(5000);
return -1;
}
/// ...
Some reference https://discourse.libsdl.org/t/help-with-initializing-sdl-image/23601
EDIT: And for the "one step closer": I think your delay is in the wrong place.
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, background, NULL, &pos);
SDL_RenderPresent(renderer);
SDL_Delay(5000); //////// For example try putting int here
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
atexit(SDL_Quit);
std::cout << "Bye!" << std::endl;
return 0;
The program is supposed take pixel data from a uni dimensional array and display it. The pixel data is supposed to be 1 byte per pixel, which is supposed to result in a gray scale image.
The result is supposed to look like this:
Th problem i run into is that the "SDL_SetPaletteColors" command crashes the program.
What am I doing wrong here?
Here is the code:
#include <SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 100;
const int SCREEN_HEIGHT = 100;
char* pixels;
int icnt,icnt2;
//Starts up SDL and creates window
bool init();
//Frees media and shuts down SDL
void close();
//The window we'll be rendering to
SDL_Window* gWindow = NULL;
//The surface contained by the window
SDL_Surface* gScreenSurface = NULL;
//The image we will load and show on the screen
//SDL_Surface* gHelloWorld = NULL;
SDL_Surface* gHelloWorld = NULL;
bool init()
{
//Initialization flag
bool success = true;
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Create window
gWindow = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
if( gWindow == NULL )
{
printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
success = false;
}
else
{
//Get window surface
gScreenSurface = SDL_GetWindowSurface( gWindow );
}
}
return success;
}
void close()
{
//Deallocate surface
SDL_FreeSurface( gHelloWorld );
gHelloWorld = NULL;
//Destroy window
SDL_DestroyWindow( gWindow );
gWindow = NULL;
//Quit SDL subsystems
SDL_Quit();
}
int main( int argc, char* args[] )
{
pixels = new char[10000]; //pixel array
icnt2=0;
SDL_Color colors[256];
for(icnt=0;icnt<10000;icnt++) //gradient test image generator
{
pixels[icnt]=(char)icnt2;
icnt2++;
if(icnt2 == 99){icnt2 =0;}
}
//Start up SDL and create window
if( !init() )
{
printf( "Failed to initialize!\n" );
}
else
{
gHelloWorld = SDL_CreateRGBSurfaceFrom((void*)pixels,
100,
100,
8,
100,
0x000000FF,
0x0000FF00,
0x00FF0000,
0);
for(icnt = 0; icnt < 255; icnt++)
{
colors[icnt].r = colors[icnt].g = colors[icnt].b = icnt;
}
//program crashes here ------------------
SDL_SetPaletteColors(gHelloWorld->format->palette, colors, 0, 255); //program crashes here
//-----------------------------------------
//Apply the image
SDL_BlitSurface( gHelloWorld, NULL, gScreenSurface, NULL );
//Update the surface
SDL_UpdateWindowSurface( gWindow );
//Wait two seconds
SDL_Delay( 2000 );
//}
}
//Free resources and close SDL
close();
return 0;
}
I'm getting a segmentation Fault and I've tracked it to my surface, which is NULL (but the Check in place doesn't trigger).
I'm unsure if i'm creating the surface correctly. Is there something I need to add when creating the Surface, Something that I've missed?
bool init()
{
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
return false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
return false;
}
else
{
//Create window
gWindow = SDL_CreateWindow( "kPaint", 575, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
GUI = SDL_CreateWindow( "GUI", 0, SDL_WINDOWPOS_UNDEFINED, 573, 542, SDL_WINDOW_SHOWN );
if( gWindow == NULL || GUI == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
return false;
}
else
{
//Create renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
return false;
}
surface = SDL_GetWindowSurface( gWindow );
GUIsurface = SDL_GetWindowSurface( GUI );
if( surface == NULL )
{
printf( "surface could not be created!" );
return false;
}
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255,255,255));
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) && imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
return false;
}
}
}
}
return true;
}
Thank you NeoAgglos.
I was Creating a renderer before the surfaces.
bool init()
{
//Initialize SDL
if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
{
printf( "SDL could not initialize! SDL Error: %s\n", SDL_GetError() );
return false;
}
else
{
//Set texture filtering to linear
if( !SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" ) )
{
printf( "Warning: Linear texture filtering not enabled!" );
return false;
}
else
{
//Create window
gWindow = SDL_CreateWindow( "kPaint", 575, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
GUI = SDL_CreateWindow( "GUI", 0, SDL_WINDOWPOS_UNDEFINED, 573, 542, SDL_WINDOW_SHOWN );
if( gWindow == NULL || GUI == NULL )
{
printf( "Window could not be created! SDL Error: %s\n", SDL_GetError() );
return false;
}
else
{
surface = SDL_GetWindowSurface( gWindow );
GUIsurface = SDL_GetWindowSurface( GUI );
if( surface == NULL )
{
printf( "surface could not be created!" );
return false;
}
SDL_FillRect(surface, NULL, SDL_MapRGB(surface->format, 255,255,255));
//Create renderer for window
gRenderer = SDL_CreateRenderer( gWindow, -1, SDL_RENDERER_ACCELERATED );
if( gRenderer == NULL )
{
printf( "Renderer could not be created! SDL Error: %s\n", SDL_GetError() );
return false;
}
//Initialize PNG loading
int imgFlags = IMG_INIT_PNG;
if( !( IMG_Init( imgFlags ) && imgFlags ) )
{
printf( "SDL_image could not initialize! SDL_image Error: %s\n", IMG_GetError() );
return false;
}
}
}
}
return true;
}