currently I re-write my codes and change them to make they are better.
I have vertex struct like this:
struct SVertex
{
float X, Y, Z;
};
struct STexCoord
{
float U, V;
};
And I re-wrote it like this
struct SVertex
{
int Flag, BoneID;
float Pos[3];
float UV[2];
};
When it comes to the render function, I just need to change it from:
glVertexPointer(3, GL_FLOAT, 0, &(Mesh[i].Vertex[0]));
glTexCoordPointer(2, GL_FLOAT, 0, &(Mesh[i].TexCoord[0]));
to:
glVertexPointer(3, GL_FLOAT, sizeof (SVertex), &(Mesh[i].Vertex[0].Pos));
glTexCoordPointer(2, GL_FLOAT, sizeof (SVertex), &(Mesh[i].Vertex[0].UV));
The problem comes from the triangle struct. I re-wrote the Triangle from
struct STriangle
{
int X, Y, Z;
};
to
struct STriangle
{
int Flag, Group;
int V[3], N[3];
};
and I changed the glDrawElements from:
glDrawElements(GL_TRIANGLES, Mesh[i].TriangleTotal*3, GL_UNSIGNED_INT, &(Mesh[i].Triangle[0]));
to
glDrawElements(GL_TRIANGLES, Mesh[i].TriangleTotal*3, GL_UNSIGNED_INT, &(Mesh[i].Triangle[0].V));
And I got messed vertex with the new triangle struct. If I use the old ones, it is correct. How to pass the new triangle struct to the glDrawElements?
glVertexPointer
andglTexCoordPointer
. Please refer to this OpenGL tutorial to see how to do modern OpenGL properly. \$\endgroup\$ – Soapy Jun 17 '15 at 10:36