Jump to content
  • Advertisement
Sign in to follow this  

using vertex arrays

This topic is 4030 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

Hello guys, I want to display an animation sequence which comprises of 100 mehses each having 40,000 triangles and 23,000 vertices. Each mesh is in the obj file format. I was using display list to draw each mesh and i switch between display lists as the frame increments. I wanted to know whats the most efficient way to go about this. As i will have two windows simultaneously running this animation sequence so i need to ensure that drawing is really fast. I have already tried display list and they are not fast enough when i have two windows open animation is very slow. I wanted to know a couple of things : 1. Whats the most efficient way to animate all this data(display lists, vertex arrays, vertex buffer objects) ? 2. Do i need to restructure my data when i am making a call to glVertexPointer, glNormalPointer and glDrawElement etc. 3. I have pasted the code below i am trying to use vertex array for some reasons my model is not drawn properly. Could someone please help me resolve the problem. m_aVertexArray and m_aNormalArray contain my vertex data and normal data. m_aFaceArray contains the information about face(which indices form the face etc). All these are read fine from the obj file so there is no problem with them. The problem is the way i use methods for Vertex Array or when i am converting the data to be used for Vertex Array calls.

struct ObjTexCoord
        float u;
        float v;
struct ObjFace
        unsigned int vertexIndices[3];
	unsigned int normalIndices[3];
	unsigned int texCoordIndices[3];
class ObjModel
		GLuint modelDL;
		string m_strFileName;
		int m_iNumberOfVertices;
		int m_iNumberOfNormals;
		int m_iNumberOfTexCoords;
		int m_iNumberOfFaces;
		Vector3D * m_aVertexArray;
		Vector3D * m_aNormalArray;
		ObjTexCoord * m_aTexArray;
		ObjFace * m_aFaceArray;
		Vector3D m_Centroid;
		Vector3D m_Min;
		Vector3D m_Max;
		float m_BBsize;
		unsigned int * m_pIndices;
		double * m_pVertices;
		double * m_pNormalVertices;	
//................................................. etc
	m_aVertexArray = new Vector3D[m_iNumberOfVertices];
	m_aNormalArray = new Vector3D[m_iNumberOfNormals];
	m_aTexArray = new ObjTexCoord[m_iNumberOfTexCoords];
	m_aFaceArray = new ObjFace[m_iNumberOfFaces];
        m_pNormalVertices  = new double[m_iNumberOfVertices * 3];
	for( int i = 0 ; i < m_iNumberOfNormals; i+=3 )
		m_pNormalVertices   = m_aNormalArray.x;
		m_pNormalVertices[i+1] = m_aNormalArray.y;
		m_pNormalVertices[i+2] = m_aNormalArray.z;
	m_pVertices  = new double[m_iNumberOfVertices * 3];
	for ( int i = 0 ; i < m_iNumberOfVertices ; i+=3 )
		m_pVertices = m_aVertexArray.x;
		m_pVertices[i+1] = m_aVertexArray.y;
		m_pVertices[i+2] = m_aVertexArray.z;
	m_pIndices = new unsigned int [m_iNumberOfFaces * 3];
	for ( int i = 0 ; i < m_iNumberOfFaces ; i+=3 )
		m_pIndices = m_aFaceArray.vertexIndices[0]-1;
		m_pIndices[i+1] = m_aFaceArray.vertexIndices[1]-1;
		m_pIndices[i+2] = m_aFaceArray.vertexIndices[2]-1;
void ObjModel::display()
	//if( !modelDL )
	//	createDisplayList();
	//	glCallList(modelDL);
	//	glCallList(modelDL);
	glVertexPointer(3, GL_DOUBLE, 0, m_pVertices);
	glNormalPointer(GL_DOUBLE, 0, m_pNormalVertices);
	glDrawElements(GL_TRIANGLES, m_iNumberOfFaces , GL_UNSIGNED_INT, m_pIndices);

Share this post

Link to post
Share on other sites
Storing your vertex and normal data as doubles is really bad. The hardware does not support this and therefore has to convert is to floats in each draw call. Use floats instead.

Also you should consider using VBOs instead of vertex arrays since they are potentially faster.

And storing 100 different meshes each of them beeing 1 frame of the animation sequence is really bad. Ideally you would only store the mesh data once and use vertex skinning for the animation with a dynamic VBO.

Share this post

Link to post
Share on other sites
Thats the only way i can use them. Its soft body so i cannot do skinning as such. Yeah you are right about doubles. But wahts wrong with the drawing code my model doesnt even draw properly. Thanks

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!