OpenGL 打开 Mesh (.m) 文件与 Visual Studio2010

OpenGL opening Mesh (.m) file with Visual Studio2010

本文关键字:文件 Visual Studio2010 打开 Mesh OpenGL      更新时间:2023-10-16
由于

某种原因,它只是不会加载网格文件。我无法判断是因为我输入了错误的内容,还是我只是没有将文件放在正确的文件夹中。我现在把它放在与.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中,它们可能位于类似的位置。

另外,在运行程序时读取"输出"。教师提供的代码片段实际上打印了程序用法。