View Full Version : Problem with trying to add lighting to a level loading 'engine'

10-21-2004, 12:38 PM
Hey, i've been having problems adding some light to NeHe's lesson 10 (i'm further than that, just didn't play with that code until now.), no i'm not just adding a little light, i'm trying to load the light from a level file (world.txt).

I get these errors when compiling with Dev-C++:
- C:\Documents and Settings\Joost\My Documents\Mijn ontvangen bestanden\forumfun\lesson10\lesson10.cpp In function `void SetupWorld()':
- 132 C:\Documents and Settings\Joost\My Documents\Mijn ontvangen bestanden\forumfun\lesson10\lesson10.cpp invalid initializer
- C:\Documents and Settings\Joost\My Documents\Mijn ontvangen bestanden\forumfun\lesson10\Makefile.win [Build Error] [lesson10.o] Error 1

This is my function 'SetupWorld()':

void SetupWorld()
float x, y, z, u, v;
int numtriangles;
FILE *filein;
FILE *filein2;
char oneline[255];
filein = fopen("data/world.txt", "rt"); // File To Load World Data From
filein2 = fopen("data/world.txt", "rt");
char nothing;
float light1;
float light2;
float light3;
float light4;
float light5;
float light6;
float light7;
float light8;
float light9;
float light10;
float light11;
float light12;
sscanf(oneline, "NUMPOLLIES %d\n", &numtriangles);
sscanf(oneline2, "%c %f %f %f %f %f %f %f %f %f %f %f %f ", &nothing, &light1, &light2, &light3, &light4, &light5, &light6, &light7, &light8, &light9, &light10, &light11, &light12);

sector1.triangle = new TRIANGLE[numtriangles];
sector1.numtriangles = numtriangles;
for (int loop = 0; loop < numtriangles; loop++)
for (int vert = 0; vert < 3; vert++)
sscanf(oneline, "%f %f %f %f %f", &amp;x, &amp;y, &amp;z, &amp;u, &amp;v);
sector1.triangle[loop].vertex[vert].x = x;
sector1.triangle[loop].vertex[vert].y = y;
sector1.triangle[loop].vertex[vert].z = z;
sector1.triangle[loop].vertex[vert].u = u;
sector1.triangle[loop].vertex[vert].v = v;

GLfloat LightAmbient[]= (light1, light2, light3, light4);
GLfloat LightDiffuse[]= { light5, light6, light7, light8 }; // Diffuse Light Values ( NEW )
GLfloat LightPosition[]= { light9, light10, light11, light12};

glEnable(GL_LIGHT1); // Quick And Dirty Lighting (Assumes Light0 Is Set Up)
glEnable(GL_LIGHTING); // Enable Lighting
glEnable(GL_COLOR_MATERIAL); // Enable Material Coloring // Light Position ( NEW )

glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
} This is the structure of light lines in my world.txt file:

l 0.5 0.5 0.5 1.0 1.0 1.0 1.0 1.0 0.0 0.0 2.0 1.0
// ambient 1, 2, 3, 4 diffuse 1, 2, 3 4, position 1, 2, 3, 4Please tell me what is causing these errors.

10-26-2004, 05:13 AM

10-26-2004, 10:04 AM
Well your compiler tells you exactly whats wrong and in which line too (132).

Just change this:

GLfloat LightAmbient[]= (light1, light2, light3, light4);into this:

GLfloat LightAmbient[]= {light1, light2, light3, light4};and the error will go away. Listen to your compiler he knows the truth ;) .

10-29-2004, 12:49 AM
Oh thanks, can't believe i didn't think of that. :confused: :)