# Settiing more than 1 Light Source Problem

I want to set 3 Light Sources. I define Array of 3 GLfloat - Position of each Source, and write simple “for” loop inside glBegin and glEnd, where I set Light Properties and write glEnable(LIGHT0 + i) for each source. BU-U-UT, It draws only the first source. Any propositions for rookie? Thnx.
Best Regards from Kyyv.

Hi !

Have a peek at the docs, you can only use glVertex…, glColor… and a few other functions between glBegin and glEnd.

Mikael

I may be completely misunderstanding you but if your code is

for(int i=0; i<BLAH; i++)
{
//do stuff
glEnable(GL_LIGHT0 + i)
//do more
}
it won’t work
GL_LIGHT0, GL_LIGHT1 etc are all predefined constants and you cannot get from one to the other just by adding, try using a case statement
ie
switch(i)
{
case 0:
glenable(GL_LIGHT0);
break;
etc…
}

Excuse me:
(from gl.h)
#define GL_LIGHT0 0x4000
#define GL_LIGHT1 0x4001
#define GL_LIGHT2 0x4002
#define GL_LIGHT3 0x4003
#define GL_LIGHT4 0x4004
#define GL_LIGHT5 0x4005
#define GL_LIGHT6 0x4006
#define GL_LIGHT7 0x4007

So, if I add 1 to GL_LIGHT0 I will get GL_LIGHT1
0x4000 + 1 = 0x4001 (GL_LIGHT1)

or there is a difference between:

• 0x4000 + 1 = 0x4001 (GL_LIGHT1)
and
• 0x4000 + 0x1 = 0x4001 (GL_LIGHT1)

sorry then…

[This message has been edited by moxx (edited 01-13-2002).]

Do it outside your glBegin and glEnd.

mox, your approach of incrementing the constant is correct. Robin Forster has your solution.

Actually, I Use glEnable(GL_LIGHT[i]) only inside “for”, And I initialize All Light Attributes there (in the “for” loop), but it’s enables only the first Souce (GL_LIGHT0)

Are you setting the light properties properly? (Ex: GL_DIFFUSE, GL_AMBIENT) Because the default light for light0 is {1, 1, 1, 1} (RGBA) i.e white light and for all other light sources it is {0,0,0,1} i.e black. So even if you enable them there will be no difference.

Hope this helps.

… finally it works…
thanx
I only had to set diffuse, ambient and specular colors separetely.

My teacher always told me: “max, you should think first then do something and ask somebody”

thnx