전체 파일 경로를 사용하지 않고 파일에서 이미지를로드하려고합니다. C#에서와 마찬가지로, 그러나 이미지를로드 할 때 콘솔에서 내 sdl 오류가 발생합니다.전체 파일 경로를 사용하지 않고 sdl_loadbmp 파일에서
bool loadMedia()
{
//Loading success flag
bool success = true;
//Load splash image
gHelloWorld = SDL_LoadBMP("SDL2_tutorials02/hello_world.bmp");
if(gHelloWorld == NULL)
{
printf("Unable to load image %s! SDL Error: %s\n", "SDL2_tutorials02/hello_world.bmp", SDL_GetError());
success = false;
}
return success;
}
이 자신에게 SDL 및 C++ InternetAussie에 대한
편집에 대한 자세한 내용을 가르치려고, 나는 온라인 튜토리얼에서 배운 내 원래 코드의 일부이며,이 내가 무슨 생각에서 내 전체 소스 코드입니다
//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>
//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;
//Starts up SDL and creates window
bool init();
//Loads media
bool loadMedia();
//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;
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;
}
bool loadMedia()
{
//Loading success flag
bool success = true;
//Load splash image
gHelloWorld = SDL_LoadBMP("SDL2_tutorials02/hello_world.bmp");
if(gHelloWorld == NULL)
{
printf("Unable to load image %s! SDL Error: %s\n", "SDL2_tutorials02/hello_world.bmp", SDL_GetError());
success = false;
}
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[])
{
//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(gHelloWorld, NULL, gScreenSurface, NULL);
//Update the surface
SDL_UpdateWindowSurface(gWindow);
//Wait two seconds
SDL_Delay(2000);
}
}
//system halt for testing
system("pause");
//Free resources and close SDL
close();
return 0;
}
하고 도움이된다면 나는 게으른 푸 '프로덕션에서 튜토리얼 1의 지시에 따라 : 튜토리얼에서 배운 것은 다음과 같습니다. 내가 적절하게 추가했으면하는 하이퍼 링크는 Visual Studio 2010을 사용하는 Windows 컴퓨터에서 sdl을 설치하는 방법에 대한 단계를 클릭 한 후 설치 부분에 불과합니다. 콘솔을 사용하여 오류가있는 출력 소스로 시스템 32 설치를 진행했습니다.
실행 파일은 어떻게 실행하고 있습니까? 자체적으로 실행하면 상대 경로는 일반적으로 포함 디렉토리에서 가져옵니다. 그렇지 않으면 작업 디렉토리가 아무 것도 될 수 없습니다. – InternetAussie
'getcwd()'와'chdir()'과 상대 경로를 일반적으로 읽는다. –
이것이 작동하는지 확인하십시오 : 실행 파일을 빌드하십시오; 'SDL2_tutorials02' 디렉토리를 실행 파일과 같은 디렉토리에 두십시오; Explorer에서 실행 파일을 두 번 클릭하십시오 (IDE에서 실행하는 대신 작업 디렉토리가 변경됨). 잘하면 도움이됩니다. – InternetAussie