Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

LNK2001

glDrawElements()

This topic is 5853 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''m trying to write a couple of classes to wrap triangle mesh data so that it can be sent to glDrawElements(). For different reasons I split the code in a CMesh class and a CSubMesh class. The CSubMesh class contains (most of)the geometry and does the actual rendering. The CMesh class owns a vector of CSubMesh. The CSubMesh class has a vector of vertex indices used when rendering triangles. These vertex indices refer to elements in a CPoint3D array owned by the CMesh class - so that vertex locations can be shared among triangles. However, I don''t want vertex normals (and texture coords) to be shared among triangles, but local to each triangle. That way, vertex locations wouldn''t have to be duplicated if two triangles share a point but have different normals(or texture coords) at that point. This is all uncomplicated enough, but somehow I can''t figure out how to represent a mesh this way and still have it work well with glDrawElements(). Of course I could store the vertex locations several times (along with the vertex normals and texure coords), each time they are used by a triangle, but that would be... ugly. The code below doesn''t work the way I want, because the *indices parameter in glDrawElements() refers to indices BOTH in the point array, the normals array and the texcoord array. Oh well. Any idea how to fix it? Maybe I''m trying to do something that glDrawElements() wasn''t designed to do? If this question seems a bit confused, that''s because I am.
  
class CMesh
{
protected:

	class CSubMesh
	{
	protected:
		// m_Indices, m_Normals, m_TexCoords all have 

		// 3*trianglecount elements (3 for each triangle).

		vector<int> m_Indices;        // Vertex indices (refers to CMesh::m_VxPoints)

		vector<CPoint3D> m_Normals;   // Vertex normals

		vector<CPoint2D> m_TexCoords; // Texture coords


	public:
		void Render(CPoint3D* pVertexPoints)
		{
			glVertexPointer(3, GL_FLOAT, 0, pVertexPoints);
			glTexCoordPointer(m_TexCoords.size(), GL_FLOAT, 0, &m_TexCoords[0]);
			glNormalPointer(GL_FLOAT, 0, &m_Normals[0]);
			glDrawElements(GL_TRIANGLES, m_Indices.size(), GL_UNSIGNED_INT, &m_Indices[0]);
		}
	};


protected:
	vector<CPoint3D> m_VxPoints;  // Vector of vertex locations, shared

	vector<CSubMesh> m_SubMeshes; // Vector of submeshes


public:
	void Render()
	{
		// Render each submesh

		for(int i=0; i<m_SubMeshes.size(); i++)
			m_SubMeshes[i].Render(&m_VxPoints[0]);
	}
};
  

Share this post


Link to post
Share on other sites
Advertisement
sorry you lost me in the first sentence
i prefer the term model (which is a collection of meshes) anyways thats moot.
if i understand u correctly youre havent problems cause in opengl for each vertice MUST have a corresponding color/normal/texture coordinate, ie they must be the same number (u can have 20 vertices + 60 texture coordinates but will have to change that to 60 each)

http://uk.geocities.com/sloppyturds/gotterdammerung.html

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!