StMark's picture

OpenTK and material

I was puzzled some time why I did not see any material and I experimented a little
bit, so the whole issue was the lack of light, so "Fiat lux" and alas there was it.
I just used the example of the opentk with these nices quads spinning around (display list)

so instead of

               GL.Color3(0.3 + 0.7 * c * c, 0.3 + 1.4 * c * c, 0.7 - 0.7 * c * c);

just use

                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Ambient,new Color4(0.3f + 0.7f * c * c, 0.3f + 1.4f * c * c, 0.7f - 0.7f * c * c, 1.0f));
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse,  new Color4(0.3f + 0.7f * c * c, 0.3f + 1.4f * c * c, 0.7f - 0.7f * c * c, 1.0f));
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Specular,  new Color4(0.3f + 0.7f * c * c, 0.3f + 1.4f * c * c, 0.7f - 0.7f * c * c, 1.0f));
                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Emission,  new Color4(0.3f + 0.7f * c * c, 0.3f + 1.4f * c * c, 0.7f - 0.7f * c * c, 1.0f));

But the color of the quads is now yellow instead of blue which was the sample code. That's the next issue to solve

Here's the light

            float diffuseLight = 0.6f;
            float ambientLight = 1.0f;
            float specularLight = 0.7f;
 
            float[] lightKa = { ambientLight, ambientLight, ambientLight, 1.0f }; 
            float[] lightKd = { diffuseLight, diffuseLight, diffuseLight, 1.0f }; 
            float[] lightKs = { specularLight, specularLight, specularLight, 1.0f };          
 
            GL.Light(LightName.Light0, LightParameter.Ambient, lightKa);
            GL.Light(LightName.Light0, LightParameter.Diffuse, lightKd);
            GL.Light(LightName.Light0, LightParameter.Specular, lightKs);
 
            float[] lightPos = { 0.0f, 10.0f, -10.0f, 1.0f };
            GL.Light(LightName.Light0, LightParameter.Position, lightPos);
 
            GL.Enable(EnableCap.Light0);
            GL.Enable(EnableCap.Lighting);
Images
yellow

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
wcdeich4's picture

What do you think is the most efficient way to combine this w/ Vertex Buffer Objects?