Jump to content
  • Advertisement
Sign in to follow this  
jon723

Vertex array woes

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

I've decided to move my drawing routines from standard immediate mode routines to use vertex arrays (after I get this to work properly I'll move it to use vertex buffer objects). Basically, I have my structure for vertices, normals, and texture coordinates and I have the model loaded and stored in the varaious arrays for each type. When I enable GL_VERTEX_ARRAY and delcare the vertex pointer for the vertex data then attempt to draw the array with glDrawElements nothing is rendered. My question to you is, based on the structures I have what is the proper way to specify the data for glVertexPointer and glDrawElements? The follow is how I'm defining my structures and arrays:
// defines a single vertex for the model
struct sVertex3d 
{
	sVertex3d();
	float vertex[3];
};

struct sFace
{
	sFace();
	vector<int> vertlist;	// the vertices that make up this face
	vector<int> normlist;	// the list of normals that make up this face
	vector<int> texcoordlist;	// the list of texture coordinates that make up this face
	string material;	// which material does this face use
};

sVertex3d *pvertices;
sFace *pfaces;

This is the section of my draw routine that attempts to use the vertex arrays:
glColor3f(1.0, 1.0, 1.0);
if(!pfaces[n].vertlist.empty())
{
	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(sVertex3d), pvertices[0].vertex);
			
	for(i = 1; i <= pfaces[n].vertlist.size(); i++)
	{	
		if(pfaces[n].vertlist.size() == 3)
			glDrawElements(GL_TRIANGLES, pfaces[n].vertlist.size(), GL_INT, (void*)pfaces[n].vertlist[0]);
		else if(pfaces[n].vertlist.size() > 3)
			glDrawElements(GL_POLYGON, pfaces[n].vertlist.size(), GL_INT, &pfaces[n].vertlist[0]);
				//glVertex3f(pvertices[pfaces[n].vertlist[i-1]].x, pvertices[pfaces[n].vertlist[i-1]].y, pvertices[pfaces[n].vertlist[i-1]].z);
	}
}

Share this post


Link to post
Share on other sites
Advertisement
It looks like you're using a glDrawElements call for each vertex? You need just one call for the entire primitive-list.

The problem with your sFace struct is that there are separate indices for vertex/texcoord/normal which you can't have. You must arrange the data into a single index array. Until you get that working (which isn't very easy) I suggest you loop through at load time and put the vertices sequentially in a data array. Use glDrawArrays to draw.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!