I have the following code to set up for some 2D drawing using OpenTK. I originally wrote it without any lighting considerations, but later added the lighting block. This version of the code uses GL.Disable(EnableCap.Lighting); to disable the lighting and show the rendering the way it looked before I added lighting.

 GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate);
 GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);

 float d1=(float)Math.Cos(Counter.FrameCounter.CurrentValue / 10.0f);
 float d2=(float)Math.Sin(Counter.FrameCounter.CurrentValue / 10.0f);
 GL.Light(LightName.Light0, LightParameter.Position, new float[] { 100.0f, 100.0f, 50.5f, 1.0f});
 GL.Light(LightName.Light0, LightParameter.SpotCutoff, new float[] { 30.0f });
 GL.Light(LightName.Light0, LightParameter.SpotDirection, new float[] { d1, d2, -0.5f });
 GL.Light(LightName.Light0, LightParameter.SpotExponent, new float[] { 2.0f });
 GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 1.0f, 0.0f, 0.0f, 1.0f }); 
 GL.Light(LightName.Light1, LightParameter.Position, new float[] { 300.0f, 400.0f, 150.5f, 1.0f});
 GL.Light(LightName.Light1, LightParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f }); 


 GL.BindTexture(texTarget, texture.Texture);

That renders like this: Blended rendering

After switching lighting on (GL.Enable(EnableCap.Lighting);) the translucency (blending?) seems to have been disabled. How to I keep both features active? (Note that in addition to the translucent blue message appearing opaque white, the background in the first image contains a graphic equalizer, which is also no longer visible in the second image because it was behind a translucent layer.) Lighted rendering

  • \$\begingroup\$ I would assume that lights in addition to transforming r,g,b values of vertices in your scene also affect alpha component (in similar way). For example, the ambient light could have alpha component of 1.0f which would render everything opaque, so you might want to check that too. In addition, you might have to set alpha component of all lights to be 0.0. \$\endgroup\$ – JBeurer Nov 23 '16 at 5:52
  • \$\begingroup\$ Mind you, fixed-pipeline lighting is probably the most confusing part of old-school OpenGL to begin with, I would suggest avoiding using GL.Light - especially in 2d games. \$\endgroup\$ – JBeurer Nov 23 '16 at 5:58
  • \$\begingroup\$ Plus, you definitely have to turn off lighting when you're rendering UI etc. \$\endgroup\$ – JBeurer Nov 23 '16 at 6:01
  • \$\begingroup\$ I've switched to using shaders and implementing much better lighting effects in my fragment shader. \$\endgroup\$ – BlueMonkMN Nov 23 '16 at 12:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.