Youg 0 Newbie Poster

Been struggling with this the past hour, so need some help. I'm trying to light my screen with objects that already have set color values glColor3f... I've included the glColorMaterial and its enable within my lighting function however, it lights the scene with the last set color which is red even after I've told it to clear. Once you take out the object that is drawing in red it loses all depth on the objects still present.

I've put the coding for just the light function below, though if anyone wants to see more just ask.

void lighting()
{

	GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 }; //white
	GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; //red
	GLfloat light_ambient[] = { 0.0, 0.0, 0.0, 1.0 }; //black


	//light position
	GLfloat light_position[] = {1.0, 1.0, 0.0, 1.0}; 
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);


	glLightfv(GL_LIGHT0,GL_DIFFUSE, light_diffuse);

	glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);

	glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);


	GLfloat mat_shininess[] = {0.0};
	GLfloat mat_amb_diff[]= {1.0, 0.5, 0.8, 1.0};
	GLfloat mat_spec[]= {1.0, 1.0, 1.0, 1.0};

	glClearColor(0.0, 0.0, 0.0, 0.0);
	glShadeModel (GL_SMOOTH);
 
	glMaterialfv(GL_FRONT,GL_SPECULAR, mat_spec);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mat_amb_diff);
	glMaterialf(GL_FRONT, GL_EMISSION, (0,0,0,1));
 
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	glLightf(GL_LIGHT0, GL_DIFFUSE, (1,1,1,1));

	glLightf(GL_LIGHT0, GL_AMBIENT,(0,0,0,1));

	glLightf(GL_LIGHT0, GL_SPECULAR,(1,1,1,1));

	glLightModelf(GL_LIGHT_MODEL_LOCAL_VIEWER, 1.0);

	//enables the use of glColor commands
	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT_AND_BACK, GL_EMISSION);

	glEnable(GL_COLOR_MATERIAL);
	glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);


//       GLfloat light_diffuse[]= {0.0,0.0,1.0,1.0};
//	glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse);
		
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT0);
	glEnable(GL_DEPTH_TEST); 
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.