Creating a spotlight

Hey everyone and first of all thanks for helping me!
I’m an absolute beginner with openGL. I tried to a lamp standing on a desk with very basic shapes. Now I want to add a spotlight shining on the desk. I already tried the following:

glPushMatrix();
	
	static float light1_pos[] = { 0.0, 0.4, 0.0, 1.0 };
	static float light1_dir[] = { 0.0, 1.0, 0.0, 1.0 };

	glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_dir);

	//lamp
	glPushMatrix();
		setColor(1, 1, 0);
		glRotatef(-30, 1, 0, 0);
		glTranslatef(0, 2, 3.5);
		glRotatef(90, 1, 0, 0);
		glScalef(1, 1, 1);
	
		myCylinder();
	glPopMatrix();

But this does not gave me an additional light at all. Whats wrong with that?

Thanks a lot!!!

kind regards

You aren’t setting any of the colours (GL_AMBIENT, GL_DIFFUSE or GL_SPECULAR). While GL_LIGHT0 has (1,1,1,1) as the initial value for both diffuse and specular, all other lights have (0,0,0,1) so you need to change that if you want the light to have any effect.

Also: did you add glEnable(GL_LIGHT1)?

Thanks for you quic answer. I tried it like this:

	glEnable(GL_LIGHTING);
	glEnable(GL_LIGHT1);
	static float light1_pos[] = { 0.0, 0.4, 0.0, 1.0 };
	static float light1_dir[] = { 0.0, 1.0, 0.0, 1.0 };
	static float light1_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
	static float light1_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };

	glLightfv(GL_LIGHT1, GL_POSITION, light1_pos);
	glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_dir);

	glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);

	//lamp
	glPushMatrix();
		setColor(1, 1, 0);
		glRotatef(-30, 1, 0, 0);
		glTranslatef(0, 2, 3.5);
		glRotatef(90, 1, 0, 0);
		glScalef(1, 1, 1);
	
		myCylinder();

But it still has now effect^^

Did you enable GL_LIGHT1? Have you enabled GL_LIGHTING? Does your model have normals?

Isn’t that what I did in the first two lines?
I wanted to keep it as simple as possible for now =)

Yes. Sorry, I missed that part.

Does your object have normals? Lighting (other than ambient) can’t work without them. Do the normals have the correct orientation? Vertices whose normals point away from the light won’t be illuminated.