Sign in to follow this  
cppcdr

Quake 3 BSP Mesh problem

Recommended Posts

Hi, I have been working on a BSP loader for the last few days and I can't get around this problem... My meshes dont render properly... I am basing my code of the BSP loader from www.paulsprojects.net, but I am trying to render the scene without Vertex pointers...Like this (from www.paulsprojects.net):
void BSP::DrawMeshFace(int meshFaceNumber)
{
	//skip this face if its texture was not loaded
	if(isTextureLoaded[meshFaces[meshFaceNumber].textureIndex]==false)
		return;

	//set array pointers
	glVertexPointer(	3, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].position);
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].decalS);

	glClientActiveTextureARB(GL_TEXTURE1_ARB);
	glTexCoordPointer(	2, GL_FLOAT, sizeof(BSP_VERTEX),
						&vertices[meshFaces[meshFaceNumber].firstVertexIndex].lightmapS);
	glClientActiveTextureARB(GL_TEXTURE0_ARB);


	//bind textures
	//unit 0 - decal texture
	glBindTexture(GL_TEXTURE_2D, decalTextures[meshFaces[meshFaceNumber].textureIndex]);

	//unit 1 - lightmap
	glActiveTextureARB(GL_TEXTURE1_ARB);
	if(meshFaces[meshFaceNumber].lightmapIndex>=0)	//only bind a lightmap if one exists
		glBindTexture(GL_TEXTURE_2D, lightmapTextures[meshFaces[meshFaceNumber].lightmapIndex]);
	else
		glBindTexture(GL_TEXTURE_2D, whiteTexture);
	glActiveTextureARB(GL_TEXTURE0_ARB);


	//draw the face, using meshIndices
	if(!EXT_draw_range_elements_supported)
	{
		glDrawElements(	GL_TRIANGLES, meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT,
						&meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);
	}
	else
	{
		glDrawRangeElementsEXT(	GL_TRIANGLES, 0, meshFaces[meshFaceNumber].numVertices,
								meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT,
								&meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);
	}
}


Instead, I am trying to do it like this:
void Quake3BSP::RenderMeshes (int i)
{
	Q3Mesh *pMesh = &m_pMeshes [i];

	m_pEngine->SetTexture (m_pTextureManager->GetTextureID (m_pnTexID [pMesh->nTexID]), GL_TEXTURE0);

	glBegin (GL_TRIANGLES);

	for (int n = 0; n < pMesh->nNumMeshIndices; n++)
	{
		m_pEngine->SetTextureCoords (m_pVertices [pMesh->nFirstVertexIndex+n].texCoord.u, m_pVertices [pMesh->nFirstVertexIndex+n].texCoord.v, R3D_TEXTURE0, R3D_TEXTURE0);
		glVertex3f (m_pVertices [pMesh->nFirstVertexIndex+n].vertex.x, m_pVertices [pMesh->nFirstVertexIndex+n].vertex.y, m_pVertices [pMesh->nFirstVertexIndex+n].vertex.z);
	}

	glEnd ()
}

// Here is the struct for Q3Mesh and Q3Vertex
struct Q3Mesh
{
	int nFirstVertexIndex;
	int nNumVertices;
	int nTexID;
	int nLightmapID;
	int nNumMeshIndices;
	int nFirstMeshIndex;
	int *pnMeshIndices;
};

struct Q3Vertex
{
	Q3Point vertex;
	Q3TexCoord texCoord;
	Q3TexCoord lightmapCoord;
	Q3Point normal;
	unsigned char chColor [4];
};
struct Q3TexCoord
{
	float u, v;
};

struct Q3Point
{
	float x, y, z;
};



For some reason, I am getting really wierd results... the skull that I am trying to render looks more like a collection on knives that just passed through a blender! =) Anyone have an idea why?

Share this post


Link to post
Share on other sites
so this works
glDrawElements( GL_TRIANGLES, meshFaces[meshFaceNumber].numMeshIndices, GL_UNSIGNED_INT, &meshIndices[meshFaces[meshFaceNumber].firstMeshIndex]);

but this doesnt

glBegin (GL_TRIANGLES);
for (int n = 0; n < pMesh->nNumMeshIndices; n++)
{
glVertex3f (m_pVertices [pMesh->nFirstVertexIndex+n].vertex.x, m_pVertices [pMesh->nFirstVertexIndex+n].vertex.y, m_pVertices [pMesh->nFirstVertexIndex+n].vertex.z);
}
glEnd ()

if so u should be wanting someit like
Q3Point &vert = m_pVertices [ meshIndices[meshFaces[meshFaceNumber].firstMeshIndex+n]];
glVertex3f (vert.x,vert.y,vert.z)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this