• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

industrialgrok

Members
  • Content count

    12
  • Joined

  • Last visited

Community Reputation

161 Neutral

About industrialgrok

  • Rank
    Member
  1. Hello, Ive been working on an Occlusion culler that uses opengl's occlusion queries although when I render the scene meshes can occlude meshes but when models are in front of each other they still render. here is the code void renderer::draw() { for( int m = 0; m < renderer::meshes.size(); m++ ) { glPushMatrix(); if(renderer::meshes[m].yaw != 0 ) glRotatef(renderer::meshes[m].yaw,1.0,0.0,0.0); if(renderer::meshes[m].pitch != 0 ) glRotatef(renderer::meshes[m].pitch,0.0,1.0,0.0); if(renderer::meshes[m].roll != 0 ) glRotatef(renderer::meshes[m].roll,0.0,0.0,1.0); if((renderer::meshes[m].scaley != 1)&&(renderer::meshes[m].scaley != 1)&&(renderer::meshes[m].scalez != 1)) glScalef(renderer::meshes[m].scaley,renderer::meshes[m].scaley,renderer::meshes[m].scalez); if((renderer::meshes[m].x != 0)&&(renderer::meshes[m].y != 0)&&(renderer::meshes[m].z != 0)) glTranslatef(renderer::meshes[m].x,renderer::meshes[m].y,renderer::meshes[m].z); for( int l = 0; l < renderer::meshes[m].trislists.size(); l++ ) { glGenQueriesARB( 1, &renderer::meshes[m].trislists[l].query ); glBeginQueryARB( GL_SAMPLES_PASSED_ARB, renderer::meshes[m].trislists[l].query); for( int t = 0; t < renderer::meshes[m].trislists[l].tris.size(); t++ ) { drawtriangle(renderer::meshes[m].trislists[l].tris[t]); } glEndQueryARB( GL_SAMPLES_PASSED_ARB ); } glPopMatrix(); } glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); for( int m = 0; m < renderer::meshes.size(); m++ ) { for( int l = 0; l < renderer::meshes[m].trislists.size(); l++ ) { glGetQueryObjectuivARB( renderer::meshes[m].trislists[l].query, GL_QUERY_RESULT_ARB, &renderer::meshes[m].trislists[l].fragmentcount); } } for( int m = 0; m < renderer::meshes.size(); m++ ) { glPushMatrix(); if(renderer::meshes[m].yaw != 0 ) glRotatef(renderer::meshes[m].yaw,1.0,0.0,0.0); if(renderer::meshes[m].pitch != 0 ) glRotatef(renderer::meshes[m].pitch,0.0,1.0,0.0); if(renderer::meshes[m].roll != 0 ) glRotatef(renderer::meshes[m].roll,0.0,0.0,1.0); if((renderer::meshes[m].scaley != 1)&&(renderer::meshes[m].scaley != 1)&&(renderer::meshes[m].scalez != 1)) glScalef(renderer::meshes[m].scaley,renderer::meshes[m].scaley,renderer::meshes[m].scalez); if((renderer::meshes[m].x != 0)&&(renderer::meshes[m].y != 0)&&(renderer::meshes[m].z != 0)) glTranslatef(renderer::meshes[m].x,renderer::meshes[m].y,renderer::meshes[m].z); for( int l = 0; l < renderer::meshes[m].trislists.size(); l++ ) { if(renderer::meshes[m].trislists[l].fragmentcount != 0 ) { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); //draw for( int t = 0; t < renderer::meshes[m].trislists[l].tris.size(); t++ ) { drawtriangle(renderer::meshes[m].trislists[l].tris[t]); } glPolygonMode( GL_FRONT_AND_BACK, GL_FILL ); } } glPopMatrix(); } //clear renderer::meshes.clear(); }
  2. 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
  3. so I'm loading it correctly?
  4. 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 
  5. so, I've made a Quake 2 bsp loader but I'm having trouble loading the visibility data here is my code #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 <vector> #include <bitset> using namespace std; int SCREEN_WIDTH = 640; int SCREEN_HEIGHT = 480; int SCREEN_BPP = 24; bool running = true; bool lightmaps; SDL_Event event; struct pos { float x; float y; float z; }; struct bspface { uint16_t plane; // index of the plane the face is parallel to uint16_t plane_side; // set if the normal is parallel to the plane normal unsigned int first_edge; // index of the first edge (in the face edge array) uint16_t num_edges; // number of consecutive edges (in the face edge array) uint16_t texture_info; // index of the texture info structure uint8_t lightmap_syles[4]; // styles (bit flags) for the lightmaps unsigned int lightmap_offset; // offset of the lightmap (in bytes) in the lightmap lump }; struct bspvertex { pos position; }; struct point3s { int16_t x; int16_t y; int16_t z; }; struct bspplane { float normal[3]; // A, B, C components of the plane equation float distance; // D component of the plane equation unsigned int type; // ? }; struct bsptexture { float u_axis[3]; float u_offset; float v_axis[3]; float v_offset; unsigned int flags; unsigned int value; char name[32]; unsigned int next_texinfo; }; struct bspnode { unsigned int plane; // index of the splitting plane (in the plane array) unsigned int front_child; // index of the front child node or leaf unsigned int back_child; // index of the back child node or leaf float bbox_min[3]; // minimum x, y and z of the bounding box float bbox_max[3]; // maximum x, y and z of the bounding box uint16_t first_face; // index of the first face (in the face array) uint16_t num_faces; // number of consecutive edges (in the face array) }; struct bspedge { uint16_t vertex[2]; // Indices into vertex array }; struct bspvis { unsigned int pvs; // offset (in bytes) from the beginning of the visibility lump unsigned int phs; // ? }; struct bsplump { int offset; int length; }; class bsp { public: ifstream bspfile; bsplump lumps[19]; char entities[10000]; vector <bspvertex> vertices; vector <bspface> faces; vector <bsptexture> textures; vector <bspplane> planes; vector <bspnode> nodes; vector <bspedge> edges; vector <unsigned int> faceedges; vector <bspvis> visarray; 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 Quake 3 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 2 BSP file" << endl; } else { int version; char vbuffer[4]; bsp::bspfile.read(vbuffer, 4); for (int k = 0; k <= 3; k++) { ((char*)&version)[k] = vbuffer[k]; } if(version != 38)//46 = 0x2e in hexidecimal cout << "ERROR: Unknown version of Quake 2 BSP" << endl; else { for (int i = 0; i <= 18; i++) { char lumpoffset[4]; char lumplength[4]; //Read lumps offset bsp::bspfile.read(lumpoffset, 4); for (int k = 0; k <= 3; k++) { ((char*)&bsp::lumps[i].offset)[k] = lumpoffset[k]; } //Read lumps length bsp::bspfile.read(lumplength, 4); for (int k = 0; k <= 3; k++) { ((char*)&bsp::lumps[i].length)[k] = lumplength[k]; } } //Load entities (LUMP 0) bsp::bspfile.seekg (bsp::lumps[0].offset, ios::beg); bsp::bspfile.read(bsp::entities, bsp::lumps[0].length); //Load planes (LUMP 1) bsp::bspfile.seekg (bsp::lumps[1].offset, ios::beg); for (int j = 0; j <= bsp::lumps[1].length/sizeof(bspplane); j++) //Read until end of lump { char buffer[20]; //create buffer for Leaffaces bsp::bspfile.read(buffer, 20); //Read bspplane plane; for (int k = 0; k <= 19; k++) //Read until end of lump { ((char*)&plane)[k] = buffer[k]; } bsp::planes.push_back(plane); } bsp::bspfile.seekg (bsp::lumps[2].offset, ios::beg); //Load vertex data from vertex lump (10) for (int j = 0; j <= (bsp::lumps[2].length/sizeof(bspvertex)) -1; j++)//Read until end of lump { char buffer[12]; //create buffer for verts bsp::bspfile.read(buffer, 12); //Read bspvertex vertex; for (int k = 0; k <= 11; k++)//Read until end of lump { ((char*)&vertex)[k] = buffer[k]; } bsp::vertices.push_back(vertex); } 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++)//Read until end of lump { ((char*)&nclusters)[k] = buffer[k]; } cout << nclusters << endl; //189 bspvis visarray[200]; for (int v = 0; v <= nclusters - 1; v++)//Read until end of lump { 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 unsigned char mask; bitset<8> x = vis[0]; cout<< x << endl; cout << endl; //bsp::bspfile.seekg (bsp::lumps[3].offset + visarray[v].pvs, ios::beg); } //Load nodes (LUMP 4) bsp::bspfile.seekg (bsp::lumps[4].offset, ios::beg); for (int j = 0; j <= bsp::lumps[4].length/sizeof(bspnode); j++) //Read until end of lump { char buffer[28]; bsp::bspfile.read(buffer, 28); bspnode node; for (int k = 0; k <= 27; k++)//Read until end of lump { ((char*)&node)[k] = buffer[k]; } bsp::nodes.push_back(node); } //Load textures (LUMP 5) bsp::bspfile.seekg (bsp::lumps[5].offset, ios::beg); for (int j = 0; j <= bsp::lumps[5].length/sizeof(bsptexture); j++) //Read until end of lump { char buffer[76]; bsp::bspfile.read(buffer, 76); bsptexture texture; for (int k = 0; k <= 75; k++)//Read until end of lump { ((char*)&texture)[k] = buffer[k]; } bsp::textures.push_back(texture); } //Load faces (LUMP 6) bsp::bspfile.seekg (bsp::lumps[6].offset, ios::beg); for (int j = 0; j <= bsp::lumps[6].length/sizeof(bspface); j++) //Read until end of lump { char buffer[20]; bsp::bspfile.read(buffer, 20); bspface face; for (int k = 0; k <= 19; k++)//Read until end of lump { ((char*)&face)[k] = buffer[k]; } bsp::faces.push_back(face); } bsp::bspfile.seekg (bsp::lumps[12].offset, ios::beg); for (int j = 0; j <= bsp::lumps[12].length/sizeof(4); j++) //Read until end of lump { char buffer[4]; bsp::bspfile.read(buffer, 4); unsigned int faceedge; for (int k = 0; k <= 3; k++)//Read until end of lump { ((char*)&faceedge)[k] = buffer[k]; } bsp::faceedges.push_back(faceedge); } bsp::bspfile.seekg (bsp::lumps[11].offset, ios::beg); for (int j = 0; j <= bsp::lumps[11].length/sizeof(bspedge); j++) //Read until end of lump { char buffer[4]; bsp::bspfile.read(buffer, 4); bspedge edge; for (int k = 0; k <= 3; k++)//Read until end of lump { ((char*)&edge)[k] = buffer[k]; } bsp::edges.push_back(edge); } } } } } void bsp::render() { glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); for (int j=0; j< bsp::lumps[6].length/sizeof(bspface); j++) { glBegin(GL_TRIANGLE_FAN); for (int i=0; i< bsp::faces[j].num_edges; i++) { /* /*if(g_bLightmaps) glTexCoord2f(pFaceTexCoords[iFace].pLightmapCoords[i].fS, pFaceTexCoords[iFace].pLightmapCoords[i].fT); else glTexCoord2f(pFaceTexCoords[iFace].pTexCoords[i].fS, pFaceTexCoords[iFace].pTexCoords[i].fT); // normal VECTOR3D vNormal = pPlanes[pFaces[iFace].iPlane].vNormal; if (pFaces[iFace].nPlaneSide) vNormal = vNormal * -1; glNormal3f(vNormal.x, vNormal.y, vNormal.z);*/ int iEdge = bsp::faceedges[bsp::faces[j].first_edge + i]; // This gives the index into the edge lump if (iEdge > 0) { glVertex3f(bsp::vertices[bsp::edges[iEdge].vertex[0]].position.x, bsp::vertices[bsp::edges[iEdge].vertex[0]].position.y, bsp::vertices[bsp::edges[iEdge].vertex[0]].position.z); } else { iEdge *= -1; glVertex3f(bsp::vertices[bsp::edges[iEdge].vertex[1]].position.x, bsp::vertices[bsp::edges[iEdge].vertex[1]].position.y, bsp::vertices[bsp::edges[iEdge].vertex[1]].position.z); } } 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() { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_NORMALIZE); angle = angle + 1; glPushMatrix(); //Clear color buffer glClear( GL_COLOR_BUFFER_BIT ); //Add ambient light GLfloat ambientColor[] = {0.2f, 0.2f, 0.2f, 1.0f}; //Color(0.2, 0.2, 0.2) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientColor); //Add positioned light GLfloat lightColor0[] = {0.5f, 0.5f, 0.5f, 1.0f}; //Color (0.5, 0.5, 0.5) GLfloat lightPos0[] = {4.0f, 0.0f, 8.0f, 1.0f}; //Positioned at (4, 0, 8) glLightfv(GL_LIGHT0, GL_DIFFUSE, lightColor0); glLightfv(GL_LIGHT0, GL_POSITION, lightPos0); //Add directed light GLfloat lightColor1[] = {0.5f, 0.2f, 0.2f, 1.0f}; //Color (0.5, 0.2, 0.2) //Coming from the direction (-1, 0.5, 0.5) GLfloat lightPos1[] = {-1.0f, 0.5f, 0.5f, 0.0f}; glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor1); glLightfv(GL_LIGHT1, GL_POSITION, lightPos1); //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("q2.bsp"); do { render(); }while(running); return 0; } if anyone could point me in the right direction that would be greatly appreciated
  6. I have been working on rendering Quake 3 bsp maps for awhile but I cant get the faces to 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 #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>                                    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 #define MAX_LEAFFACES   65536 struct pos {  float x;  float y;  float z; }; 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 {  pos position;      //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];   int         faceindex[MAX_LEAFFACES];   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 Quake 3 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;            char vbuffer[4];                            bsp::bspfile.read(vbuffer, 4);               for (int k = 0; k <= 3; k++)                   {                ((char*)&version)[k] = vbuffer[k];               }                           if(version != 46)//46 = 0x2e in hexidecimal              cout << "ERROR: Unknown version of Quake 3 BSP" << endl;            else                {                 for (int i = 0; i <= 16; i++)                    {                     char lumpoffset[4];                     char lumplength[4];                                          //Read lumps offset                     bsp::bspfile.read(lumpoffset, 4);                                         for (int k = 0; k <= 3; k++)                            {                         ((char*)&bsp::lumps[i].offset)[k] = lumpoffset[k];                        }                                             //Read lumps length                        bsp::bspfile.read(lumplength, 4);                                         for (int k = 0; k <= 3; k++)                            {                         ((char*)&bsp::lumps[i].length)[k] = lumplength[k];                        }                                             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);                 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 Leaffaces (LUMP 5)                 bsp::bspfile.seekg (bsp::lumps[5].offset, ios::beg);                 for (int j = 0; j <= bsp::lumps[5].length/sizeof(bspvertex); j++) //Read until end of lump                    {                     char buffer[4];                 //create buffer for Leaffaces                              bsp::bspfile.read(buffer, 4);   //Read                     for (int k = 0; k <= 3; k++)    //Read until end of lump                        {                         ((char*)&bsp::faceindex[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 face data from face lump (13)                 for (int j = 0; j <= bsp::lumps[13].length/sizeof(bspface); j++)//Read until end of lump                    {                     char buffer[104];                 //create buffer for faces                         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];                        }                    }                }           }      } } 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);          for (int k = 0; k <=  bsp::faces[j].numofverts - 1; k++)//Read until end of lump             {              glVertex3f(bsp::vertices[bsp::faces[j].vertexindex+k].position.x, bsp::vertices[bsp::faces[j].vertexindex+k].position.y, bsp::vertices[bsp::faces[j].vertexindex+k].position.z);             }          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; } any help would be appreciated
  7. OpenGL

    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 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()
  8. OpenGL

    Ok thanks borntocode I was unaware of this. Thanks blueshotgun, Have you actually implemented the PVS system? (like paulsprojects)
  9. so a while back I messed with ode because i was going to impliment it in my engine, its been about a month so i dont have the compile command in my terminal history and i forgot specificly what i used to compile it but here is the code   #include <ode/ode.h> #include <drawstuff/drawstuff.h> #include <string.h> #include <iostream> #ifdef dDOUBLE #define dsDrawSphere dsDrawSphereD #endif using namespace std; const int VertexCount = 5; const int IndexCount = 12; static dVector3 Size; static float Vertices[VertexCount][3]; static dTriIndex Indices[IndexCount]; static dJointGroupID contactgroup; //static int flag = 0; dsFunctions fn; const double radius = 0.2; const double mass = 1.0; struct cworld { int numobjects; dSpaceID space; dWorldID world; }; struct object { string name; string type; const double *position; const double *rotation; dBodyID body; dGeomID geom; dMass mass; }; cworld world; object objects[10]; //object objects[0]; //object objects[1]; //object objects[3]; static void nearCallback(void *data, dGeomID o1, dGeomID o2) { const int N = 10; dContact contact[N]; int n; for(int i = 0; i <= world.numobjects; i++) { n = dCollide(o1,o2,N,&contact[0].geom,sizeof(dContact)); if(n >= 1) //object hit somthing { if(objects[i].geom == o1) { //cout << objects[i].type << endl; for(int j = 0; j <= world.numobjects; j++) { if(objects[j].geom == o2) { cout << objects[j].name << " is hitting a " << objects[j].name << endl; } } } } } for(int i = 0; i < n; i++) { contact[i].surface.mode = dContactBounce; contact[i].surface.mu = dInfinity; contact[i].surface.bounce = 0.0; // (0.0~1.0) restitution parameter contact[i].surface.bounce_vel = 0.0; // minimum incoming velocity for bounce dJointID c = dJointCreateContact(world.world,contactgroup,&contact[i]); dJointAttach (c,dGeomGetBody(contact[i].geom.g1),dGeomGetBody(contact[i].geom.g2)); } } static void simLoop (int pause) { //flag = 0; dSpaceCollide(world.space,0,&nearCallback); dWorldStep(world.world,0.01); dJointGroupEmpty(contactgroup); /*if(flag == 0) dsSetColor(1.0, 0.0, 0.0); else dsSetColor(0.0, 0.0, 1.0);*/ objects[0].position = dBodyGetPosition(objects[0].body); objects[0].rotation = dBodyGetRotation(objects[0].body); dsDrawSphere(objects[0].position,objects[0].rotation,radius); objects[1].position = dBodyGetPosition(objects[1].body); objects[1].rotation = dBodyGetRotation(objects[1].body); dsDrawSphere(objects[1].position,objects[1].rotation,radius); } void start() { static float xyz[3] = {0.0,-3.0,1.0}; static float hpr[3] = {90.0,0.0,0.0}; dsSetViewpoint (xyz,hpr); } void prepDrawStuff() { fn.version = DS_VERSION; fn.start = &start; fn.step = &simLoop; fn.command = NULL; fn.stop = NULL; fn.path_to_textures = "../../drawstuff/textures"; } int main (int argc, char *argv[]) { double x0 = 0.0, y0 = 0.0, z0 = 2.0; prepDrawStuff(); dInitODE(); world.world = dWorldCreate(); world.space = dHashSpaceCreate(0); contactgroup = dJointGroupCreate(0); dWorldSetGravity(world.world,0,0,-0.5); //Create a trimesh Size[0] = 5.0f; Size[1] = 5.0f; Size[2] = 2.5f; Vertices[0][0] = -Size[0]; Vertices[0][1] = -Size[1]; Vertices[0][2] = Size[2]; Vertices[1][0] = Size[0]; Vertices[1][1] = -Size[1]; Vertices[1][2] = Size[2]; Vertices[2][0] = Size[0]; Vertices[2][1] = Size[1]; Vertices[2][2] = Size[2]; Vertices[3][0] = -Size[0]; Vertices[3][1] = Size[1]; Vertices[3][2] = Size[2]; Vertices[4][0] = 0; Vertices[4][1] = 0; Vertices[4][2] = 0; Indices[0] = 0; Indices[1] = 1; Indices[2] = 4; Indices[3] = 1; Indices[4] = 2; Indices[5] = 4; Indices[6] = 2; Indices[7] = 3; Indices[8] = 4; Indices[9] = 3; Indices[10] = 0; Indices[11] = 4; dTriMeshDataID Data = dGeomTriMeshDataCreate(); //dGeomTriMeshDataBuildSimple(Data, (dReal*)Vertices, VertexCount, Indices, IndexCount); dGeomTriMeshDataBuildSingle(Data, Vertices[0], 3 * sizeof(float), VertexCount, &Indices[0], IndexCount, 3 * sizeof(dTriIndex)); objects[4].geom = dCreateTriMesh(world.space, Data, 0, 0, 0); dGeomSetPosition(objects[4].geom, 0, 0, 0.0); objects[4].type = "world"; objects[4].name = "crappy sky"; world.numobjects = world.numobjects + 1; // Create a ground objects[3].geom = dCreatePlane(world.space,0,0,1,0); objects[3].type = "ground"; objects[3].name = "ground(duh)"; world.numobjects = world.numobjects + 1; // Create objects[0] objects[0].type = "sphere"; objects[0].name = "ball1"; objects[0].body = dBodyCreate(world.world); dMassSetZero(&objects[0].mass); dMassSetSphereTotal(&objects[0].mass,mass,radius); dBodySetMass(objects[0].body,&objects[0].mass); dBodySetPosition(objects[0].body, x0, y0, z0); objects[0].geom = dCreateSphere(world.space,radius); dGeomSetBody(objects[0].geom,objects[0].body); dBodySetLinearVel(objects[0].body, 1.0, 0.0,1.0); world.numobjects = world.numobjects + 1; //Create objects[1] objects[1].type = "sphere"; objects[1].name = "ball2"; objects[1].body = dBodyCreate(world.world); dMassSetZero(&objects[1].mass); dMassSetSphereTotal(&objects[1].mass,mass,radius); dBodySetMass(objects[1].body,&objects[1].mass); dBodySetPosition(objects[1].body, -1.0, y0, 3.0); objects[1].geom = dCreateSphere(world.space,radius); dGeomSetBody(objects[1].geom,objects[1].body); world.numobjects = world.numobjects + 1; dsSimulationLoop (argc,argv,352,288,&fn); dWorldDestroy (world.world); dCloseODE(); return 0; }   here is the output : sample6.cpp: In function ‘void simLoop(int)’: sample6.cpp:102:57: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment sample6.cpp:103:59: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment sample6.cpp:104:62: error: cannot convert ‘const double*’ to ‘const float*’ for argument ‘1’ to ‘void dsDrawSphere(const float*, const float*, float)’ sample6.cpp:106:57: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment sample6.cpp:107:59: error: cannot convert ‘const dReal* {aka const float*}’ to ‘const double*’ in assignment sample6.cpp:108:62: error: cannot convert ‘const double*’ to ‘const float*’ for argument ‘1’ to ‘void dsDrawSphere(const float*, const float*, float)’   when I fix these errors and run it I get a zero inertia runtime error now I remember this code compiling and running fine. So I must be compiling it wrong (I bet its somthing stupid I simply forgot) have any idea?
  10. OpenGL

    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 
  11. OpenGL

    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 loadbsp(string); //prototype void init() { glClearColor(0.0,0.0,0.0,1.0); //Background color glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Reset 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(); glLoadIdentity(); 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 != "") { loadbsp(tolken); } } do { SDL_Surface* screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE|SDL_OPENGL); //Window //Tab SDL_WM_SetCaption( "BSPloader","BSPloader"); Uint32 start; init(); display(); SDL_Delay(1000/30); }while(running); } return 0; } void loadbsp(string name) { 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; version = readInt(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++) { bspbuffer.lumps[i].offset = readInt(bspfile); bspbuffer.lumps[i].length = readInt(bspfile); cout << "Lump " << i << " offset is " << bspbuffer.lumps[i].offset << endl << "Lump " << i << " length is " << bspbuffer.lumps[i].length << endl << endl; } //Load vertices bspfile.seekg (bspbuffer.lumps[10].offset, ios::beg); //Load vertex data from vertex lump (10) long readmemory = 0; cout << "Loading"; for (int j = 0; j <= bspbuffer.lumps[10].length/sizeof(bspvertex); j++)//Read until end of lump { //Actual vertexes bspbuffer.vertices[j].position[0] = readFloat(bspfile); bspbuffer.vertices[j].position[1] = readFloat(bspfile); bspbuffer.vertices[j].position[2] = readFloat(bspfile); //U,V coordinates bspbuffer.vertices[j].texturecoord[0] = readFloat(bspfile); bspbuffer.vertices[j].texturecoord[1] = readFloat(bspfile); //Lightmap U,V coordinates bspbuffer.vertices[j].lightmapcoord[0] = readFloat(bspfile); bspbuffer.vertices[j].lightmapcoord[1] = readFloat(bspfile); //Normalized vertex coordinates bspbuffer.vertices[j].position[0] = readFloat(bspfile); bspbuffer.vertices[j].position[1] = readFloat(bspfile); bspbuffer.vertices[j].position[2] = readFloat(bspfile); char buffer[64]; bspfile.read(buffer, 4); //Read RGBA color index 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; cout << "Loading"; 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) readmemory2 = readmemory2 + 104; cout << "."; } cout << "Lump 13 loaded" << endl; } } } }                              
  12. 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 loadbsp(string); //prototype void init() { glClearColor(0.0,0.0,0.0,1.0); //Background color glMatrixMode(GL_PROJECTION); glLoadIdentity(); //Reset 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(); glLoadIdentity(); 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 != "") { loadbsp(tolken); } } do { SDL_Surface* screen=SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,SDL_SWSURFACE|SDL_OPENGL); //Window //Tab SDL_WM_SetCaption( "BSPloader","BSPloader"); Uint32 start; init(); display(); SDL_Delay(1000/30); }while(running); } return 0; } void loadbsp(string name) { 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; version = readInt(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++) { bspbuffer.lumps[i].offset = readInt(bspfile); bspbuffer.lumps[i].length = readInt(bspfile); cout << "Lump " << i << " offset is " << bspbuffer.lumps[i].offset << endl << "Lump " << i << " length is " << bspbuffer.lumps[i].length << endl << endl; } //Load vertices bspfile.seekg (bspbuffer.lumps[10].offset, ios::beg); //Load vertex data from vertex lump (10) long readmemory = 0; cout << "Loading"; for (int j = 0; readmemory <= bspbuffer.lumps[10].length; j++)//Read until end of lump { //Actual vertexes bspbuffer.vertices[j].position[0] = readFloat(bspfile); bspbuffer.vertices[j].position[1] = readFloat(bspfile); bspbuffer.vertices[j].position[2] = readFloat(bspfile); //U,V coordinates bspbuffer.vertices[j].texturecoord[0] = readFloat(bspfile); bspbuffer.vertices[j].texturecoord[1] = readFloat(bspfile); //Lightmap U,V coordinates bspbuffer.vertices[j].lightmapcoord[0] = readFloat(bspfile); bspbuffer.vertices[j].lightmapcoord[1] = readFloat(bspfile); //Normalized vertex coordinates bspbuffer.vertices[j].position[0] = readFloat(bspfile); bspbuffer.vertices[j].position[1] = readFloat(bspfile); bspbuffer.vertices[j].position[2] = readFloat(bspfile); char buffer[64]; bspfile.read(buffer, 4); //Read RGBA color index 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) readmemory = readmemory + 44; cout << "."; } bspfile.seekg (bspbuffer.lumps[13].offset, ios::beg); //Load face data from vertex lump (13) long readmemory2 = 0; cout << "Loading"; 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) readmemory2 = readmemory2 + 104; } 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?