• Create Account

Banner advertising on our site currently available from just \$5!

# Problem rendering Quake 3 BSP files

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

15 replies to this topic

### #1Noah2033  Members   -  Reputation: 161

Like
0Likes
Like

Posted 17 February 2013 - 01:28 PM

Ok, so for the past week ive been working on a Quake 3 bsp veiwer this is what I have finished already

//standard librarys
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <sstream>

#include "sys_mem.h"
using namespace std;

#define SCREEN_WIDTH  640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP    32

#define MAX_FACES  10000
#define MAX_VERTS  100000

struct bspface
{
int textureID;           // The index into the texture array
int effect;              // The index for the effects (or -1 = n/a)
int type;                // 1=polygon, 2=patch, 3=mesh, 4=billboard
int vertexIndex;         // The index into this face's first vertex
int numOfVerts;          // The number of vertices for this face
int meshVertIndex;       // The index into the first meshvertex
int numMeshVerts;        // The number of mesh vertices
int lightmapID;          // The texture index for the lightmap
int lMapCorner[1];       // The face's lightmap corner in the image
int lMapSize[1];         // The size of the lightmap section
float lMapPos[2];        // The 3D origin of lightmap.
float lMapBitsets[1][2]; // The 3D space for s and t unit vectors.
float vNormal[2];        // The face normal.
int size[1];             // The bezier patch dimensions.
};

//

struct bspvertex
{
float position[2];      //x y z
float texturecoord[1];  //u, v texture coordinate
float lightmapcoord[1]; //u, v lightmap coordinate
float normal[2];        //x, y, z normalized vector
char  color[3];         //RGBA color for the vertex //char = byte?
};

struct bsplump
{
int offset;
int length;
};

struct bsp
{
bsplump   lumps[16];
bspvertex vertices[MAX_VERTS];
bspface   faces[MAX_FACES];
};

bsp bspbuffer;

bool running = true;  //if renderer is running
bool lightmaps;

void init()
{
glClearColor(0.0,0.0,0.0,1.0);            //Background color
glMatrixMode(GL_PROJECTION);
gluPerspective(45,640.0/480.0,1.0,500.0); //Perspective
glMatrixMode(GL_MODELVIEW);
glEnable(GL_CULL_FACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);

float light_0_amb[] = {0.2f, 0.2, 0.2};
glLightfv(GL_LIGHT0,GL_AMBIENT, light_0_amb);

float light_0_pos[] = {1.0,3.0,1.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_0_pos);

float light_0_dif[] = {1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_0_dif);

float light_0_spec[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0, GL_SPECULAR, light_0_spec);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glFlush();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //OpenGL's texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//RENDERLOOP

SDL_GL_SwapBuffers();
}

int main(int argc, char *argv[])
{
if(argv[1] == NULL)
cout << "ERROR: No bsp file used as an argument example \"./bsploader.x86 -map.bsp\"" << endl;
else
{
/*tolkenize argument*/
istringstream namebuffer(argv[1]);  //zero is ./bsploader
while (!namebuffer.eof())
{
string tolken;                      //tolken buffer
getline(namebuffer, tolken, '-' );  //split and store in tolken buffer
if(tolken != "")
{
}
}
do
{
SDL_Surface* screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE|SDL_OPENGL);
//Window           //Tab
Uint32 start;
init();
display();
SDL_Delay(1000/30);
}while(running);

}

return 0;
}

