Jon723
07-26-2006, 06:16 PM
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?
// 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;
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);
}
}
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?
// 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;
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);
}
}