OpenGL 打开 Mesh (.m) 文件与 Visual Studio2010
OpenGL opening Mesh (.m) file with Visual Studio2010
由于
某种原因,它只是不会加载网格文件。我无法判断是因为我输入了错误的内容,还是我只是没有将文件放在正确的文件夹中。我现在把它放在与.exe相同的文件夹中,我也把它放在我的"源文件"下(这可能是错误的)。
网格.cpp
#include "MeshTable.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
void MeshTable::ReadMesh_M(const char *filename) {
points.clear();
faces.clear();
//the Vertex id in .m file begins from 1,
//we insert an empty point to align the index
points.push_back(Point());
std::ifstream input("C:\Users\Zach\Documents\Visual Studio 2010\Projects\MAIN\Release\dog.m");
while(input.good()) {
std::string line;
getline(input, line);
if (line.empty()) {
continue;
}
std::stringstream ss(line);
std::string title;
int id;
ss >> title;
if (title == "Vertex") {
Point pt;
ss >> id >> pt[0] >> pt[1] >> pt[2];
points.push_back(pt);
}
else if (title == "Face") {
Face face;
ss >> id >> face.pt_ids[0] >> face.pt_ids[1] >> face.pt_ids[2];
faces.push_back(face);
}
}
input.close();
}
void MeshTable::SaveMesh_M(const char *filename) {
std:: ofstream output(C:\Users\Zach\Documents\Visual Studio 2010\Projects\MAIN\Release\dog_out.m);
for (unsigned int i = 1; i < points.size(); ++i) {
const Point& pt = points[i];
output << "Vertex " << i << " " << pt[0] << " " << pt[1] << " " << pt[2] << "n";
}
for (unsigned int i = 0; i < faces.size(); ++i) {
const Face& face = faces[i];
output << "Face " << i + 1 << " " << face.pt_ids[0] << " " << face.pt_ids[1] << " " << face.pt_ids[2] << "n";
}
output.close();
}
它构建良好,但是当我尝试调试它时,OpenGL 窗口弹出打开大约 3 秒钟,然后关闭并说"程序'[3188] Main.exe:Native' 已退出,代码为 -1 (0xffffffff)。这来自我的主要.cpp。
if (argc != 2) {
std::cout << "Load a .m file as a mesh table.n";
std::cout << "Usage: " << argv[0] << " input_mesh.mn";
exit(-1);
}
编辑 一旦我删除了它,它就起作用了。我的老师给了我这(部分)代码,所以我真的不明白为什么这会让它不起作用。
if (argc != 2) {
std::cout << "Load a .m file as a mesh table.n";
std::cout << "Usage: " << argv[0] << " input_mesh.mn";
exit(-1);
}
if (argc != 2) {
std::cout << "Load a .m file as a mesh table.n";
std::cout << "Usage: " << argv[0] << " input_mesh.mn";
exit(-1);
}
运行程序时,您需要将网格文件的名称传递到命令行参数中。 即它应该作为"program.exe meshfile.m"启动。
在VS 2008中,调试参数/命令行参数可以在项目属性->配置属性->调试->命令参数中指定。在VS2010中,它们可能位于类似的位置。
另外,在运行程序时读取"输出"。教师提供的代码片段实际上打印了程序用法。
相关文章:
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- Visual Studio在尝试读取resource.txt文件时崩溃
- 找不到Linux Visual Studio代码C++文件
- 从 exe 文件 (Visual Studio ) 启动时调试断言失败
- Visual Studio C++ 它只构建选项卡中显示的文件吗?
- 如何在Visual Studio Code中重命名我的a.exe文件?
- 如何在Visual C+++中从JSON文件中读取节点数据
- 通过命令行在Visual Studio中编译单个独立文件
- 来自Visual Studio中控制台项目的exe文件?
- C++20 使用 Visual Studio 编译模块:不编译或导入 ixx 文件
- 将Visual Studio Code路径设置为.clang_format文件
- 无法在Visual Studio 2019中打开文件
- 区分 32 位和 cl.exe 生成的 64 位 PE 对象文件(Visual Studio C++)
- Unitest 文件 (Visual Studio) 上未解析的外部符号
- 强制链接静态库中的 CPP 文件 (Visual Studio)
- C++ CPP 文件 (Visual Studio) 中实现的模板错误
- 如何读/写INI文件Visual c++6.0(MFC)
- 从文件中读取数据并将其写入其他文件(Visual studio 2012)
- 编译*.Lib文件visual studio
- 在可执行文件(Visual Studio)中嵌入编译器选项的字符串