Advertisement Jump to content
Sign in to follow this  

BSP render!!!

This topic is 4963 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

Hi, First of all, sorry for my english, Im from Madrid :-). Im trying to render BSP map. The problem comes when i try to render it. I dont want to use nodes and lefs for the moment. First i want to know if everything that i did before was good. So now i want to render bsp with the fastest(writting code) way. I saw two ways of do that. A)With glDrawArrays void render() { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(tBSPVertex), &(sMBSP.BSPVertex[0].vPosition)); glTexCoordPointer(2, GL_FLOAT, sizeof(tBSPVertex), &(sMBSP.BSPVertex[0].vTextureCoord)); int nfaces = matConstTam[12][1]; //number of faces while(nfaces--) { if(sMBSP.BSPFace[nfaces].type != 1) continue; //only normal poly tBSPFace *pFace = &sMBSP.BSPFace[faceIndex]; glBindTexture(GL_TEXTURE_2D, todas_texturas[pFace->textureID]); glDrawArrays(GL_TRIANGLE_FAN, pFace->vertexIndex, pFace->numOfVerts); } } B)Inside de while tBSPFace *pFace = &sMBSP.BSPFace[faceIndex]; glBindTexture(GL_TEXTURE_2D, todas_texturas[pFace->textureID]); glBegin( GL_TRIANGLE_FAN); int verts = pFace->vertexIndex; for(int k=0; k < pFace->numOfVerts; k++) { glTexCoord2f(sMBSP.BSPVertex[k + verts].vTextureCoord.u, sMBSP.BSPVertex[k + verts].vTextureCoord.v); glVertex3f(sMBSP.BSPVertex[k + verts].vPosition.x, sMBSP.BSPVertex[k + verts].vPosition.y, sMBSP.BSPVertex[k + verts].vPosition.z); } glEnd; Neither of them works. The result is horrible, infinite polys, strange structures and it should be a simple room. I have seen other fast ways in internet using meshvert, but i dont understand it very well. Anyone can help me? Thank a lot.

Share this post

Link to post
Share on other sites
You might want to check if you loaded your data correctly from file. Maybe something is wrong there. I assume that all the vertex and texture coordinates are in one array. What is the way you structure your data? if it a simple structure with 2 float arrays?

Plus, this isn't realy the fastest way to render your world, but it works for quick and dirty rendering. For a bit faster display, you should sort and batch the faces and render them per texture. This is more optimal for the hardware, and results in much beter performance.

Share this post

Link to post
Share on other sites
Some structs doesnt have the correct size to loading the bsp map.
So i have created constants.

#define VERTEX_SIZE 44
#define FACE_SIZE 104
#define TEXTURE_SIZE 72

struct tBSPVertex
tvector vPosition; //tvector 3 float x, y, z
tvector2 vTextureCoord; //tvector2 2 float u, v
tvector2 vLightmapCoord;
tvector vNormal;
int color[4];

struct tBSPFace
int textureID;
int effect;
int type;
int vertexIndex;
int numOfVerts;
int meshVertIndex;
int numMeshVerts;
int lightmapID;
int lMapCorner[2];
int lMapSize[2];
tvector lMapPos;
tvector lMapBitsets[2];
tvector vNormal;
int size[2];


struct tBSPTexture
char strName[64];
int flags;
int contents;

I extracted all the vertex, texture and face into a file and i compared it with other bsp render tht works, line per line a i couldnt see nothing diferent.

I know that this isn´t the fastest way, but is temporal, for the moment i only want to know if everyting that i did before was good. After that i´ll optimize my code.


Share this post

Link to post
Share on other sites
Problem solved, thanks.

Fist i changed the algoritm for this:

tBSPFace *pFace = &sMBSP.BSPFace[faceIndex];

glBindTexture(GL_TEXTURE_2D, todas_texturas[pFace->textureID]);

glBegin( GL_TRIANGLES );
for( int j=0; j < pFace->numMeshVerts; j++)
int offset = sMBSP.BSPMeshVerts[pFace->meshVertIndex+j].pMeshVerts + pFace->vertexIndex;

glVertex3f( sMBSP.BSPVertex[offset].vPosition.x,


And i had to divide every vertex by a constant, if i dont do this i cant see the map.


Now de vertex are printed correctly.

But now i have other problem. The textures. I know that have loaded it correctly because i printed a single triangle manally with a texture and i could see perfect.

The map seems to load the texture but it seems like the texture coords arent correctly assigned to gltextcoord;

Any idea?


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!