Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法获取SDL_LoadBMP以显示图像(C++)?_C++_File_Bitmap_Sdl_Sdl 2 - Fatal编程技术网

无法获取SDL_LoadBMP以显示图像(C++)?

无法获取SDL_LoadBMP以显示图像(C++)?,c++,file,bitmap,sdl,sdl-2,C++,File,Bitmap,Sdl,Sdl 2,我正在尝试在窗口上显示位图图像。我为我的窗口创建了一个SDL_曲面,为初始化为NULL的图像创建了一个SDL_曲面。我的错误,无法加载位图“forhalentro_Screen.bmp”!正在返回,因此我知道在menuImage被分配位图函数并以图像路径作为参数的行中,代码失败。我仔细检查了文件名、位置和路径。我试着用文件名作为路径。该文件与我的vcrxproj文件和main.cpp文件位于同一文件夹中。我哪里出错了?我没有得到任何语法错误,我显然包括了必要的头文件。 编辑: 我现在也尝试了SD

我正在尝试在窗口上显示位图图像。我为我的窗口创建了一个SDL_曲面,为初始化为NULL的图像创建了一个SDL_曲面。我的错误,无法加载位图“forhalentro_Screen.bmp”!正在返回,因此我知道在menuImage被分配位图函数并以图像路径作为参数的行中,代码失败。我仔细检查了文件名、位置和路径。我试着用文件名作为路径。该文件与我的vcrxproj文件和main.cpp文件位于同一文件夹中。我哪里出错了?我没有得到任何语法错误,我显然包括了必要的头文件。 编辑:
我现在也尝试了SDL_image,但仍然不起作用。

您这里的问题是无意逃逸,很可能是路径不正确

    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();
    }

}
假设这是Visual Studio为您创建的默认目录,正确的路径是:C:\Users\Liam C\Documents\Visual Studio 2015\Projects\graphicsractice\graphicsractice\forehalentro\u Screen.bmp

在大多数编程语言中,使用\来创建通常无法键入的特殊字符,例如空字符'\0'或Unicode字符u16'\u263A'或u32'\U0001F60A'。因此,您在字符串中使用\字符时,无意中尝试使用来自“\L”、“D”、“V”、“P”、“g”、“g”和“\F”的特殊字符

您可以将反斜杠“\\”加倍以生成\字符,也可以将分隔符更改为正斜杠:

menuImage = SDL_LoadBMP("\Liam C\Documents\Visual Studio 2015\Projects\graphicsPractice\graphicsPractice\ForehalenIntro_Screen.bmp");

您正在使用哪个版本的Windows,其中\Liam C是有效的路径前缀?这只是使其工作的众多尝试之一。我只试过文件名,完整的目录从磁盘开始,从项目文件夹开始,从vcrxproj文件夹开始。etcThank你这么多!
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");