Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Noah2033

Member Since 17 Feb 2013
Offline Last Active Sep 19 2013 09:22 PM

Posts I've Made

In Topic: Loading Quake 2 BSP vis data

19 June 2013 - 09:00 PM

code for vis is now

				bsp::bspfile.seekg (bsp::lumps[3].offset, ios::beg); //Load vertex data from vertex lump (10)
                unsigned int nclusters;
				char buffer[8];           //create buffer for verts    
                bsp::bspfile.read(buffer, 4);   //Read
				for (int k = 0; k <= 3; k++)
                   {
                    ((char*)&nclusters)[k] = buffer[k];
                   }
				cout << nclusters << endl; //189
				bspvis visarray[200];
				for (int v = 0; v <=  nclusters - 1; v++)
				    {
                     bsp::bspfile.seekg (bsp::lumps[3].offset + 4 + (v * 8), ios::beg);
					 cout << v << endl;
				     bsp::bspfile.read(buffer, 8);
                     for (int k = 0; k <= 7; k++)//Read until end of lump
                        {
                         ((char*)&visarray[v])[k] = buffer[k];
                        }	
				     cout << visarray[v].pvs << endl; 
					 char vis[6];
					 bsp::bspfile.seekg (bsp::lumps[3].offset + visarray[v].pvs, ios::beg);
					 bsp::bspfile.read(vis, 8);   //Read
		             bitset<8> x;
					 for(int b = 0; b <= ceil(nclusters/8); b++)
					 {
					  x = vis[b];
					  cout << x ;
					 }
					 cout << endl << endl;
                     //bsp::bspfile.seekg (bsp::lumps[3].offset + visarray[v].pvs, ios::beg);
				 
                    }

here's the output

00101000010000110000000000000000

140
4236
00000000000001000111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

141
4259
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

142
4282
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

143
4305
00000000000001000111000001111110011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

144
4328
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

145
4351
01100000100111010000001011100001111111000111111101111111011110010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

146
4376
00100000100111010000001011100001111111000111111101111111000000000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

147
4393
01100000100111110000001011100001111111000111111101111111000000000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

148
4415
00000000000001001111000001111111011111110001000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

149
4438
00000000000001001111000001111111011111110000000000000011000100000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

150
4458
01100000100111010000001011100001111111000111111101111111000100010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

151
4483
00000000000100101000000010000000000001010000000000000001100000000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

152
4492
00000000000001001111000001111111011111110101000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

153
4516
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

154
4543
00000000000001001111000001111111011111110101000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

155
4566
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

156
4592
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

157
4618
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

158
4644
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

159
4670
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

160
4696
00000000000001110110000000000000000000101111000101101101110100000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

161
4715
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

162
4741
00000000000001110110000000000000000000101111000101101101110100000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

163
4760
00000000000001001111000001111110111111110111111100000101110101000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

164
4782
00000000000000011000000000000010010000001111000001111111111111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

165
4807
00000000000001000011000000010010010010000111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

166
4831
00000000000001000111000001111110011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

167
4855
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

168
4881
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

169
4907
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

170
4930
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

171
4956
00000000000001000011000000010010000010000111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

172
4980
00000000000001000011000000010010010010000000000000001000111000000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

173
4996
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

174
5020
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

175
5044
00000000000001001111000001111111011111110000000000000100010000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

176
5064
00000000000001001111000001111111011111110000000000000111010010000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

177
5081
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

178
5107
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

179
5133
00000000000011100100100011000000001111100000000000000001011100000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

180
5147
00000000000011100100100011000000001111100000000000000100101110000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

181
5157
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

182
5183
00000000000011100100100011100000101111100000001101110000000111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

183
5196
00000000000001110110000000000000000000101111000101101101110100000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

184
5216
00000000000001000011000000000000000000100111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

185
5240
00000000000001001111000001111111011111110111000100000000000000010010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

186
5264
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

187
5291
00000000000001110110000000000000000000101111000101101101110100000010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

188
5311
00000000000000011000000000000010010000001111000001111111011111110010100001000011
00000000000000000001000001000100000000000000000010010100010000110000000000000000
00101000010000110000000000000000

In Topic: Loading Quake 2 BSP vis data

18 June 2013 - 08:20 PM

This is correct and expected.  The PVS in Quake engine games is a run-length encoded bitfield; so if - say - the 17th element in the bitfield is a 1, then the 17th leaf is visible, if it's a 0 the 17th leaf is not visible.

so I'm loading it correctly?


In Topic: Loading Quake 2 BSP vis data

18 June 2013 - 01:53 PM

Please don't do this.

 

I don't mean "load Quake 2 vis data", I mean just say "I'm having trouble" without saying what the trouble is, then give a code dump and ask others to debug it for you.

 

Have you cross-checked with the Quake 2 source code here?

sorry I was in a hurry when I wrote this

I had to get to work, what Wanted to say was I do not think I am loading it correctly because I get multiple 1011's randomly since this is pvs data I would think the values would be unique. Also I know the data is run length encoded 


In Topic: Problem rendering Quake 3 BSP files

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 biggrin.png )

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 load(string);
  void render();  
};

void bsp::load(string name)
{
 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;
           version = readInt(bsp::bspfile);
           if(version != 46)//46 = 0x2e in hexidecimal
             cout << "ERROR: Unknown version of Quake 3 BSP" << endl;
           else
               {
                for (int i = 0; i <= 16; i++)
                   {                 
                    bsp::lumps[i].offset = readInt(bsp::bspfile);
                    bsp::lumps[i].length = readInt(bsp::bspfile);
                    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); 
		        bsp::bspfile.read(bsp::entities, bsp::lumps[0].length);  
                
                //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];           
                    bsp::bspfile.read(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	
                    bsp::bspfile.read(buffer, 44);   //Read 
                    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	
                    bsp::bspfile.read(buffer, 104);   //Read 
                    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 ); 
	glLoadIdentity(); 
	//Initialize Modelview Matrix 
	glMatrixMode( GL_MODELVIEW ); 
	glLoadIdentity(); 
	//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 ); 
   //Render quad 
   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();
 bspbuffer.load("test1.bsp");
 do
   {
    render(); 
   }while(running);   
 return 0;
}//End main()



In Topic: Problem rendering Quake 3 BSP files

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)


PARTNERS