{
cout << "Loading BSP \"" << name << "\"" << endl;
ifstream bspfile;
bspfile.open (name.c_str(),ios::in|ios::binary);//Load BSP file into memory
if(bspfile == NULL)
cout << "ERROR: No file named \""<< name <<"\" found" << endl;
else
{
char magic[64];           //Number used in BSP header
bspfile.read(magic, 4);   //Read the magic number in the header of the BSP file it should be "IBSP"
if((magic[0] != 'I')||(magic[1] != 'B')||(magic[2] != 'S')||(magic[3] != 'P'))
{
cout << "ERROR: Not a valid Quake 3 BSP file" << endl;
}
else
{
int version;
if(version != 46)//46 = 0x2e in hexidecimal
cout << "ERROR: Unknown version of Quake 3 BSP" << endl;
else
{
for (int i = 0; i <= 16; i++)
{
cout << "Lump " << i << " offset is " << bspbuffer.lumps[i].offset << endl
<< "Lump " << i << " length is " << bspbuffer.lumps[i].length << endl << endl;
}
bspfile.seekg (bspbuffer.lumps[10].offset, ios::beg); //Load vertex data from vertex lump (10)
long readmemory = 0;

for (int j = 0; readmemory <= bspbuffer.lumps[10].length; j++)//Read until end of lump
{
//Actual vertexes

//U,V coordinates

//Lightmap U,V coordinates

//Normalized vertex coordinates

char buffer[64];
bspbuffer.vertices[j].color[0] = buffer[0];
bspbuffer.vertices[j].color[1] = buffer[1];
bspbuffer.vertices[j].color[2] = buffer[2];
bspbuffer.vertices[j].color[3] = buffer[3];
//10 floats 4 char so 10(4) + 4(1)
cout << ".";
}

bspfile.seekg (bspbuffer.lumps[13].offset, ios::beg); //Load face data from vertex lump (13)
long readmemory2 = 0;
for (int b = 0; readmemory2 <= bspbuffer.lumps[13].length; b++)//Read until end of lump
{
bspbuffer.faces[b].textureID     = readInt(bspfile); // The index into the texture array
bspbuffer.faces[b].effect        = readInt(bspfile); // The index for the effects (or -1 = n/a)
bspbuffer.faces[b].type          = readInt(bspfile); // 1=polygon, 2=patch, 3=mesh, 4=billboard
bspbuffer.faces[b].vertexIndex   = readInt(bspfile); // The index into this face's first vertex
cout << bspbuffer.faces[b].vertexIndex << endl;
bspbuffer.faces[b].numOfVerts    = readInt(bspfile); // The number of vertices for this face
bspbuffer.faces[b].meshVertIndex = readInt(bspfile); // The index into the first meshvertex
bspbuffer.faces[b].numMeshVerts  = readInt(bspfile); // The number of mesh vertices
bspbuffer.faces[b].lightmapID    = readInt(bspfile); // The texture index for the lightmap

bspbuffer.faces[b].lMapCorner[0] = readInt(bspfile); // The face's lightmap corner in the image
bspbuffer.faces[b].lMapCorner[1] = readInt(bspfile); // The face's lightmap corner in the image

bspbuffer.faces[b].lMapSize[0]   = readInt(bspfile); // The size of the lightmap section
bspbuffer.faces[b].lMapSize[1]   = readInt(bspfile); // The size of the lightmap section

bspbuffer.faces[b].lMapPos[0]    = readFloat(bspfile); // The 3D origin of lightmap.
bspbuffer.faces[b].lMapPos[1]    = readFloat(bspfile); // The 3D origin of lightmap.
bspbuffer.faces[b].lMapPos[2]    = readFloat(bspfile); // The 3D origin of lightmap.

bspbuffer.faces[b].lMapBitsets[0][0]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[0][1]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[0][2]  = readFloat(bspfile); // The 3D space for s and t unit vectors.

bspbuffer.faces[b].lMapBitsets[1][0]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[1][1]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[1][2]  = readFloat(bspfile); // The 3D space for s and t unit vectors.

bspbuffer.faces[b].vNormal[0]    = readFloat(bspfile); // The face normal.
bspbuffer.faces[b].vNormal[1]    = readFloat(bspfile); // The face normal.
bspbuffer.faces[b].vNormal[2]    = readFloat(bspfile); // The face normal.

bspbuffer.faces[b].size[0] = readInt(bspfile);            // The bezier patch dimensions.
bspbuffer.faces[b].size[1] = readInt(bspfile);             // The bezier patch dimensions.
//26(4)
}

cout << "Loaded" << endl;
}
}

}
}


