Render an .OBJ file to the screen

A freind of mine and myself are trying to make a map for a game that I am working on. He made the map and the faces are triangulated to go into my .OBJ loader (it just reads off all of the verticies and stores them into an array in order). HOWEVER, when I try and render it to the screen, it seems like all of the faces are tilted. Here is the code for the rendering:

for(int i = 2;i <= coordcount-1;i++){
	glEnd( );

and this is the object loader:

ifstream objfile ("triangulatedrockyhills.obj");	//open the .obj file
		string line;
		stringstream ss;
		string trash;
		if(line[0] == 'v' && line[1] == ' '){
			ss >> trash >> coord[coordcount][0] >> coord[coordcount][1] >> coord[coordcount][2];
			printf("V	I:%d	X:%f	Y:%f	Z:%f	
		}else if(line[0] == 'v' && line[1] == 'n'){
			ss >> trash >> normcoord[normcoordcount][0] >> normcoord[normcoordcount][1] >> normcoord[normcoordcount][2];
			printf("VN	I:%d	X:%f	Y:%f	Z:%f	
		}else if(line[0] == 'f' && line[1] == ' '){
			ss >> trash >> face[facecount][0] >> face[facecount][1] >> face[facecount][2];
			printf("F	I:%d	A:%s	B:%s	C:%s	
",facecount,(char *)face[facecount][0].c_str(),(char *)face[facecount][1].c_str(),(char *)face[facecount][2].c_str());

not sure exactly where the problem is (if it is in the loader or the rendering) but I decided to post it here since I have more experience in the coding than OpenGL. I hope you can help.

Shouldn’t that be i+=3 ?

I tried that and that does not work (I think an OBJ file makes 2 points and any others go off of the 2 previous ones to make a triangle). I also checked the OBJ loader and it works perfectly. Here is an image of the OBJ loader failing to render a file.

Here is the full program if that will help:

This is the program rendering a much simpler shape, a triangulated cube.

Can anyone help?

for starters, the face data is used to index into the array of vertices, i.e you’ll need to rewrite your render loop to use the face data to index into the array of vertices to form the triangles correctly.
e.g. suppose one face is defined as 6, 7, 1
then the sixth, seventh and first vertices you read in will form one triangle.

not to sound critical but im surprised this loader even works for you. ive looked at some obj files and they do things like describing a shape through indexed triangles and then suddenly switching to describing it in a long line strip or triangle strip or whatever. if you want a goo obj loader i think you’re gonna need alot more than what you’ve just written. ive been thinking about how to write one and i think the easiest way would be to store all your data in a structure and include variables to indicate when it switches between primitive types. then you can write a display function to display these structures. thats what i would do. To make a good one, is gonna take alot of work. sorry :frowning:

I will try and rewrite it to use the faces and use structs instead of the variables.