PDA

View Full Version : Blending/Lighting Problems



MrShoe
12-07-2001, 01:55 PM
My terrain eningine has multipass multitexturing... The multitexturing works if lighting is off, but doesnt work when lighting is on, it kinda disables blending by turning on lighting... This is not a bug as im pretty sure this is what usually happens, but does anybody know how to fix this?>

Leyder Dylan
12-07-2001, 02:10 PM
Put some code.

MrShoe
12-07-2001, 06:50 PM
void renderTerrain(void){
register int mapx, mapz;
register int x, y;
float distance;

glPushMatrix();
gluLookAt(player.xpos, player.ypos, player.zpos, player.xlook, player.ylook, player.zlook, 0.0, 1.0, 0.0);

glBindTexture(GL_TEXTURE_2D, texture[0]);
for(mapx = 0; mapx < (TERRAIN_LENGTH-2); mapx++){
for(mapz = 0; mapz < (TERRAIN_WIDTH-2); mapz++){
// Make sure not to draw polygons that are too far away
distance = sqrt((player.xpos-(float)mapx/TERRAIN_DETAIL)*(player.xpos-(float)mapx/TERRAIN_DETAIL) + (player.ypos-terrain_height[mapx][mapz])*(player.ypos-terrain_height[mapx][mapz]) + (player.zpos-(float)mapz/TERRAIN_DETAIL)*(player.zpos-(float)mapz/TERRAIN_DETAIL));
if(distance < CULL_DISTANCE){
glBegin(GL_TRIANGLE_STRIP);
//glColor4f(1.0, 1.0, 1.0, (1.0-alpha_values[mapx][mapz]));
glNormal3f(terrain_normals[mapx][mapz].x, terrain_normals[mapx][mapz].y, terrain_normals[mapx][mapz].z);
glTexCoord2f(0.0, 0.0); glVertex3f((float)mapx/TERRAIN_DETAIL, terrain_height[mapx][mapz], (float)mapz/TERRAIN_DETAIL);

//glColor4f(1.0, 1.0, 1.0, (1.0-alpha_values[mapx+1][mapz]));
glNormal3f(terrain_normals[mapx+1][mapz].x, terrain_normals[mapx+1][mapz].y, terrain_normals[mapx+1][mapz].z);
glTexCoord2f(0.0, TEXTURE_DETAIL); glVertex3f((float)(mapx+1)/TERRAIN_DETAIL, terrain_height[mapx+1][mapz], (float)mapz/TERRAIN_DETAIL);

//glColor4f(1.0, 1.0, 1.0, (1.0-alpha_values[mapx][mapz+1]));
glNormal3f(terrain_normals[mapx][mapz+1].x, terrain_normals[mapx][mapz+1].y, terrain_normals[mapx][mapz+1].z);
glTexCoord2f(TEXTURE_DETAIL, 0.0); glVertex3f((float)mapx/TERRAIN_DETAIL, terrain_height[mapx][mapz+1], (float)(mapz+1)/TERRAIN_DETAIL);

//glColor4f(1.0, 1.0, 1.0, (1.0-alpha_values[mapx+1][mapz+1]));
glNormal3f(terrain_normals[mapx+1][mapz+1].x, terrain_normals[mapx+1][mapz+1].y, terrain_normals[mapx+1][mapz+1].z);
glTexCoord2f(TEXTURE_DETAIL, TEXTURE_DETAIL); glVertex3f((float)(mapx+1)/TERRAIN_DETAIL, terrain_height[mapx+1][mapz+1], (float)(mapz+1)/TERRAIN_DETAIL);
glEnd();
}
}
}
glPopMatrix();
}

void renderSnowTerrain(void){
register int mapx, mapz;
register int x, y;
float distance;

glPushMatrix();
gluLookAt(player.xpos, player.ypos, player.zpos, player.xlook, player.ylook, player.zlook, 0.0, 1.0, 0.0);

glBindTexture(GL_TEXTURE_2D, texture[8]);
for(mapx = 0; mapx < (TERRAIN_LENGTH-2); mapx++){
for(mapz = 0; mapz < (TERRAIN_WIDTH-2); mapz++){
distance = sqrt((player.xpos-(float)mapx/TERRAIN_DETAIL)*(player.xpos-(float)mapx/TERRAIN_DETAIL) + (player.ypos-terrain_height[mapx][mapz])*(player.ypos-terrain_height[mapx][mapz]) + (player.zpos-(float)mapz/TERRAIN_DETAIL)*(player.zpos-(float)mapz/TERRAIN_DETAIL));
if(distance < CULL_DISTANCE){

glBegin(GL_TRIANGLE_STRIP);
glColor4f(1.0, 1.0, 1.0, alpha_values[mapx][mapz]);
glNormal3f(terrain_normals[mapx][mapz].x, terrain_normals[mapx][mapz].y, terrain_normals[mapx][mapz].z);
glTexCoord2f(0.0, 0.0); glVertex3f((float)mapx/TERRAIN_DETAIL, terrain_height[mapx][mapz], (float)mapz/TERRAIN_DETAIL);

glColor4f(1.0, 1.0, 1.0, alpha_values[mapx+1][mapz]);
glNormal3f(terrain_normals[mapx+1][mapz].x, terrain_normals[mapx+1][mapz].y, terrain_normals[mapx+1][mapz].z);
glTexCoord2f(0.0, TEXTURE_DETAIL); glVertex3f((float)(mapx+1)/TERRAIN_DETAIL, terrain_height[mapx+1][mapz], (float)mapz/TERRAIN_DETAIL);

glColor4f(1.0, 1.0, 1.0, alpha_values[mapx][mapz+1]);
glNormal3f(terrain_normals[mapx][mapz+1].x, terrain_normals[mapx][mapz+1].y, terrain_normals[mapx][mapz+1].z);
glTexCoord2f(TEXTURE_DETAIL, 0.0); glVertex3f((float)mapx/TERRAIN_DETAIL, terrain_height[mapx][mapz+1], (float)(mapz+1)/TERRAIN_DETAIL);

glColor4f(1.0, 1.0, 1.0, alpha_values[mapx+1][mapz+1]);
glNormal3f(terrain_normals[mapx+1][mapz+1].x, terrain_normals[mapx+1][mapz+1].y, terrain_normals[mapx+1][mapz+1].z);
glTexCoord2f(TEXTURE_DETAIL, TEXTURE_DETAIL); glVertex3f((float)(mapx+1)/TERRAIN_DETAIL, terrain_height[mapx+1][mapz+1], (float)(mapz+1)/TERRAIN_DETAIL);
glEnd();
}
}
}
glPopMatrix();
}
This is the relecant part of my render func:

glDisable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
renderTerrain();
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

glDisable(GL_LIGHTING);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
renderSnowTerrain();
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glDisable(GL_BLEND);

then this in my init func:

float LightPosition0[] = { 0.0, 2.0, 0.0, LIGHT_ALPHA };
float LightSpecular0[] = { 1.0, 1.0, 1.0, LIGHT_ALPHA };
float LightDiffuse0[] = { 1.0, 1.0, 1.0, LIGHT_ALPHA };
float LightAmbient0[] = { 1.0, 1.0, 1.0, LIGHT_ALPHA };

glLightfv(GL_LIGHT0, GL_POSITION, LightPosition0);
glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse0);
glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient0);
glEnable(GL_LIGHT0);

everything works if i dont turn the light on, if i do then it just draws one of the layers and the otehr is hidden


[This message has been edited by MrShoe (edited 12-07-2001).]