Problem with mesh data structure

Started by
4 comments, last by UncleRemus 18 years, 3 months ago
Hello, First of all a happy new year !! I'm creating a simple mesh class and I stumbled upon the following : Initialization of Mesh :

m_Vertices.push_back(cVector(-1.0f,-1.0f,1.0f));
m_Vertices.push_back(cVector(-1.0f,1.0f,1.0f));
m_Vertices.push_back(cVector(1.0f,1.0f,1.0f));
m_Vertices.push_back(cVector(1.0f,-1.0f,1.0f));
m_Vertices.push_back(cVector(-1.0f,-1.0f,-1.0f));
m_Vertices.push_back(cVector(-1.0f,1.0f,-1.0f));
m_Vertices.push_back(cVector(1.0f,1.0f,-1.0f));
m_Vertices.push_back(cVector(1.0f,-1.0f,-1.0f));

m_Triangles.push_back(cTriangle(0,1,2));
m_Triangles.push_back(cTriangle(2,3,0));
m_Triangles.push_back(cTriangle(4,5,6));
m_Triangles.push_back(cTriangle(6,7,4));

m_Mesh.push_back(0);
m_Mesh.push_back(1);
m_Mesh.push_back(2);

m_Mesh.push_back(2);
m_Mesh.push_back(3);
m_Mesh.push_back(0);

m_Mesh.push_back(4);
m_Mesh.push_back(5);
m_Mesh.push_back(6);

m_Mesh.push_back(6);
m_Mesh.push_back(7);
m_Mesh.push_back(4);

glVertexPointer(3,GL_FLOAT,0,&m_Vertices[0]);


Rendering :

glColor3f(1.0,0.0,0.0);  //Red
glDrawElements(GL_TRIANGLES,m_Triangles.size()*3,GL_UNSIGNED_INT,&m_Triangles[0]);

glColor3f(0.0,1.0,0.0); //Green
glDrawElements(GL_TRIANGLES,m_Mesh.size(), GL_UNSIGNED_INT,&m_Mesh[0]);

Now the red mesh is drawn incorrectly, while the green one is correct. Does anyone have an idea why this is ? kind regards UncleRemus
Advertisement
what does cTriangle look like?
The ctriangle looks like this :

class cTriangle{public:	unsigned int a,b,c;	cTriangle(unsigned int _a=0.0f,unsigned int _b=0.0f,unsigned int _c=0.0f);	virtual ~cTriangle(void);};
strange...
it might have a vtable because of your 'virtual'. if sizeof(cTriangle) is returning 12 it should work. =)
are you sure both triangles are being drawn counter-clockwise? What is incorrect about the mesh? Is it not visible?
moe.ron
Grelle,

It was indeed the vtable, sizeof(cTriangle) returned 16 instead of 12.

Thx !!
UncleRemus

This topic is closed to new replies.

Advertisement