the vertex information is mostly gibberish (as that two of the values are zero) Im aware that you have to use vertexIndex for the first vertex and put them into a triangle fan, but how?

### #2BGB  Crossbones+   -  Reputation: 1554

Like
0Likes
Like

Posted 17 February 2013 - 06:03 PM

me:
looks at struct definitions... "WTF?".

check array sizes.

### #3blueshogun96  Crossbones+   -  Reputation: 1665

Like
2Likes
Like

Posted 17 February 2013 - 11:18 PM

Instead of using triangle fans, you're better off using indexed triangles.  Not every Quake3 map will render properly if you use triangle fans.  I made the same mistake for ages and that's how I fixed my bogus vertex data problem.  My renderer is Direct3D based so it might not help much.  If you want it anyway, I can upload it and hopefully it will help.

Shogun.

Follow Shogun3D on the official website: http://shogun3d.net

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

### #4BornToCode  Members   -  Reputation: 1015

Like
0Likes
Like

Posted 18 February 2013 - 11:41 AM

You have buffer overflow in your structure.

Edited by BornToCode, 18 February 2013 - 11:41 AM.

### #5Noah2033  Members   -  Reputation: 161

Like
0Likes
Like

Posted 18 February 2013 - 11:59 AM

blueshogun96  that would be aprecciated. BornToCode how would I fix that? here is my updated code
//standard librarys
#include <SDL/SDL.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <sstream>

#include "sys_mem.h"
using namespace std;

#define SCREEN_WIDTH  640
#define SCREEN_HEIGHT 480
#define SCREEN_BPP    32

#define MAX_FACES  10000
#define MAX_VERTS  100000

struct bspface
{
int textureID;           // The index into the texture array
int effect;              // The index for the effects (or -1 = n/a)
int type;                // 1=polygon, 2=patch, 3=mesh, 4=billboard
int vertexIndex;         // The index into this face's first vertex
int numOfVerts;          // The number of vertices for this face
int meshVertIndex;       // The index into the first meshvertex
int numMeshVerts;        // The number of mesh vertices
int lightmapID;          // The texture index for the lightmap
int lMapCorner[1];       // The face's lightmap corner in the image
int lMapSize[1];         // The size of the lightmap section
float lMapPos[2];        // The 3D origin of lightmap.
float lMapBitsets[1][2]; // The 3D space for s and t unit vectors.
float vNormal[2];        // The face normal.
int size[1];             // The bezier patch dimensions.
};

//

struct bspvertex
{
float position[3];      //x y z
float texturecoord[2];  //u, v texture coordinate
float lightmapcoord[2]; //u, v lightmap coordinate
float normal[3];        //x, y, z normalized vector
char  color[4];         //RGBA color for the vertex //char = byte?
};

struct bsplump
{
int offset;
int length;
};

struct bsp
{
bsplump   lumps[16];
bspvertex vertices[MAX_VERTS];
bspface   faces[MAX_FACES];
};

bsp bspbuffer;

bool running = true;  //if renderer is running
bool lightmaps;

void init()
{
glClearColor(0.0,0.0,0.0,1.0);            //Background color
glMatrixMode(GL_PROJECTION);
gluPerspective(45,640.0/480.0,1.0,500.0); //Perspective
glMatrixMode(GL_MODELVIEW);
glEnable(GL_CULL_FACE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_COLOR_MATERIAL);

float light_0_amb[] = {0.2f, 0.2, 0.2};
glLightfv(GL_LIGHT0,GL_AMBIENT, light_0_amb);

float light_0_pos[] = {1.0,3.0,1.0};
glLightfv(GL_LIGHT0, GL_POSITION, light_0_pos);

float light_0_dif[] = {1.0,1.0,1.0,0.0};
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_0_dif);

float light_0_spec[] = {1.0, 1.0, 1.0, 0.0};
glLightfv(GL_LIGHT0, GL_SPECULAR, light_0_spec);
}

void display()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glFlush();

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //OpenGL's texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

//RENDERLOOP

SDL_GL_SwapBuffers();
}

