learnopengl-cn中,glfwtemplate/container.jpg路径问题的解决

首先,要把所有文件(包括.cpp,.h,.fs,.vs)都放到当前文档目录下,不能放在各个src文件夹里,不然会加载着色器错误,可能跟路径有关。

在learnopengl-cn的6.1章纹理映射中,网站原本的源码并不好,会出现filesystem.h的相关错误,而filesystem.h的作用仅仅是用来加载图片文件(例如container.jpg),并没有其他的作用。

learnopengl-cn中,glfwtemplate/container.jpg路径问题的解决_第1张图片

打开filesystem.h后,发现有一行

learnopengl-cn中,glfwtemplate/container.jpg路径问题的解决_第2张图片

#include "root_directory.h" // This is a configuration file generated by CMake.

这说明有个root_directory.h文件需要我们自己去编译,但是在OPENGL学习中,我们并不必使用filesystem.h来读取文件.

解决方法:

  注释掉 filesystem.h 所在行,并在 stbi_load() 函数中将 getPath 函数替换为目标文件的目录,并把读取图片container.jpg的路径设置为自己的绝对路径:

//修改后的代码,使用绝对路径    
    unsigned char *data = stbi_load("D:/Template/glfwtemplate/glfwtemplate/container.jpg", &width, &height, &nrChannels, 0);

//原本的代码:
    //unsigned char *data = stbi_load(FileSystem::getPath("resources/textures/container.jpg").c_str(), &width, &height, &nrChannels, 0);

此外,还可以将VS平台换成VS 16 2019可以解决此问题。

(但是2019会将顶点着色器和片段着色器里的空格识别为整数文本,很头疼。)

或许可以下载存储库的新副本。解压到对应目录/文件夹中,然后不要更改或重命名该目录/文件夹,运行 cmake 并构建。但我没试了。
 

除此之外,首先在VS2013中搭建opengl环境,配置VS2013中各个库的信息,在这里记录一下备查。

C++命令行:

/GS /analyze- /W3 /Zc:wchar_t /I"D:\Template\glfwtemplate\glfwtemplate\glm" /I"D:\Template\glfwtemplate\glfwtemplate\LearnOpenGL\includes\learnopengl" /I"D:\Template\glfwtemplate\glfwtemplate\stb-master" /ZI /Gm /Od /sdl /Fd"Debug\vc120.pdb" /fp:precise /D "_MBCS" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /Oy- /MDd /Fa"Debug\" /EHsc /nologo /Fo"Debug\" /Fp"Debug\glfwtemplate.pch" 

链接器命令行:

/OUT:"D:\Template\glfwtemplate\Debug\glfwtemplate.exe" /MANIFEST /NXCOMPAT /PDB:"D:\Template\glfwtemplate\Debug\glfwtemplate.pdb" /DYNAMICBASE "glfw3.lib" "opencv_ml2413d.lib" "opencv_calib3d2413d.lib" "opencv_contrib2413d.lib" "opencv_core2413d.lib" "opencv_features2d2413d.lib" "opencv_flann2413d.lib" "opencv_gpu2413d.lib" "opencv_highgui2413d.lib" "opencv_imgproc2413d.lib" "opencv_legacy2413d.lib" "opencv_objdetect2413d.lib" "opencv_ts2413d.lib" "opencv_video2413d.lib" "opencv_nonfree2413d.lib" "opencv_ocl2413d.lib" "opencv_photo2413d.lib" "opencv_stitching2413d.lib" "opencv_superres2413d.lib" "opencv_videostab2413d.lib" "opencv_objdetect2413.lib" "opencv_ts2413.lib" "opencv_video2413.lib" "opencv_nonfree2413.lib" "opencv_ocl2413.lib" "opencv_photo2413.lib" "opencv_stitching2413.lib" "opencv_superres2413.lib" "opencv_videostab2413.lib" "opencv_calib3d2413.lib" "opencv_contrib2413.lib" "opencv_core2413.lib" "opencv_features2d2413.lib" "opencv_flann2413.lib" "opencv_gpu2413.lib" "opencv_highgui2413.lib" "opencv_imgproc2413.lib" "opencv_legacy2413.lib" "opencv_ml2413.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:"D:\Template\glfwtemplate\Debug\glfwtemplate.pgd" /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /ManifestFile:"Debug\glfwtemplate.exe.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /TLBID:1 

清单列表命令行:/verbose /out:"Debug\glfwtemplate.exe.embed.manifest" /nologo "Debug\glfwtemplate.exe.embed.manifest.res" 

learnopengl-cn中,glfwtemplate/container.jpg路径问题的解决_第3张图片

learnopengl-cn中,glfwtemplate/container.jpg路径问题的解决_第4张图片

learnopengl-cn中,glfwtemplate/container.jpg路径问题的解决_第5张图片

你可能感兴趣的:(c++,计算机视觉,图形渲染)