Lighting problems

Started by
5 comments, last by Chupa 22 years, 1 month ago
I'm having trouble getting lighting to work in program that rotates a cube. All I see is the solid color of my cube, and no shading of any kind. I've read and re-read what to do, and I can't figure out where I'm going wrong... here are the relevant code segments:
void initLighting(void) {
  GLfloat mat_properties[] = {1, 1, 0, 1.0};
  GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0};
  GLfloat light_position[] = {5.0, 5.0, -5.0, 1.0 };
  glShadeModel(GL_SMOOTH);

  glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light);
  glLightfv(GL_LIGHT0, GL_AMBIENT, white_light);

  /* object color determined here */
  glMaterialfv(GL_FRONT, GL_AMBIENT, mat_properties);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_properties);

  glEnable(GL_LIGHTING);
  glEnable(GL_LIGHT0);
}
  
and in the display callback func:
glBegin(GL_QUADS);
	for(int i = 0; i < 6; i++)
	{
		GLfloat d1[3], d2[3], norm[3];
		for(int j = 0; j < 3; j++)
		{
			d1[j] = vdata[qindices[0]-1][j] - vdata[qindices[1]-1][j];
			d2[j] = vdata[qindices[2]-1][j] - vdata[qindices[1]-1][j];
		}
		normcrossprod(d1,d2,norm);
		glNormal3fv(norm);
		glVertex3fv(&vdata[qindices[0]-1][0]);
		glVertex3fv(&vdata[qindices[1]-1][0]);
		glVertex3fv(&vdata[qindices[2]-1][0]);
		glVertex3fv(&vdata[qindices[3]-1][0]);
	}

	glEnd();

  </pre>  
Thanks   </i> 

edit: there should be an  after the first qindices, but I don't know how to turn off the codes

Edited by - Chupa on March 22, 2002 6:04:47 PM    
Advertisement
Well, instead of setting the light to white 1.0,1.0,1.0, try setting it to something like 0.01,0.01,0.01 or so... That oughta do the trick...

Although I''m not sure what the standard of these should be: on one computer I have to set the values to 100 times greater than the original value. So on the one computer I use 10 (x3) and on the other I use 0.01 (x3) with the same graphical result.

Well, I kinda drifted from your problem to my problem but just try setting the amplitude of the color to something way less.

Also try setting the ambient to zero, this way only the light from the source will be applied, and when the source doesn''t reach a face, it must be black (if no other lights are applied)

/G
---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
Its your ambient light. Ambient lighting is basically how much default light you get, whether you are lit by a light or not. Since you set this to 100%, everything will be 100% lit whether its facing the light or not. Try .2, .2, .2 gray instead.
how can i do an enviroment light like inthose quake engines?
http://www.8ung.at/basiror/theironcross.html
your normal is not normalized to length 1.
could be a problem
either normalize it, or glEnable(GL_NORMALIZE) to let gl do it automatically..
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Well, besiror. I''m not sure what kind of technic they use in quake to get shadows and nice looking lighting effects. I think it''s lightmap or so, I haven''t seen quake in a long time. If you mean quake 1 I''m almost sure they use only ordinary vertex map...

If you really want state of the art lighting effects, you should check out developer.nvidia.com

/G

---GUI Programming Division Manager at Wildfire Gamesworking on the 0 A.D. project
My problem was what Gee said, the color was too bright.

Thanks!

This topic is closed to new replies.

Advertisement