Jump to content
  • Advertisement
Sign in to follow this  

Problem with mesh data structure

This topic is 4521 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, 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

Share this post


Link to post
Share on other sites
Advertisement
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);
};

Share this post


Link to post
Share on other sites
strange...
it might have a vtable because of your 'virtual'. if sizeof(cTriangle) is returning 12 it should work. =)

Share this post


Link to post
Share on other sites
are you sure both triangles are being drawn counter-clockwise? What is incorrect about the mesh? Is it not visible?

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!