int main(int argc, char *argv[])
{
if(argv[1] == NULL)
cout << "ERROR: No bsp file used as an argument example \"./bsploader.x86 -map.bsp\"" << endl;
else
{
/*tolkenize argument*/
istringstream namebuffer(argv[1]);  //zero is ./bsploader
while (!namebuffer.eof())
{
string tolken;                      //tolken buffer
getline(namebuffer, tolken, '-' );  //split and store in tolken buffer
if(tolken != "")
{
}
}
do
{
SDL_Surface* screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE|SDL_OPENGL);
//Window           //Tab
Uint32 start;
init();
display();
SDL_Delay(1000/30);
}while(running);

}

return 0;
}

{
cout << "Loading BSP \"" << name << "\"" << endl;
ifstream bspfile;
bspfile.open (name.c_str(),ios::in|ios::binary);//Load BSP file into memory
if(bspfile == NULL)
cout << "ERROR: No file named \""<< name <<"\" found" << endl;
else
{
char magic[64];           //Number used in BSP header
bspfile.read(magic, 4);   //Read the magic number in the header of the BSP file it should be "IBSP"
if((magic[0] != 'I')||(magic[1] != 'B')||(magic[2] != 'S')||(magic[3] != 'P'))
{
cout << "ERROR: Not a valid Quake 3 BSP file" << endl;
}
else
{
int version;
if(version != 46)//46 = 0x2e in hexidecimal
cout << "ERROR: Unknown version of Quake 3 BSP" << endl;
else
{
for (int i = 0; i <= 16; i++)
{
cout << "Lump " << i << " offset is " << bspbuffer.lumps[i].offset << endl
<< "Lump " << i << " length is " << bspbuffer.lumps[i].length << endl << endl;
}
bspfile.seekg (bspbuffer.lumps[10].offset, ios::beg); //Load vertex data from vertex lump (10)
long readmemory = 0;

for (int j = 0; j <= bspbuffer.lumps[10].length/sizeof(bspvertex); j++)//Read until end of lump
{
//Actual vertexes

//U,V coordinates

//Lightmap U,V coordinates

//Normalized vertex coordinates

char buffer[64];
bspbuffer.vertices[j].color[0] = buffer[0];
bspbuffer.vertices[j].color[1] = buffer[1];
bspbuffer.vertices[j].color[2] = buffer[2];
bspbuffer.vertices[j].color[3] = buffer[3];
//10 floats 4 char so 10(4) + 4(1)
cout << bspbuffer.vertices[j].position[0] << bspbuffer.vertices[j].position[1] << bspbuffer.vertices[j].position[2] << endl;
}
cout << "Lump 10 loaded" << endl;
bspfile.seekg (bspbuffer.lumps[13].offset, ios::beg); //Load face data from vertex lump (13)
long readmemory2 = 0;
for (int b = 0; readmemory2 <= bspbuffer.lumps[13].length; b++)//Read until end of lump
{
bspbuffer.faces[b].textureID     = readInt(bspfile); // The index into the texture array
bspbuffer.faces[b].effect        = readInt(bspfile); // The index for the effects (or -1 = n/a)
bspbuffer.faces[b].type          = readInt(bspfile); // 1=polygon, 2=patch, 3=mesh, 4=billboard
bspbuffer.faces[b].vertexIndex   = readInt(bspfile); // The index into this face's first vertex
bspbuffer.faces[b].numOfVerts    = readInt(bspfile); // The number of vertices for this face
bspbuffer.faces[b].meshVertIndex = readInt(bspfile); // The index into the first meshvertex
bspbuffer.faces[b].numMeshVerts  = readInt(bspfile); // The number of mesh vertices
bspbuffer.faces[b].lightmapID    = readInt(bspfile); // The texture index for the lightmap

bspbuffer.faces[b].lMapCorner[0] = readInt(bspfile); // The face's lightmap corner in the image
bspbuffer.faces[b].lMapCorner[1] = readInt(bspfile); // The face's lightmap corner in the image

bspbuffer.faces[b].lMapSize[0]   = readInt(bspfile); // The size of the lightmap section
bspbuffer.faces[b].lMapSize[1]   = readInt(bspfile); // The size of the lightmap section

bspbuffer.faces[b].lMapPos[0]    = readFloat(bspfile); // The 3D origin of lightmap.
bspbuffer.faces[b].lMapPos[1]    = readFloat(bspfile); // The 3D origin of lightmap.
bspbuffer.faces[b].lMapPos[2]    = readFloat(bspfile); // The 3D origin of lightmap.

bspbuffer.faces[b].lMapBitsets[0][0]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[0][1]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[0][2]  = readFloat(bspfile); // The 3D space for s and t unit vectors.

bspbuffer.faces[b].lMapBitsets[1][0]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[1][1]  = readFloat(bspfile); // The 3D space for s and t unit vectors.
bspbuffer.faces[b].lMapBitsets[1][2]  = readFloat(bspfile); // The 3D space for s and t unit vectors.

bspbuffer.faces[b].vNormal[0]    = readFloat(bspfile); // The face normal.
bspbuffer.faces[b].vNormal[1]    = readFloat(bspfile); // The face normal.
bspbuffer.faces[b].vNormal[2]    = readFloat(bspfile); // The face normal.

bspbuffer.faces[b].size[0] = readInt(bspfile);            // The bezier patch dimensions.
bspbuffer.faces[b].size[1] = readInt(bspfile);             // The bezier patch dimensions.
//26(4)
cout << ".";
}
cout << "Lump 13 loaded" << endl;
}
}

}
}


