出于某种原因,它只是不会加载网格文件。我不知道是因为我输入了错误的东西,还是我只是在正确的文件夹中没有文件。我现在将它与 .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)。” 这来自我的 main.cpp。
if (argc != 2) {
std::cout << "Load a .m file as a mesh table.\n";
std::cout << "Usage: " << argv[0] << " input_mesh.m\n";
exit(-1);
}
编辑一旦我删除了它,它就起作用了。我的老师给了我这个(部分)代码,所以我真的不明白为什么这会使它不起作用。
if (argc != 2) {
std::cout << "Load a .m file as a mesh table.\n";
std::cout << "Usage: " << argv[0] << " input_mesh.m\n";
exit(-1);
}