osg系列文章目录
前言
运行VS2019的OSG工程时,前一天可以正常读取模型与纹理windows字体文件,今天就不行了
Error reading file C:\Windows\Fonts\arial.ttf: read error (Could not find plugin to read objects from file “C:\Windows\Fonts\arial.ttf”.)
Error writing file Text.osg: write error (Could not find plugin to write nodes to file “Text.osg”.)
Failed in osgDB::writeNodeFile().
Successfully wrote “Text.osg”. Execute " osgviewer Text.osg" to view.
void StateSet::setGlobalDefaults() ShaderPipeline disabled.
Error reading file Text.osg: read error (Could not find plugin to read objects from file “Text.osg”.)
请按任意键继续. . .
一、问题定位
首先,从编译器的错误提示来看,osg的读写字体文件的插件dll找不到了。因为我把osg相关的环境变量全部删除了,我的机器上安装了多个osg版本,把这些不同版本的osg写入环境变量是会冲突的。所以程序找不到对应的osg读写文件插件而报错
二、解决
1.修改系统环境变量
在系统环境变量中只保留一个版本的osg 的path路径,运行的工程用到哪个版本的osg,就在环境变量中设置哪个osg 的path路径。缺点是,反复修改环境变量,而且还要重启机器,太麻烦。也可以不用重启,注销一下系统环境变量就会生效。
2.在每个osg工程中配置osg头文件lib和dll已经plugins
删除掉环境变量中osg相关的路径,在每个osg工程中都包含osg头文件lib和dll已经plugins