Sign in to follow this  
MrM

MD2 LOader and NormalVector

Recommended Posts

Hi! I'm starting to use OpenGL and have already my little "engine running. But now i want a little bit more "complex" modeln in my Engine so i found the MD2 Loader Tut on gametutorials.com. It nearly works but i have strange problems with the Normal Vectors. i just see the inner side of my Model... The first thing i dont understand is why the do FrontFaceCulling??? I use in my whole Engine backface culling so i want to stay there.
glEnable(GL_CULL_FACE);		Turn culling on
glCullFace(GL_FRIONT);          Quake2 uses front face culling apparently

Ok.. the next thing is in the drawing algorithm:
	// Render lines or normal triangles mode, depending on the global variable
	glBegin(GL_TRIANGLES);

		// Go through all of the faces (polygons) of the object and draw them
		for(int j = 0; j < pObject->numOfFaces; j++)
		{
			// Go through each corner of the triangle and draw it.
			for(int whichVertex = 0; whichVertex < 3; whichVertex++)
			{
				// Get the index for each point in the face
				int index = pObject->pFaces[j].vertIndex[whichVertex];

				// Get the index for each texture coord in the face
				int index2 = pObject->pFaces[j].coordIndex[whichVertex];
			
				// Give OpenGL the normal for this vertex.  Notice that we put a 
				// - sign in front.  It appears that because of the ordering of Quake2's
				// polygons, we need to invert the normal
				glNormal3f( -pObject->pNormals[ index ].x, -pObject->pNormals[ index ].y, -pObject->pNormals[ index ].z);
					
				// Make sure there was a UVW map applied to the object or else it won't have tex coords.
				if(pObject->pTexVerts) 
				{
					glTexCoord2f(pObject->pTexVerts[ index2 ].x, pObject->pTexVerts[ index2 ].y);
				}
				
				// Pass in the current vertex of the object (Corner of current face)
				glVertex3f(pObject->pVerts[ index ].x, pObject->pVerts[ index ].y, pObject->pVerts[ index ].z);
			}
		}

	glEnd();

He puts a - in front of all Normals, So i thought why not just removing all - signs and switch back to Bachface culling? Where is my fault??? it doesn't work?? Greets MrM

Share this post


Link to post
Share on other sites
You have to change the winding order of the triangles as well as inverting the normals. So when you are reading in the triangles just swap any two of the indices.

Quote:
The first thing i dont understand is why the do FrontFaceCulling???

As it says right next to the glCullFace(GL_FRONT) call, they use front face culling because that's apparently what the Quake2 model format uses. If you meant why does Quake2 use it, you'd have to ask the developers.

Share this post


Link to post
Share on other sites
YES! It works.. (I've read the post in between.. Forget my dumpness.. ; )

THANKS!!!!

Greets
MrM

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this