Author Topic: Setting an angular light in OpenGL.  (Read 3410 times)

0 Members and 1 Guest are viewing this topic.

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Setting an angular light in OpenGL.
« on: December 22, 2008 »

I know how to set a light in OpenGL but I cannot quite figure out how to set a directional vector for it.

I whipped this up in AutoCAD to show what I mean. The view here is isometric to show how the light rises above the canvas then points back down at an angle. I've checked on line documentation but find it a bit confusing. Now I could be wrong but I think AutoCAD uses OpenGL to render in this old version so hopefully the effects will be transferable.

Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Setting an angular light in OpenGL.
« Reply #1 on: December 22, 2008 »
For directional lights you simply set the 4th component of the light's position to zero which will set it infinitely far away.
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Setting an angular light in OpenGL.
« Reply #2 on: December 22, 2008 »
Wouldn't the lights have no direction if they were infinitely far away?

The light I need should rise above the drawing area and shine back down on the drawing. The drawing is what I want even though it was done in a drafting program. It is isometric to show how the light is positioned. By default the lights make everything appear fully lit because I assume the default view is parallel to the light source.
Challenge Trophies Won:

Offline hellfire

  • Sponsor
  • Pentium
  • *******
  • Posts: 1294
  • Karma: 466
    • View Profile
    • my stuff
Re: Setting an angular light in OpenGL.
« Reply #3 on: December 23, 2008 »
Even if it's at infinity you can still tell the direction (just like the sun), so all light-rays are parallel which is exactly what you want.
See here and have a look at homogenous coordinates.
Challenge Trophies Won:

Offline Pixel_Outlaw

  • Pentium
  • *****
  • Posts: 1382
  • Karma: 83
    • View Profile
Re: Setting an angular light in OpenGL.
« Reply #4 on: December 23, 2008 »
GREAT thanks!

Have some karma.
Challenge Trophies Won: