Humle

01-06-2002, 07:25 AM

Hi!

I have managed to create a simple Quake3 Level Renderer. Textures and Lightmaps are succesfully applied and I think the PVS and Frustumculling works great, but itīs still very slow (sometimes aprox. 15 fps.)

The below code is my BSP Render() function:

void BSP: http://www.opengl.org/discussion_boards/ubb/biggrin.gifraw(float PosX, float PosY, float PosZ)

{

Frustum->CalculateFrustum();

CameraPoint[1] = PosX;

CameraPoint[2] = PosY;

CameraPoint[0] = PosZ;

int CameraLeaf=0;

CameraLeaf = FindLeaf();

if (CameraLeaf < 0)

return;

if (&Leaves[CameraLeaf].cluster < 0)

return;

glPushMatrix();

glTranslatef(PositionX, PositionY, PositionZ);

int i=0;

int x=0;

int j=0;

int k=0;

int CurrFace=0;

int n_leaffaces=0;

for (x=0; x<NumLeaves; x++) // For every leaf in the level

{

if (TESTVIS(Leaves[CameraLeaf].cluster, Leaves[x].cluster)) // Test to see if leaf MAY be visible

{

if (InFrustum(Leaves[x].mins, Leaves[x].maxs)) // Test to see if leaf IS visible

{

n_leaffaces = Leaves[x].n_leaffaces; // Get number of faces in the current leaf

for (j = 0; j < n_leaffaces; j++) // For every face in that leaf

{

CurrFace = LeafFaces[Leaves[x].leafface+j].face;

if (Faces[CurrFace].type == 1 && Faces[CurrFace].lm_index > -1)

{

glActiveTextureARB(GL_TEXTURE0_ARB);

glEnable(GL_TEXTURE_2D);

TexData[Faces[CurrFace].texture].Use();

glActiveTextureARB(GL_TEXTURE1_ARB);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, LightMapTextures[Faces[CurrFace].lm_index].ID);

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );

glBegin( GL_TRIANGLE_FAN);

for(k = Faces[CurrFace].vertex; k < Faces[CurrFace].vertex + Faces[CurrFace].n_vertexes; k++)

{

glColor4f(Vertices[k].color[0], Vertices[k].color[1], Vertices[k].color[2], Vertices[k].color[3]);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, Vertices[k].texcoord[0][0], Vertices[k].texcoord[0][1]);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, Vertices[k].texcoord[1][0], Vertices[k].texcoord[1][1]);

glNormal3f(Vertices[k].normal[0], Vertices[k].normal[1], Vertices[k].normal[2]);

glVertex3f(Vertices[k].position[1], Vertices[k].position[2], Vertices[k].position[0]);

}

glEnd();

}

}

}

}

}

glActiveTextureARB(GL_TEXTURE1_ARB);

glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE0_ARB);

glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE_2D);

glPopMatrix();

}

The TESTVIS Macro is from the Aftershock engine:

#define TESTVIS(from,to) \

(*(VisData->vecs + (from)*VisData->sz_vecs + \

((to)>>3)) & (1 << ((to) & 7)))

Please help me! It really bugs me!

Best regards

Humle

I have managed to create a simple Quake3 Level Renderer. Textures and Lightmaps are succesfully applied and I think the PVS and Frustumculling works great, but itīs still very slow (sometimes aprox. 15 fps.)

The below code is my BSP Render() function:

void BSP: http://www.opengl.org/discussion_boards/ubb/biggrin.gifraw(float PosX, float PosY, float PosZ)

{

Frustum->CalculateFrustum();

CameraPoint[1] = PosX;

CameraPoint[2] = PosY;

CameraPoint[0] = PosZ;

int CameraLeaf=0;

CameraLeaf = FindLeaf();

if (CameraLeaf < 0)

return;

if (&Leaves[CameraLeaf].cluster < 0)

return;

glPushMatrix();

glTranslatef(PositionX, PositionY, PositionZ);

int i=0;

int x=0;

int j=0;

int k=0;

int CurrFace=0;

int n_leaffaces=0;

for (x=0; x<NumLeaves; x++) // For every leaf in the level

{

if (TESTVIS(Leaves[CameraLeaf].cluster, Leaves[x].cluster)) // Test to see if leaf MAY be visible

{

if (InFrustum(Leaves[x].mins, Leaves[x].maxs)) // Test to see if leaf IS visible

{

n_leaffaces = Leaves[x].n_leaffaces; // Get number of faces in the current leaf

for (j = 0; j < n_leaffaces; j++) // For every face in that leaf

{

CurrFace = LeafFaces[Leaves[x].leafface+j].face;

if (Faces[CurrFace].type == 1 && Faces[CurrFace].lm_index > -1)

{

glActiveTextureARB(GL_TEXTURE0_ARB);

glEnable(GL_TEXTURE_2D);

TexData[Faces[CurrFace].texture].Use();

glActiveTextureARB(GL_TEXTURE1_ARB);

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, LightMapTextures[Faces[CurrFace].lm_index].ID);

glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD );

glBegin( GL_TRIANGLE_FAN);

for(k = Faces[CurrFace].vertex; k < Faces[CurrFace].vertex + Faces[CurrFace].n_vertexes; k++)

{

glColor4f(Vertices[k].color[0], Vertices[k].color[1], Vertices[k].color[2], Vertices[k].color[3]);

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, Vertices[k].texcoord[0][0], Vertices[k].texcoord[0][1]);

glMultiTexCoord2fARB(GL_TEXTURE1_ARB, Vertices[k].texcoord[1][0], Vertices[k].texcoord[1][1]);

glNormal3f(Vertices[k].normal[0], Vertices[k].normal[1], Vertices[k].normal[2]);

glVertex3f(Vertices[k].position[1], Vertices[k].position[2], Vertices[k].position[0]);

}

glEnd();

}

}

}

}

}

glActiveTextureARB(GL_TEXTURE1_ARB);

glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE0_ARB);

glDisable(GL_TEXTURE_2D);

glEnable(GL_TEXTURE_2D);

glPopMatrix();

}

The TESTVIS Macro is from the Aftershock engine:

#define TESTVIS(from,to) \

(*(VisData->vecs + (from)*VisData->sz_vecs + \

((to)>>3)) & (1 << ((to) & 7)))

Please help me! It really bugs me!

Best regards

Humle