Advertisement

COBRA PLEASE READ THIS AGAIN

Started by April 08, 2001 08:25 AM
0 comments, last by steveharper101 23 years, 7 months ago
I have found an Halflife BSP loader on the homepage of Nehe but i cannot understand the following code I thinks this is used to render the vertices: ////////////////////////////////////////////////////// float is = 1.0f/(float)bsp->textures[ti->miptex].width; float it = 1.0f/(float)bsp->textures[ti->miptex].height; // USED TO DRAW THE VERTACIE DATA face->first = vt_array.current(); face->count = f->numedges; for(c = 0; c < f->numedges; c++) { float v[7]; int eidx = *(bsp->edge_list + f->firstedge + c); if(eidx < 0) { eidx = -eidx; dedge_t* e = bsp->edges + eidx; v[0] = bsp->vertices[e->v[1]].point[0]; v[1] = bsp->vertices[e->v[1]].point[1]; v[2] = bsp->vertices[e->v[1]].point[2]; } else { dedge_t* e = bsp->edges + eidx; v[0] = bsp->vertices[e->v[0]].point[0]; v[1] = bsp->vertices[e->v[0]].point[1]; v[2] = bsp->vertices[e->v[0]].point[2]; } vec3_t vertex = v; float s = vertex.dot(ti->vecs[0]) + ti->vecs[0][3]; float t = vertex.dot(ti->vecs[1]) + ti->vecs[1][3]; v[3] = s*is; v[4] = t*it; if(face->flags==0) { // compute lightmap coords float mid_poly_s = (min[0] + max[0])/2.0f; float mid_poly_t = (min[1] + max[1])/2.0f; float mid_tex_s = (float)lw / 2.0f; float mid_tex_t = (float)lh / 2.0f; float ls = mid_tex_s + (s - mid_poly_s) / 16.0f; float lt = mid_tex_t + (t - mid_poly_t) / 16.0f; ls /= (float) lw; lt /= (float) lh; v[5] = ls; v[6] = lt; */ // } //////////////////////// vt_array.add(v); st_array.add(v+3); lst_array.add(v+5); } /////////////////////////////// vec3_t n = face->plane.normal; float d = face->plane.dist; if(face->side) { face->p = plane_t(-n,d); } else { face->p = plane_t(n,-d); } // add face faces = face; } // set visible faces size to total texture count visible_faces.resize(textures.size()); // setup vertex arrays glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vt_array); if(use_multi) { glClientActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, st_array); glClientActiveTextureARB(GL_TEXTURE1_ARB); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, lst_array); } If you can help me understand this code please reply please bear in mind that i am very new to BSP but have been learning OpenGL for a while. Shouldn''t there be an glBegin(GL_Triangles);, and GlEnd(); ? Does yor code have a better way of rendering vertices Please Please send me your Halflife loader before it''s uploded to your site my email is: steveharper@clara.co.uk THANKS A LOT FOR TAKING TIME TO READ THIS POST
From what I can tell......

v[0] = bsp->vertices[e->v[0]].point[0];
v[1] = bsp->vertices[e->v[0]].point[1];
v[2] = bsp->vertices[e->v[0]].point[2];

is the 3 vertices for the triangles... however, he puts them into an array, and uses glDrawArrays(f->type, f->first, f->count)
to draw the array to the screen..


The code you have posted is simply arranging all the vertice data into the array ( including face normals e.t.c ).


I actually think that you''ve missed some of his rendering code ( I had a good look through his code, and his seems a bit better than mine *ashamed*.. )

But basically the code you''ve shown is just to put the node data into the array.

~Cobra~
"Build a man a fire, and he will be warm for a day. Set a man on fire, and he will have warmth for the rest of his life"

This topic is closed to new replies.

Advertisement