   [.net] OpenTK lighting problems
  Heey all,Well, it may not be a OpenTK problem but it is really a problem.I am trying to add light to my scene, but I can't get it to work. I have looked at various tutorials on the internet, and did everything they did and: it doesn't work:- eighter there simply is NO lighting, my mesh is just plain white or the model is turned black.I have been trying for the past 5 days to get it working, but no succes.Can anybody see my error(s)?Thanks in advance,assainatorMy code:this is my glControl1_load functionprivate void glControl1_Load(object sender, EventArgs e)   {  GL.ClearColor(Color.Black);  Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;  float[] light_ambient = { 0.5f, 0.5f, 0.5f, 1.0f };  float[] light_diffuse = { 1.0f, 1.0f, 1.0f, 1.0f };  float[] light_position = { 0.0f, 0.0f, 10000.0f, 0.0f };  GL.ShadeModel(ShadingModel.Smooth);  GL.Enable(EnableCap.Lighting);  GL.Enable(EnableCap.DepthTest);  GL.DepthFunc(DepthFunction.Lequal);  GL.Light(LightName.Light1, LightParameter.Ambient, light_ambient);  GL.Light(LightName.Light1, LightParameter.Diffuse, light_diffuse);  GL.Light(LightName.Light1, LightParameter.Position, light_position);  GL.Enable(EnableCap.Light1);  GL.Enable(EnableCap.ColorMaterial);  DisplayModel = new Mesh();  DisplayModel.UseNormals = true;  Application.Idle += Application_Idle;  SetupViewport(glControl1);  Loaded = true;   }The Render function[source lang="C#]glControl1.MakeCurrent();  GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);  DisplayModel.Render();  glControl1.SwapBuffers();the function that renders the model (the Mesh class)public void Render()   {  if (DoRender)  { for (int x = 0; x < Triangles.Count; x++) {GL.Begin(BeginMode.Triangles);if (UseVertexColor)    GL.Color3(Vertices[Triangles[x].V1].R, Vertices[Triangles[x].V1].G, Vertices[Triangles[x].V1].B);else    GL.Color3(Color.White);if (UseNormals)    GL.Normal3(Triangles[x].Normal.X, Triangles[x].Normal.Y, Triangles[x].Normal.Z);GL.Vertex3(Vertices[Triangles[x].V1].X, Vertices[Triangles[x].V1].Y, Vertices[Triangles[x].V1].Z);if (UseVertexColor)    GL.Color3(Vertices[Triangles[x].V2].R, Vertices[Triangles[x].V2].G, Vertices[Triangles[x].V2].B);if (UseNormals)    GL.Normal3(Triangles[x].Normal.X, Triangles[x].Normal.Y, Triangles[x].Normal.Z);GL.Vertex3(Vertices[Triangles[x].V2].X, Vertices[Triangles[x].V2].Y, Vertices[Triangles[x].V2].Z);if (UseVertexColor)    GL.Color3(Vertices[Triangles[x].V3].R, Vertices[Triangles[x].V3].G, Vertices[Triangles[x].V3].B);if (UseNormals)    GL.Normal3(Triangles[x].Normal.X, Triangles[x].Normal.Y, Triangles[x].Normal.Z);GL.Vertex3(Vertices[Triangles[x].V3].X, Vertices[Triangles[x].V3].Y, Vertices[Triangles[x].V3].Z);    GL.End(); }  }   }
  It's been years since I last used fixed-function vertex lighting, but looking through my code I can spot a few differences. Here is my init routine for reference:GL.Enable(EnableCap.DepthTest);// Enable Light 0 and set its parameters.GL.Light(LightName.Light0, LightParameter.Position, new float[] { 1.0f, 1.0f, -0.5f });GL.Light(LightName.Light0, LightParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });GL.Light(LightName.Light0, LightParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });GL.Light(LightName.Light0, LightParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });GL.Light(LightName.Light0, LightParameter.SpotExponent, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });GL.LightModel(LightModelParameter.LightModelAmbient, new float[] { 0.2f, 0.2f, 0.2f, 1.0f });GL.LightModel(LightModelParameter.LightModelTwoSide, 1);GL.LightModel(LightModelParameter.LightModelLocalViewer, 1);GL.Enable(EnableCap.Lighting);GL.Enable(EnableCap.Light0);Use GL.Material to set your object's material parameters.GL.Material(MaterialFace.Front, MaterialParameter.Ambient, new float[] { 0.3f, 0.3f, 0.3f, 1.0f });GL.Material(MaterialFace.Front, MaterialParameter.Diffuse, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });GL.Material(MaterialFace.Front, MaterialParameter.Specular, new float[] { 1.0f, 1.0f, 1.0f, 1.0f });GL.Material(MaterialFace.Front, MaterialParameter.Emission, new float[] { 0.0f, 0.0f, 0.0f, 1.0f });Rendering is identical to yours.Two differences that jump out at me is that you are using Light1 instead of Light0 (which may or may not make a difference) and that you are enabling ColorMaterial which (IIRC) modifies the lighting calculations to take vertex color into account (which means you'll get black output unless you specify vertex colors explicitly). See this for more details: http://www.sjbaker.org/steve/omniv/opengl_lighting.htmlEdit: you can move GL.Begin()/GL.End() outside the for-loop for a pretty significant performance improvement.   ;  Thanks,after I applied your advice I got a dark gray color (that would be the ambient color) so I thought something had to be wrong with the normals. I found out that when the model was loaded, that the normals where shut off. Therefor the model getting no normals. I fixed it and I can now enjoy lighting!thanks again!   