0

When I build my program It fails to load the media as it can't find the image, although the image is in the working directory the one which also contains "vcxproj" and my executable. Is that the correct directory or am I not linking it correctly?

Main.cpp

//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;


bool init(); //starts SDL and creates a window

bool loadmedia(); //close function

void close(); //close function



SDL_Window* gWindow = NULL; //The window we will be rendering to

SDL_Surface* gSurface = NULL; //the surface contained by the window

SDL_Surface* gOpening = NULL; //The image we will load to screen

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("Welcome to Tenno", 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
            gSurface = SDL_GetWindowSurface(gWindow);
        }
    }

    return success;
}


bool loadMedia()
{
    //Loading success flag
    bool success = true;

    //Load splash image
    gOpening = SDL_LoadBMP("Project8A\Opening.bmp");
    if (gOpening == NULL)
    {
        printf("Unable to load image %s! SDL Error: %s\n", "Opening.bmp", SDL_GetError());
        success = false;
    }

    return success;
}

void close()
{
    //Deallocate surface
    SDL_FreeSurface(gOpening);
    gOpening = NULL;

    //Destroy window
    SDL_DestroyWindow(gWindow);
    gWindow = NULL;

    //Quit SDL subsystems
    SDL_Quit();
}

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
        {
            //Apply the image
            SDL_BlitSurface(gOpening, NULL, gSurface, NULL);

            //Update the surface
            SDL_UpdateWindowSurface(gWindow);

            //Wait two seconds
            SDL_Delay(2000);
        }
    }

    //Free resources and close SDL
    close();

    return 0;
}
im brett
  • 33
  • 2
  • 12

0 Answers0