Jump to content
  • Advertisement
Sign in to follow this  
kburkhart84

OpenGL MD2 and Vertex Arrays

This topic is 4890 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Sorry about this. I tried to post this yesterday and it was giving me http500 internal server error. I'll try again. Thanks in advance. The problem I'm having is that I'm trying to convert my MD2 model class to draw using Vertex Arrays instead of Immediate mode for obvious(speed) reasons. I got the code(I did redo it though) from OpenGL Game Programming by Kevin Hawkins. The Immediate mode drawing works fine. I can get the Vertex Arrays to works as well, supplying random vertices, so that's not the problem. I looked at the drawing code, and each frame, I take the triangles, put the vertices into arrays, and draw them. Now what I get is like I'm completely missing parts of the model(even the head). The boots show up, but I can't tell whether or not the vertices of what is drawn is correct or not. The code follows. The commented part is what the Immediate mode is like that works fine, the rest is the new stuff. listPtr gets pointed to the section of the array of verts that has the frame we want to draw.
mytexture.Use();
	vector_t* listPtr;
	int i;
	listPtr=&pointList[numPoints*framenumber];
	for(i=0;i<numTriangles;i++)
	{
		tmpverts[i*3][0]=listPtr[triIndex.meshIndex[0]].point[0];
		tmpverts[i*3][1]=listPtr[triIndex.meshIndex[0]].point[1];
		tmpverts[i*3][2]=listPtr[triIndex.meshIndex[0]].point[2];
		tmpverts[(i*3)+1][0]=listPtr[triIndex.meshIndex[1]].point[0];
		tmpverts[(i*3)+1][1]=listPtr[triIndex.meshIndex[1]].point[1];
		tmpverts[(i*3)+1][2]=listPtr[triIndex.meshIndex[1]].point[2];
		tmpverts[(i*3)+2][0]=listPtr[triIndex.meshIndex[2]].point[0];
		tmpverts[(i*3)+2][1]=listPtr[triIndex.meshIndex[2]].point[1];
		tmpverts[(i*3)+2][2]=listPtr[triIndex.meshIndex[2]].point[2];
		
		tmptexcoords[i*2][0]=st[triIndex.stIndex[0]].s;
		tmptexcoords[i*2][1]=st[triIndex.stIndex[0]].t;
		tmptexcoords[(i*2)+1][0]=st[triIndex.stIndex[1]].s;
		tmptexcoords[(i*2)+1][1]=st[triIndex.stIndex[1]].t;
		tmptexcoords[(i*2)+2][0]=st[triIndex.stIndex[2]].s;
		tmptexcoords[(i*2)+2][1]=st[triIndex.stIndex[2]].t;

		CalculateNormal(vector(listPtr[triIndex.meshIndex[0]].point[0],
				listPtr[triIndex.meshIndex[0]].point[1],
				listPtr[triIndex.meshIndex[0]].point[2]),
				vector(listPtr[triIndex.meshIndex[1]].point[0],
				listPtr[triIndex.meshIndex[1]].point[1],
				listPtr[triIndex.meshIndex[1]].point[2]),
				vector(listPtr[triIndex.meshIndex[2]].point[0],
				listPtr[triIndex.meshIndex[2]].point[1],
				listPtr[triIndex.meshIndex[2]].point[2]),
				&tmpnormals[i*3][0], &tmpnormals[i*3][1], &tmpnormals[i*3][2]);
		tmpnormals[(i*3)+1][0]=tmpnormals[i*3][0];
		tmpnormals[(i*3)+1][1]=tmpnormals[i*3][1];
		tmpnormals[(i*3)+1][2]=tmpnormals[i*3][2];
		tmpnormals[(i*3)+2][0]=tmpnormals[i*3][0];
		tmpnormals[(i*3)+2][1]=tmpnormals[i*3][1];
		tmpnormals[(i*3)+2][2]=tmpnormals[i*3][2];
	}
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glNormalPointer(GL_FLOAT, 0, tmpnormals);
	glTexCoordPointer(2, GL_FLOAT, 0, tmptexcoords);
	glVertexPointer(3, GL_FLOAT, 0, tmpverts);
	glDrawArrays(GL_TRIANGLES, 0, numTriangles);

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	
	/*glBegin(GL_TRIANGLES);
		for(i=0;i<numTriangles;i++)
		{
			
			
			CalculateNormal(vector(listPtr[triIndex.meshIndex[0]].point[0],
				listPtr[triIndex.meshIndex[0]].point[1],
				listPtr[triIndex.meshIndex[0]].point[2]),
				vector(listPtr[triIndex.meshIndex[1]].point[0],
				listPtr[triIndex.meshIndex[1]].point[1],
				listPtr[triIndex.meshIndex[1]].point[2]),
				vector(listPtr[triIndex.meshIndex[2]].point[0],
				listPtr[triIndex.meshIndex[2]].point[1],
				listPtr[triIndex.meshIndex[2]].point[2]));
			glTexCoord2f(st[triIndex.stIndex[0]].s,
				st[triIndex.stIndex[0]].t);
			glVertex3fv(listPtr[triIndex.meshIndex[0]].point);
			glTexCoord2f(st[triIndex.stIndex[2]].s,
				st[triIndex.stIndex[2]].t);
			glVertex3fv(listPtr[triIndex.meshIndex[2]].point);
			glTexCoord2f(st[triIndex.stIndex[1]].s,
				st[triIndex.stIndex[1]].t);
			glVertex3fv(listPtr[triIndex.meshIndex[1]].point);
		}
	glEnd();*/

By the way, mytexture.Use() just binds the correct texture. I saved screenshots, but I don't know how to put them up, I don't have a website. If anyone can tell me an easy way, I'll put up the screenies as well. [Edited by - _the_phantom_ on March 30, 2005 5:21:28 PM]

Share this post


Link to post
Share on other sites
Advertisement
My guess is that it's the call to glDrawArrays. The third parameter, where you are passing numTriangles should be the number of indices to render from the buffers, so it would be more like (numTriangles * 3).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!