void MainGame::drawGame() {
glClearDepth(1.0);
// clear colour and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
windowSurface = SDL_GetWindowSurface(_window);
menuImage = SDL_LoadBMP("\Liam C\Documents\Visual Studio 2015\Projects\graphicsPractice\graphicsPractice\ForehalenIntro_Screen.bmp");
if (menuImage == NULL) {
fatalError("Unable to load bitmap, 'ForhalenIntro_Screen.bmp'!");
}
//swap buffer/window displayed and draw to screen
SDL_GL_SwapWindow(_window);
}
// Wont exit unless _gameState is equal to EXIT
void MainGame::gameLoop() {
while (_gameState != GameState::EXIT) {
procInput();
drawGame();
}
}
I am trying to display a bitmap image onto my window. I created an SDL_Surface for my window, and an SDL_Surface for my image initialized to NULL. My error, "Unable to load bitmap, 'ForhalenIntro_Screen.bmp'!" is returning, so I know the code is failing at the line where menuImage is assigned the bitmap function with the path to the image as the argument. I've double checked the file name, location and path. I've tried having just the filename as the path. The file is in the same folder as my vcrxproj file and main.cpp file. Where have I gone wrong? I am not getting any syntax errors and I have obviously included the necessary header files. EDIT: I've now also tried it with SDL_image but it still didn't work.
我想在我的窗口上显示一个位图图像。我为我的窗口创建了一个SDL_Surface,并为我的图像初始化为NULL的SDL_Surface。我的错误,“无法加载位图,'ForhalenIntro_Screen.bmp'!”正在返回,所以我知道代码在menuImage被赋予位图函数的行中失败,其中图像的路径作为参数。我仔细检查了文件名,位置和路径。我试过只用文件名作为路径。该文件与我的vcrxproj文件和main.cpp文件位于同一文件夹中。我哪里出错了?我没有收到任何语法错误,显然我已经包含了必要的头文件。编辑:我现在也尝试使用SDL_image,但它仍然无法正常工作。
1 个解决方案
#1
0
Your issue here is unintentional escaping (and most likely an incorrect path).
你在这里的问题是无意的逃避(很可能是一条错误的路径)。
menuImage = SDL_LoadBMP("\Liam C\Documents\Visual Studio 2015\Projects\graphicsPractice\graphicsPractice\ForehalenIntro_Screen.bmp");
Assuming this is in the default directory Visual Studio creates for you, the correct path would be: "C:\Users\Liam C\Documents\Visual Studio 2015\Projects\graphicsPractice\graphicsPractice\ForehalenIntro_Screen.bmp"
假设这是Visual Studio为您创建的默认目录,则正确的路径为:“C:\ Users \ Liam C \ Documents \ Visual Studio 2015 \ Projects \ graphicsPractice \ graphicsPractice \ ForehalenIntro_Screen.bmp”
In most programming languages, a \
is used to create a special character that cannot normally be typed, such as a null character ('\0'
) or a Unicode character (u16'\u263A'
or u32'\U0001F60A'
). So your use of the \
character in your string is (accidentally) trying to make special characters from '\L'
, '\D'
, '\V'
, '\P'
, '\g'
, '\g'
, and '\F'
.
在大多数编程语言中,\用于创建通常无法输入的特殊字符,例如空字符('\ 0')或Unicode字符(u16'\ u263A'或u32'\ U0001F60A')。所以你在你的字符串中使用\字符是(意外)尝试从'\ L','\ D','\ V','\ P','\ g','\ g'制作特殊字符,和'\ F'。
You can either double up the backslashes ('\\'
makes a \
character) or change the separators to forward slashes:
您可以将反斜杠加倍('\\'创建\字符)或将分隔符更改为正斜杠:
menuImage = SDL_LoadBMP("C:\\Users\\Liam C\\Documents\\Visual Studio 2015\\Projects\\graphicsPractice\\graphicsPractice\\ForehalenIntro_Screen.bmp");
// OR
menuImage = SDL_LoadBMP("C:/Users/Liam C/Documents/Visual Studio 2015/Projects/graphicsPractice/graphicsPractice/ForehalenIntro_Screen.bmp");
#1
0
Your issue here is unintentional escaping (and most likely an incorrect path).
你在这里的问题是无意的逃避(很可能是一条错误的路径)。
menuImage = SDL_LoadBMP("\Liam C\Documents\Visual Studio 2015\Projects\graphicsPractice\graphicsPractice\ForehalenIntro_Screen.bmp");
Assuming this is in the default directory Visual Studio creates for you, the correct path would be: "C:\Users\Liam C\Documents\Visual Studio 2015\Projects\graphicsPractice\graphicsPractice\ForehalenIntro_Screen.bmp"
假设这是Visual Studio为您创建的默认目录,则正确的路径为:“C:\ Users \ Liam C \ Documents \ Visual Studio 2015 \ Projects \ graphicsPractice \ graphicsPractice \ ForehalenIntro_Screen.bmp”
In most programming languages, a \
is used to create a special character that cannot normally be typed, such as a null character ('\0'
) or a Unicode character (u16'\u263A'
or u32'\U0001F60A'
). So your use of the \
character in your string is (accidentally) trying to make special characters from '\L'
, '\D'
, '\V'
, '\P'
, '\g'
, '\g'
, and '\F'
.
在大多数编程语言中,\用于创建通常无法输入的特殊字符,例如空字符('\ 0')或Unicode字符(u16'\ u263A'或u32'\ U0001F60A')。所以你在你的字符串中使用\字符是(意外)尝试从'\ L','\ D','\ V','\ P','\ g','\ g'制作特殊字符,和'\ F'。
You can either double up the backslashes ('\\'
makes a \
character) or change the separators to forward slashes:
您可以将反斜杠加倍('\\'创建\字符)或将分隔符更改为正斜杠:
menuImage = SDL_LoadBMP("C:\\Users\\Liam C\\Documents\\Visual Studio 2015\\Projects\\graphicsPractice\\graphicsPractice\\ForehalenIntro_Screen.bmp");
// OR
menuImage = SDL_LoadBMP("C:/Users/Liam C/Documents/Visual Studio 2015/Projects/graphicsPractice/graphicsPractice/ForehalenIntro_Screen.bmp");