Hey, so I’m working in C++ and wanting to render an .obj file I parsed.
Parse code:
void objparse() {
std::vector<float> TempVertices;
std::vector<short> TempIndices;
std::ifstream File("C:/Users/Owen/Desktop/Game/Folder/Models/obj.obj");
std::string Line;
std::string Name;
while (std::getline(File, Line)) {
if (Line == "" || Line[0] == '#')// Skip everything and continue with the next line
continue;
std::istringstream LineStream(Line);
LineStream >> Name;
if (Name == "v"){// Vertex
float Vertex[3];
sscanf_s(Line.c_str(), "%*s %f %f %f", &Vertex[0], &Vertex[1], &Vertex[2]);
TempVertices.push_back(Vertex[0]);
TempVertices.push_back(Vertex[1]);
TempVertices.push_back(Vertex[2]);
}
if (Name == "f"){// Index
short Index[3];
sscanf_s(Line.c_str(), "%*s %d %d %d", &Index[0], &Index[1], &Index[2]);
TempIndices.push_back(Index[0]);
TempIndices.push_back(Index[1]);
TempIndices.push_back(Index[2]);
}
}
}
I’m not worried about the .mtl file yet. I just wanna render the .obj. I am using D3D11, so if someone can help, thanks.