How to add light in TORCS

"ju jackie" <[email protected]> Thu, 31 Jul 2008 03:32:58 +0800
Newsgroups gmane.games.torcs.devel
Message-ID <[email protected]>
Hi All,

I am trying to make TORCE night-mode racing . I spent plenty of time
on adding some light, but failed.
The first thing is the the a3cd loader (grloadac.cpp->myssgLoadAC())
doesn't load light in ac file.
So I tried to add some fixed light sourcesfirstly, but didn't get the
effection. Here is my function called in
grscene.cpp->grInitScene(void)

void testLight(){

	static float light_ambient[] = {0.1,0.1,0.1,1.0};
static float light_diffuse[] = {0.5,1.0,1.0,1.0};
static float light_position[] = {0,0,1,0.0};
static float light_direction[] = {-90.0,-90.0,-150.0,0.0};
static float light_cutoff[] = {90.0};

static float front_mat_shininess[] = {60.0};
static float front_mat_specular[] = {0.2,0.2,0.2,1.0};
static float front_mat_diffuse[] = {0.5,0.5,0.28,1.0};

static float back_mat_shininess[] = {60.0};
static float back_mat_specular[] = {0.5,0.5,0.2,1.0};
static float back_mat_diffuse[] = {1.0,0.9,0.2,1.0};

static float Imodel_ambient[] = {1.0,1.0,1.0,1.0};
static float Imodel_twoside[] = {GL_TRUE};
static float Imodel_oneside[] = {GL_FALSE};

	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);

	// set light source
	glLightfv(GL_LIGHT7,GL_AMBIENT,light_ambient);
	glLightfv(GL_LIGHT7,GL_DIFFUSE,light_diffuse);
	glLightfv(GL_LIGHT7,GL_POSITION,light_position);
	//glLightfv(GL_LIGHT7, GL_SPOT_DIRECTION, light_direction);
	//glLightfv(GL_LIGHT7, GL_SPOT_CUTOFF, light_cutoff);

       // set material
	glMaterialfv(GL_FRONT,GL_DIFFUSE,front_mat_diffuse);
	glMaterialfv(GL_FRONT,GL_SPECULAR,front_mat_specular);
	glMaterialfv(GL_FRONT,GL_SHININESS,front_mat_shininess);

	glMaterialfv(GL_BACK,GL_DIFFUSE,back_mat_diffuse);
	glMaterialfv(GL_BACK,GL_SPECULAR,back_mat_specular);
	glMaterialfv(GL_BACK,GL_SHININESS,back_mat_shininess);

	// set lighting parameter
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT,Imodel_ambient);
	glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,Imodel_twoside);

	// enable light
	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT7);
	glShadeModel(GL_SMOOTH);
	
}

And I adjust the material in scene using AC3D and blender, to make
sure the object in scene will be lighten by any lighting.

And I tried all kinds lighting sources in any position with any
parameter, but always no effect. This made me really frustrated.
Another strange thing is, I found that in file "grInitScene.cpp"
function "int grInitScene(void)", if I remove the fog by commeting out
lines:
  //         glFogi(GL_FOG_MODE, GL_LINEAR);
   //        glFogfv(GL_FOG_COLOR, fog_clr);
   //        glFogf(GL_FOG_DENSITY, 0.05);
   //        glHint(GL_FOG_HINT, GL_DONT_CARE);
Then nothing can be seen in game except the sky.

I am wondering  there was some very simple and stupid mistake I'v
made, but I couldn't fingure it out.
Can anybody kindly shed me some light? I will very appreciat it.
Thanks in advance !

Best Regards,
Jackie Ju

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/