# BSP version 30 Rendering

## Recommended Posts

Hi, I'm writing a new geometry loader for my 3D engine that loads in half-life 1 BSPs which are BSP version 30. I downloaded the SDK and have gotten the file reading into the proper data structures. Now the issue I have come to is figuring out how to efficiently render using the data I have. Right now I'm not worrying about the leafs or anything, I'm just trying to render all the geometry every frame. So I start with the faces, each face as a "firstEdge" which is an index into the edge array, and a "numEdges" which is the number of consecutive edges in the edge array. Now each edge is simply a struct containing an array of 2 integers, which are indices into the vertex array, to two different vertices which make up 1 edge. So how do I put these into a GLvertex array? Right now I'm doing:
// vertices is an array of BSPVertex structs
glVertexPointer(3, GL_FLOAT, sizeof(BSPVertex), vertices);


then each frame i do:
for(int i=0; i<numFaces; ++i)
glDrawArrays(GL_TRIANGLE_FAN, faces[faceIndex].firstEdge, faces[faceIndex].numEdges);


But the resulting geometry is uber fucked. So any ideas? I mean are these "edges" even what I'm suppose to be using to get my indices to vertices for rendering? I did a bit of work with the quake 3 BSP format and each face just had a startIndex, and numIndex, so you could go straight to the vertex array from the face. But I don't see any thing else that stores the actual indices into the vertex array... [Edited by - Wavesonics on April 29, 2006 1:22:36 PM]

##### Share on other sites
Sigh... Obviously to use vertex arrays you must have polygons set up in the vertex array so their vertices are consecutive, and how this appears, is the faces hold an index into a surface edge array, who's elements just hold an index into the edge array. Edges hold indices to two vertices that are almost never consecutive. It seems like the vertex array is assembled arbitrarily and then only made sense out of through the edge's indices into it.

How I understand it is it describes pollygons by giving the 2 vertices that make up an edge, and it does this fir every edge the polygon has. So how in the hell do I make use of this with vertex arrays, or do I need to do something with display lists instead...

Heres some of the structs I made from looking at the HL SDK:

// This is our BSP face structuretypedef struct{    unsigned __int16 plane;            // index of the plane the face is parallel to    unsigned __int16 planeSide;        // set if the normal is parallel to the plane normal    unsigned __int32 firstEdge;        // index of the first edge (in the face edge array)    unsigned __int16 numEdges;         // number of consecutive edges (in the face edge array)    unsigned __int16 textureInfo;       // index of the texture info structure    unsigned __int8 lightMapstyles[4]; // styles, bit flags    unsigned __int32 lightMapOffset;    // Offsets the lightmap} BSPFace;

// This is our BSP edge structtypedef struct{	unsigned __int16	v[2];		// vertex numbers} BSPEdge;

This is a vertex. CVector3 is just a struct that holds 3 flots
// This is our BSP vertex structuretypedef struct{    CVector3 coordinate;			// (x, y, z) position} BSPVertex;

I have some debug output writing to a file, this is produced after everything has been read into the data structurs:
Quote:
 //==================================// Black Engine: -= 3dpoints.txt =-//// Description:// ---------------// This textfile was created by// traversing// [BSPFace] // in BSPLoader.cpp//// [.bsp used]: "maps/q2/triangle.bsp"//==================================Header: version- 30numFaces: 10numEdges: 19numVerts: 6Face # Info-+-+-+- -+-+-+-+-+-Face 1 NumOfEdges: 4 FirstEdge: 0 Edge[0]: 0 Edge[1]: 0 Face 2 NumOfEdges: 4 FirstEdge: 4 Edge[0]: 3 Edge[1]: 0 Face 3 NumOfEdges: 4 FirstEdge: 8 Edge[0]: 0 Edge[1]: 3 Face 4 NumOfEdges: 4 FirstEdge: 12 Edge[0]: 1 Edge[1]: 5 Face 5 NumOfEdges: 3 FirstEdge: 16 Edge[0]: 4 Edge[1]: 3 Face 6 NumOfEdges: 3 FirstEdge: 19 Edge[0]: 0 Edge[1]: 0 Face 7 NumOfEdges: 3 FirstEdge: 22 Edge[0]: 0 Edge[1]: 16256 Face 8 NumOfEdges: 3 FirstEdge: 25 Edge[0]: 0 Edge[1]: 16256 Face 9 NumOfEdges: 4 FirstEdge: 28 Edge[0]: 0 Edge[1]: 16256 Face 10 NumOfEdges: 4 FirstEdge: 32 Edge[0]: 0 Edge[1]: 0 -+-+-+-+ -+-+-+-+-+-

The vertex indicies stored in edge[0] and edge[1] seem to get a bit fucked, the BSP has 19 edges but some of the "firstEdge"s have much higher indices into the edge array, so I do a check to see if the "firstEdge" index is <= numEdges so as to avoid trying to render those fucked up edgges. Thats another problem I'll have to look into at some point.

[Edited by - Wavesonics on April 29, 2006 2:17:16 PM]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627708
• Total Posts
2978730

• 21
• 14
• 12
• 22
• 35