I’m using Microsoft Visual Studio with OpenGL/C++.
I’ve been searching the web for days on tutorials, but there doesn’t seem to be any that still work / that I can follow and get working.
I’m just trying to display a Cube for now, but can’t seem to read in the correct values T_T.
I’m currently reading in Colours, Vertices, and Indices from my own created file, and drawing Polygons to make a cube, but I can’t seem to expand this to the format of a .obj file.
Here’s what I currently have:
int read_file (const string fileName)
{
ifstream inFile;
inFile.open(fileName.c_str());
inFile >> NUM_VERTS;
vertices = new point3D[NUM_VERTS];
for (int i=0; i < NUM_VERTS; i++)
{
inFile >> vertices[i].x;
inFile >> vertices[i].y;
inFile >> vertices[i].z;
}
inFile >> NUM_COL;
colours = new colour[NUM_COL];
for (int i=0; i < NUM_COL; i++)
{
inFile >> colours[i].r;
inFile >> colours[i].g;
inFile >> colours[i].b;
}
inFile >> NUM_POLY;
indices = new polygon[NUM_POLY];
for (int i=0; i < NUM_POLY; i++)
{
inFile >> indices[i].a;
inFile >> indices[i].b;
inFile >> indices[i].c;
}
inFile.close();
return 0;
}
void drawCube()
{
for (int i = 0; i < NUM_POLY; i++)
{
glColor3f(colours[i].r, colours[i].g, colours[i].b);
drawPolygon(indices[i].a, indices[i].b, indices[i].c);
}
}
void drawPolygon(int a, int b, int c)
{
glBegin(GL_TRIANGLES);
glVertex3fv(&vertices[a].x); //Top
glVertex3fv(&vertices[b].x); //Bottom left
glVertex3fv(&vertices[c].x); //Bottomg right
glEnd();
}
Any help would be massively appreciated, as I’m really confused.