Sign in to follow this  
canond

Rendering the quake 1 bsp format

Recommended Posts

I'm working my way up so I'm starting using the old Quake 1 .bsp format. Using the references online, I was able to load it up but I'm not sure what type of polygon I'm supposed to be rendering it in. When using lines it works, but of course I dont want just lines. For now I'm just rendering the entire seen and will use the PVS later on. My rendering loop looks something like:
for(int x = 0; x < bsp->numFaces; ++x){
	glColor3f( (float)x / bsp->numFaces, (float)x / bsp->numFaces, (float)x / bsp->numFaces);
	// No texturing for now.
	
	int reverse = 0;
	if(bsp->listOfEdges[ bsp->faces[x].firstEdge ] < 0){ 
		//		Reverse the order. Go from Vertex 1 to 0, instead of 0 to 1
		reverse = 1;
	}
	
	int numEdges = bsp->faces[x].numEdges;
	if(numEdges == 4){
		glBegin(GL_QUADS);
	} else if(numEdges == 3){
		glBegin(GL_TRIANGLES);		
	} else {
		glBegin(GL_POLYGON);
	}

	for(int i = 0; i < numEdges; i++){
		int temp = abs(bsp->listOfEdges[ bsp->faces[x].firstEdge + i]);
		BSPVertex *vertex1;
		BSPVertex *vertex2;
		
		if(reverse){
			vertex1 = &bsp->vertices[ bsp->edges[ temp ].edgeIndices[1] ];
			vertex2 = &bsp->vertices[ bsp->edges[ temp ].edgeIndices[0] ];
		} else {
			vertex1 = &bsp->vertices[ bsp->edges[ temp ].edgeIndices[0] ];
			vertex2 = &bsp->vertices[ bsp->edges[ temp ].edgeIndices[1] ];
		}
		glVertex3f(vertex1->x, vertex1->y, vertex1->z);
		glVertex3f(vertex2->x, vertex2->y, vertex2->z);
	}

	glEnd();
}


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