### #6mhagain  Crossbones+   -  Reputation: 9618

Like
0Likes
Like

Posted 18 February 2013 - 07:59 PM

Maybe have a look at the Quake 3 code itself?  https://github.com/id-Software/Quake-III-Arena

Going through the BSP loading and drawing code may give you a few hints and save you a whole heap of pain and frustration.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.

### #7blueshogun96  Crossbones+   -  Reputation: 1665

Like
0Likes
Like

Posted 21 February 2013 - 08:59 PM

blueshogun96  that would be aprecciated.

Sorry for the slow response, my regular job has me working nights so I find myself sleeping all day... (I'm at work now) \/_\/

I'll upload it when I get home, but it wasn't until I found this link it made sense (Direct3D wise): http://www.xbdev.net/3dformats/quake3bsp/index.php

IIRC, this one also renders BSPs the proper way and uses OpenGL, but it's a bit more complex: http://www.paulsprojects.net/opengl/q3bsp/q3bsp.html

Hope this helps,

Shogun.

Follow Shogun3D on the official website: http://shogun3d.net

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

### #8BornToCode  Members   -  Reputation: 1015

Like
0Likes
Like

Posted 22 February 2013 - 01:06 AM

What i mean is that in your structure for normal for example. Normal cosist of xyz which is 3 elements but your array is using 2 elements for bspface.

### #9Noah2033  Members   -  Reputation: 161

Like
0Likes
Like

Posted 25 February 2013 - 06:31 AM

blueshogun96 thanks,  BornToCode an array starts at zero so 0,1,2.          mhagain ok, I will start reading Idtech 3's source code, I have read quake, and quake2's have a fairly good understanding of them

### #10BornToCode  Members   -  Reputation: 1015

Like
2Likes
Like

Posted 26 February 2013 - 11:45 AM

blueshogun96 thanks,  BornToCode an array starts at zero so 0,1,2.          mhagain ok, I will start reading Idtech 3's source code, I have read quake, and quake2's have a fairly good understanding of them

That is what your index needs to say 3 index 0 1 and 2 are used. When you create an array with one element you do not say int Array[0] you say int Array[1] and you use only used index 0. So if you have x y and z then your Array needs to be defined as int Array[3] not int Array[2]. Look at your code in your bspface you have float vNormal[2];

vNormal supposed to have xyz which means vNormal needs to be [3] not [2]

Edited by BornToCode, 26 February 2013 - 11:49 AM.

### #11blueshogun96  Crossbones+   -  Reputation: 1665

Like
0Likes
Like

Posted 27 February 2013 - 06:48 AM

I attached the source file I used to render .bsp files.  It's a heavily modified version of the one from gametutorials.com.  I modified it to use Direct3D9 and use triangle lists instead of fans.  Maybe I should have included the entire project source.  If you need it, I'll upload that too.

So far, my BSP loader is the only one I've ever seen render the Simpsons Q3 map correctly (besides Q3 itself), which is the most complex Q3 map I've seen to date.  Hopefully this helps.

Shogun.

PS: Be warned, it's messy!

#### Attached Files

Edited by blueshogun96, 27 February 2013 - 06:49 AM.

Follow Shogun3D on the official website: http://shogun3d.net

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

### #12Noah2033  Members   -  Reputation: 161

Like
0Likes
Like

Posted 28 February 2013 - 06:25 PM

Ok thanks borntocode I was unaware of this. Thanks blueshotgun, Have you actually implemented the PVS system? (like paulsprojects)

### #13blueshogun96  Crossbones+   -  Reputation: 1665

Like
0Likes
Like

Posted 04 March 2013 - 01:34 PM

Ok thanks borntocode I was unaware of this. Thanks blueshotgun, Have you actually implemented the PVS system? (like paulsprojects)

PVS system?  I'm sorry, what does that mean?  The only thing I used from paulsprojects is his patch rendering code.  My D3D implementation isn't very efficient since it uses D3DDevice::DrawIndexedPrimitiveUP every frame N times per tessellation, but it works.

Btw, my nickname is blueshogun, not blueshotgun.  No worries, happens all the time.

Shogun.

Follow Shogun3D on the official website: http://shogun3d.net

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

### #14BornToCode  Members   -  Reputation: 1015

Like
0Likes
Like

Posted 04 March 2013 - 03:35 PM

Ok thanks borntocode I was unaware of this. Thanks blueshotgun, Have you actually implemented the PVS system? (like paulsprojects)

PVS system?  I'm sorry, what does that mean?  The only thing I used from paulsprojects is his patch rendering code.  My D3D implementation isn't very efficient since it uses D3DDevice::DrawIndexedPrimitiveUP every frame N times per tessellation, but it works.

Btw, my nickname is blueshogun, not blueshotgun.  No worries, happens all the time.

Shogun.

PVS=Potensial visibility set. It is a system used in an BSP tree that does Occlusion.

Edited by BornToCode, 04 March 2013 - 03:37 PM.

### #15blueshogun96  Crossbones+   -  Reputation: 1665

Like
0Likes
Like

Posted 06 March 2013 - 04:08 PM

Ok thanks borntocode I was unaware of this. Thanks blueshotgun, Have you actually implemented the PVS system? (like paulsprojects)

PVS system?  I'm sorry, what does that mean?  The only thing I used from paulsprojects is his patch rendering code.  My D3D implementation isn't very efficient since it uses D3DDevice::DrawIndexedPrimitiveUP every frame N times per tessellation, but it works.

Btw, my nickname is blueshogun, not blueshotgun.  No worries, happens all the time.

Shogun.

PVS=Potensial visibility set. It is a system used in an BSP tree that does Occlusion.

Oh, now I remember.  Yeah, my code does support PVS.  IIRC, it supports everything except billboards and Q3 shaders.  Everything else works, but my beizer patch code isn't perfect because I screwed up the fragment colour thing.

Shogun

Follow Shogun3D on the official website: http://shogun3d.net

"Yo mama so fat, she can't be frustum culled." - yoshi_lol

"One objection to a “critique of C#” would be that you can’t talk about C# without talking about the whole “.Net experience”. However, one can approach the topic of Hitler without a complete discussion of Nationalist Socialism, so I feel justified." - Steve White.

### #16Noah2033  Members   -  Reputation: 161

Like
0Likes
Like

Posted 10 April 2013 - 06:15 PM

Ok guys (blueshogun96 BornToCode mhagain) I read the xbox dev tutorial. Then I worked on it a week got frustrated and then started working on other parts of my engine instead (Finished normal mapping )

anyway I started working on it a week ago and just got it working but now faces wont render correctly.

http://postimg.org/image/o2lf8vlp9/ Here are the vertices for a map

and here's what happens when I render faces on a map

http://postimg.org/image/6hmoht7ep/

here's the code to it

#include <stdio.h>
#include <cstdio>
#include <string>
#include <algorithm>
#include <fstream>
#include <cstdio>
#include <iostream>
#include <stdlib.h>
#include <sstream>
#include <GL/GL.h>
#include <SDL/SDL.h>

#include <assert.h>

#include "sys_mem.h"
using namespace std;

int SCREEN_WIDTH = 640;
int SCREEN_HEIGHT = 480;
int SCREEN_BPP = 24;
bool running = true;
bool lightmaps;
SDL_Event event;

#define MAX_BRUSHES   10000
#define MAX_FACES     10000
#define MAX_VERTS     10000000
#define MAX_TEXTURES  1000

struct bspface
{
int   textureid;        // The index into the texture array
int   effect;           // The index for the effects (or -1 = n/a)
int   type;             // 1=polygon, 2=patch, 3=mesh, 4=billboard
int   vertexindex;      // The index into this face's first vertex
int   numofverts;       // The number of vertices for this face
int   meshvertindex;    // The index into the first meshvertex
int   nummeshverts;     // The number of mesh vertices
int   lightmapid;       // The texture index for the lightmap
int   lmapcorner[2];    // The face's lightmap corner in the image
int   lmapsize[2];      // The size of the lightmap section
float lmappos[3];     // The 3D origin of lightmap.
float lmapbitsets[2][3]; // The 3D space for s and t unit vectors.
float vnormal[3];     // The face normal.
int   size[2];          // The bezier patch dimensions.
};

struct bspvertex
{
float position[3];      //x y z
float texturecoord[2];  //u, v texture coordinate
float lightmapcoord[2]; //u, v lightmap coordinate
float normal[3];        //x, y, z normalized vector
char  color[4];         //RGBA color for the vertex
};

struct bsptexture
{
char name[64];      // The name of the texture w/o the extension
int flags;          // The surface flags (unknown)
int contents;       // The content flags (unknown)
};

struct bspbrush
{
int brushSide;           // The starting brush side for the brush
int numofbrushsides;     // Number of brush sides for the brush
int textureid;           // The texture index for the brush
};

struct bsplump
{
int offset;
int length;
};

class bsp
{
public:
ifstream    bspfile;
bsplump     lumps[16];
char        entities[10000];
bspvertex   vertices[MAX_VERTS];
bspface     faces[MAX_FACES];
bsptexture  textures[MAX_TEXTURES];
bspbrush    brushs[MAX_BRUSHES];
void render();
};

{
cout << "Loading BSP \"" << name << "\"" << endl;
bsp::bspfile.open (name.c_str(), istream::binary);
if(bsp::bspfile == NULL)
cout << "ERROR: No file named \""<< name <<"\" found" << endl;
else
{
char magic[64];           //Number used in BSP header
bsp::bspfile.read(magic, 4);   //Read the magic number in the header of the BSP file it should be "IBSP"
if((magic[0] != 'I')||(magic[1] != 'B')||(magic[2] != 'S')||(magic[3] != 'P'))
{
cout << "ERROR: Not a valid Quake 3 BSP file" << endl;
}
else
{
int version;
if(version != 46)//46 = 0x2e in hexidecimal
cout << "ERROR: Unknown version of Quake 3 BSP" << endl;
else
{
for (int i = 0; i <= 16; i++)
{
cout << "Lump " << i << " offset is " << bsp::lumps[i].offset << endl
<< "Lump " << i << " length is " << bsp::lumps[i].length << endl << endl;
}

//Load entities (LUMP 0)
bsp::bspfile.seekg (bsp::lumps[0].offset, ios::beg);

//Load textures	(LUMP 1)
bsp::bspfile.seekg (bsp::lumps[1].offset, ios::beg); //Load face data from vertex lump (13)
for (int j = 0; j <= bsp::lumps[1].length/sizeof(bsptexture); j++)//Read until end of lump
{
char buffer[72];

for (int k = 0; k <= 71; k++)//Read until end of lump
{
((char*)&bsp::textures[j])[k] = buffer[k];
}
}

//Load vertices (LUMP 10)
bsp::bspfile.seekg (bsp::lumps[10].offset, ios::beg); //Load vertex data from vertex lump (10)
for (int j = 0; j <= bsp::lumps[10].length/sizeof(bspvertex); j++)//Read until end of lump
{
char buffer[44];           //create buffer for verts
for (int k = 0; k <= 43; k++)//Read until end of lump
{
((char*)&bsp::vertices[j])[k] = buffer[k];
}
}

//Load faces (LUMP 13)
bsp::bspfile.seekg (bsp::lumps[13].offset, ios::beg); //Load vertex data from vertex lump (10)
for (int j = 0; j <= bsp::lumps[13].length/sizeof(bspface); j++)//Read until end of lump
{
char buffer[104];           //create buffer for verts
for (int k = 0; k <= 103; k++)//Read until end of lump
{
((char*)&bsp::faces[j])[k] = buffer[k];
}
}

cout << "Lump 13 loaded" << endl;
}
}

}
}
//glVertex3f(bspbuffer.vertices[j].position[0], bspbuffer.vertices[j].position[1], bspbuffer.vertices[j].position[2]);
void bsp::render()
{
for (int j = 0; j <= bsp::lumps[13].length/sizeof(bspface); j++)//Read until end of lump
{
if ((bsp::faces[j].type == 1)||(bsp::faces[j].type == 3))       // 1=polygon, 2=patch, 3=mesh, 4=billboard
{
glFrontFace(GL_CW);
glBegin(GL_TRIANGLE_STRIP);
//cout << bsp::faces[j].vertexindex << " " << bsp::faces[j].numofverts <<endl;
for (int k = 0; k <=  bsp::faces[j].numofverts - 1; k++)//Read until end of lump
{
//cout<< " " <<bsp::faces[j].vertexindex+k << " vertex" << endl;
glVertex3f(bsp::vertices[bsp::faces[j].vertexindex+k].position[0], bsp::vertices[bsp::faces[j].vertexindex+k].position[1], bsp::vertices[bsp::faces[j].vertexindex+k].position[2]);
}
glEnd();

}
}
}

bsp bspbuffer;

bool initGL()
{
//Initialize Projection Matrix
glMatrixMode( GL_PROJECTION );
//Initialize Modelview Matrix
glMatrixMode( GL_MODELVIEW );
//Initialize clear color
glClearColor( 0.f, 0.f, 0.f, 1.f );

//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
return true;
}

float angle;
void render()
{
angle = angle + 1;
glPushMatrix();
//Clear color buffer
glClear( GL_COLOR_BUFFER_BIT );
glPointSize(5.0);
glRotatef(angle,1,1,1);
glScalef(.002,.002,.002);
bspbuffer.render();
//Update screen
glPopMatrix();
SDL_GL_SwapBuffers();

//While there are events to handle
while( SDL_PollEvent( &event ) )
{
if(event.type == SDL_QUIT)
{
running = false;
exit(0);
}
}
SDL_Delay( 1000 / 30 );
}

bool init()
{

//Initialize SDL
if( SDL_Init( SDL_INIT_EVERYTHING ) < 0 )
{
return false;
}
//Create Window
if( SDL_SetVideoMode( SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_BPP, SDL_OPENGL ) == NULL )
{
return false;
}
//Initialize OpenGL
if( initGL() == false )
{
return false;
} //Set caption
SDL_WM_SetCaption( "OpenGL BSP", NULL );
return true;
}

#undef main
int main()
{
init();
do
{
render();
}while(running);
return 0;
}//End main()



Edited by industrialgrok, 10 April 2013 - 07:04 PM.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS