Direct x equivilent in opengl


Is there an equivilent to the opengl point light in opengl?

Example code :

  // Fill in a light structure defining our light
  D3DLIGHT9 light;
  ZeroMemory( &light, sizeof(D3DLIGHT9) );
  light.Type       = D3DLIGHT_POINT;
  light.Diffuse.r  = 1.0f;
  light.Diffuse.g  = 1.0f;
  light.Diffuse.b  = 1.0f;
  // Point lights have no direction but do have a position
  light.Position = pos
  // Tell the device about the light and turn it on
  light.Attenuation0 = 0.1f;
  gD3dDevice->SetLight( 1, &light );
  gD3dDevice->LightEnable( 1, TRUE );


Yes. For legacy fixed function lighting, see

Sure. But you don’t set the values this way.

Check out:

BTW, this was a 1 sec Google search. But since I’m in a good mood I don’t mind.

Thanks but I have seen the webpage you have linked and it doesn’t answer my specific question.

In directx there are multiple types of light

Ambient Light
Spot Light
Directional Light
Point Light

The first three map very well to opengl but the point light doesn’t

The specific parameter of interest in the example I posted was


This is where I took the example from.

The range is the maximum distance the light can travel, the attenuation is covered as you say in the links posted above but the important bit of the point light is the range, ie where the spot light is no longer relevant and the ambient light is now the default.

I believe the range parameter doesn’t exist in GL.

In fixed-function OpenGL lights are identified by the information you pass.


By default, for instance, a light source has the position (0, 0, 1, 0) (notice the w-component). This means you have a directional light source. The direction is the default value of GL_SPOT_DIRECTION: (0, 0, -1, 0).

If you want to have a point light source you need to set a position other than the default and a w-component > 0.

If you want a spot light source you also need to set a different GL_SPOT_CUTOFF since the default is the special value 180.

Yeah I thought so as the documentation doesn’t mention anything like this (but wanted to confirm), does anyone know how wine gets round this then as they render directx commands in to opengl and can render point like directx programs?

Nope. Not using FF. But if you think about it, that’s actually more realistic since you can’t tell light rays to suddenly vanish at some distance. :slight_smile:

I think Wine will simply ignore the distance calculation.

the attenuation in opengl is rubbish, its almost impossible to say… be very bright at the spot of the point light then fade out gradually till at radius 200 you have blended in with the ambient light.

I may also be very bad at attenuation in opengl :slight_smile:

Also with spot light I found that if you are outside of the degree’s of spotlight it is pitch black or very dark. That isn’t too relistic to me.

Actually the attenuation factor is exactly the same as in Direct3D. I think you’re doing it wrong.

EDIT: BTW, neither the GL nor D3D are realistic when it comes to attenuation, since the physically correct attenuation is merely 1 / d ^ 2. The thing is that with three factors you can tweak the attenuation more so you get the desired visual result - still, it’s not physically correct.

EDIT2: Considering the range, in the real world there is no such thing. In geometric optics the luminance some differential area receives decreases with the squared distance, so not providing the user with an explicitly value from to indicate that all calculations be discarded IS more realistic.

EDIT3: The fact that there’s no incident light outside the spot lights cone is mathematically correct. D3D simply maintains two spot cutoff angles. In the range between the two the lighting contributions are simply faded out by some function (linear for instance).

I think Wine will simply ignore the distance calculation.[/QUOTE]

I would image Wine ignores it as well. I don’t feel like looking at the code.
Also, not many games use D3DLIGHT. They then to use light maps.

Or they would be using shaders and the people working on Wine concentrate a lot of their work writing code converters.

the attenuation in opengl is rubbish, its almost impossible to say… be very bright at the spot of the point light then fade out gradually till at radius 200 you have blended in with the ambient light.

That’s because light doesn’t work that way. It’s only “rubbish” if you insist on using non-gamma-correct lighting, non-HDR lighting, and unrealistic light attenuation. If you’re doing anything remotely conversant with reality, it’s fine.