PDA

View Full Version : Everything going toward the origin?



nukem
11-19-2003, 08:56 PM
For some reason when run my Quake III BSP engine it looks (http://zonkbonk.virtualave.net/NuclearGraphics.png) like everything is going toward the origin. I do not understand why my engine is doing this. Could someone please look at my code?




void NuclearBSP::Q3::RenderLeaf(int Leaf, bool CheckFrustum, Vect3& Pos)
{
BSPLeaf* leaf = &leafs[Leaf];

//preform PVS
if(!IsClusterVisible(leafs[FindLeaf(Pos)].cluster, leaf->cluster))
{
return;
}

//if the node we came from is COMPLETEIN then CheckFrustum will be false and we
//wont need to check this leaf against the frstum because we know we are COMPLETEIN
//if the node was intersecting then check agienst the frstum

if(CheckFrustum)
{
if(!frustum.BoxInFrustum(leaf->min.x, leaf->min.y, leaf->min.z, leaf->max.x, leaf->max.y, leaf->max.z))
{
return;
}
}

int lfacecount = leaf->leaffacecount;

//Size faces
CRender render(lfacecount);

//render all the faces in this leaf
while(lfacecount--)
{
//get current face index
int faceindex = leaffaces[leaf->leafface + lfacecount];

if((faces[faceindex].type == BEZIER_PATCH) | | (faces[faceindex].type == BILLBOARD))
{
render.Push(0);
continue;
}

//make sure the face hasnt been drawn
if(!facesdrawn.On(faceindex))
{
facesdrawn.Set(faceindex);
render.Push(&faces[faceindex]);
}else{
render.Push(0);
}
}

render.Render();
}

CRender::CRender(int size)
{
faces = 0;
SetupFaces(size);
}

CRender::CRender()
{
faces = 0;
facecount = 0;
pos = 0;
}

CRender::~CRender()
{
if(faces)
{
delete [] faces;
}
}

//resizes the faces before they're pushed
void CRender::SetupFaces(int size)
{
if(faces)
{
delete [] faces;
}

facecount = size;
faces = new PVertexBuffer[facecount];
pos = 0;
}

//add a face to the faces array
void CRender::Push(VertexBuffer* face)
{
faces[pos] = face;
pos++;
}

//render the faces
void CRender::Render()
{
if(pos != facecount)
{
fprintf(stderr, "Error pos(%i) != facecount(%i)!!!\n", pos, facecount);
}

//go threw all the faces and render them
for(int i=0;i<facecount;i++)
{
if(faces[i] == 0)
{
continue;
}

//set the texture
glActiveTextureARB(GL_TEXTURE0_ARB);

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, faces[i]->textureID);

//set the lightmaps up
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, faces[i]->lightmapID);

//set the vertex pointer for each face
glVertexPointer(3, GL_FLOAT, sizeof(VertexBuffer), faces[i]->vert);
//assign texture pass to point to normal texture coords
glClientActiveTextureARB(GL_TEXTURE0_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), faces[i]->texcoord);
//assign lightmap pass to point
glClientActiveTextureARB(GL_TEXTURE1_ARB);
glTexCoordPointer(2, GL_FLOAT, sizeof(VertexBuffer), faces[i]->lightmapcoord);

//draw it
glDrawElements(GL_TRIANGLES, faces[i]->indicescount, GL_UNSIGNED_INT, faces[i]->indices);
}
}


The complete source is here (http://zonkbonk.virtualave.net/NuclearGraphics.zip) .

Can someone please help me figure out whats wrong?

Thanks

Nuke

[This message has been edited by nukem (edited 11-19-2003).]

Relic
11-20-2003, 12:57 AM
faces[i]->vert, faces[i]->texcoord, faces[i]->lightmapcoord are pointers to Vect3 or Vect2.
Strides in gl..Pointer calls need to be sizeof(Vect3) and sizeof(Vect2) instead of sizeof(VertexBuffer).

nukem
11-20-2003, 12:51 PM
That fixed it! Thank you!!!