Advertisement

q3 BSP loader problems

Started by July 25, 2003 11:01 AM
4 comments, last by tHiSiSbOb 21 years, 7 months ago
Hi. I just started coding a simple q3 BSP map loader and ran into some problems. I use Vertex Arrays to draw the map and when I run it, it causes and error in my OGL driver''s DLL. I ran it with debug and found that it wasn''t loading the correct values for the faces (e.g. some of the face''s starting indecies were negative). Here is the code
bool CBSP::LoadBSP(char *filename)
{
	q3BSPLump lumps[kMaxLumps]={0};
	FILE* fin=fopen(filename,"rb");
	if(!fin)
		return false;

	fread(&header,1,sizeof(q3BSPHeader),fin);
	
	
	fread(&lumps,kMaxLumps,sizeof(q3BSPLump),fin);

	int numVerts=lumps[kVertices].len/sizeof(q3BSPVertex);
	verts=new q3BSPVertex[numVerts];
	fseek(fin,lumps[kVertices].offset,SEEK_SET);
	fread(verts,numVerts,sizeof(q3BSPVertex),fin);


	int numFaces=lumps[kFaces].len/sizeof(q3BSPFace);
	faces=new q3BSPFace[numFaces];
	fseek(fin,lumps[kFaces].offset,SEEK_SET);
	fread(faces,numFaces,sizeof(q3BSPFace),fin);
	CnumFaces=numFaces;
	CnumVerts=numVerts;
	
	fclose(fin);
	return true;
}

void CBSP::DrawBSP()
{
	int i;
	
	glVertexPointer(3,GL_FLOAT,sizeof(q3BSPVertex),&(verts[0].pos));
	glEnableClientState(GL_VERTEX_ARRAY);

	q3BSPFace *face;
	for(i=0;i;
		glDrawArrays(GL_TRIANGLE_FAN, face->vertexIndex,face->numVerts);
	}
}




 
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
1) Make doubly sure that your structures are the same size and layout as the Q3 structures. (Check the Q3 tools source, maybe)

2) You can''t draw all the faces as triangle fans. That''s just the faces where type == 1. 2 (patches) ,3 (meshes), and 4(billboards) need to be drawn in different ways.
Advertisement
Well, it is a simple map that has nothing but faces of type 1. Just in case though I added the if statement and now I don''t get n e errors, but I c nothing. I looked at what was going on through the debugger and saw that on somethings the type was 0 or some crazy number like 126351223. I did check the structures and they are all correct.
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Your rendering code seems strange to me : you seem to iterate through the face array, but the "face" variable doesn't depend on "i". So it's likely you render the first face many times.

Your loop should contain something like :


q3BSPFace& face=faces; // Why use a ptr instead of a ref ?<br>glDrawArrays(GL_TRIANGLE_FAN, face.vertexIndex, face.numVerts);<br></code> <br><br>(edit) I realize your code might be OK ; seems the page interprets "" so your code doesn't show as it is…<br><br>Hmmm, you should also at least enable the color array. Enabling the vertex array &#111;nly will probably draw a whole lot of black polys. <br><br><SPAN CLASS=editedby>[edited by - rodzilla on July 25, 2003 12:11:02 AM]</SPAN>
SaM3d!, a cross-platform API for 3d based on SDL and OpenGL.The trouble is that things never get better, they just stay the same, only more so. -- (Terry Pratchett, Eric)
Ok, well I enabled the tex_coords array and then texture mapping and I still get nothing....
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.
Ok, got it. Not sure what the problem was. I just changed a whole bunch of stuff and now it works ty for the hlp
----------------------------------------------------"Plant a tree. Remove a Bush" -A bumper sticker I saw.

This topic is closed to new replies.

Advertisement