Esempio n. 1
0
        protected override void OnRenderFrame(FrameEventArgs e)
        {
            t += (float)e.Time;
            GL.ClearColor(0.1f, 0.1f, 0.1f, 1);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);


            Vector3 lightPos = new Vector3(0, 1, -1);
            Vector3 cubePos  = new Vector3(0);

            Matrix4 proj = cam.Projection;
            Matrix4 view = cam.View;


            #region oldCube

            /*
             * lightingShader.Use();
             * int viewPosLoc = lightingShader.GetUniformLoc("viewPos");
             * GL.Uniform3(viewPosLoc, cam.Position.X, cam.Position.Y, cam.Position.Z);
             *
             *
             * //material uniforms
             * //int matAmbientLoc = lightingShader.GetUniformLoc("material.ambient");
             * int matDiffuseLoc = lightingShader.GetUniformLoc("material.diffuse");
             * int matSpecularLoc = lightingShader.GetUniformLoc("material.specular");
             * int matShinyLoc = lightingShader.GetUniformLoc("material.shiny");
             *
             * diffuseMap.ActivateTextureUnit();
             * diffuseMap.Bind();
             * GL.Uniform1(matDiffuseLoc, diffuseMap.TextureUnitAsInt);
             * GL.Uniform3(matSpecularLoc, 0.5f, 0.5f, 0.5f);
             * GL.Uniform1(matShinyLoc, 32.0f);
             *
             *
             *
             *
             * //light colors / intensity
             * Vector3 lightColor = new Vector3(1);//new Vector3((float) Math.Sin(t + 2), (float)Math.Sin(t-0.2), (float)Math.Sin(t-1));
             * Vector3 diffColor = lightColor * 0.5f;
             * Vector3 ambColor = diffColor * 0.2f;
             *
             * //light uniforms
             * int lightAmbientLoc = lightingShader.GetUniformLoc("light.ambient");
             * int lightDiffuseLoc = lightingShader.GetUniformLoc("light.diffuse");
             * int lightSpecularLoc = lightingShader.GetUniformLoc("light.specular");
             * int lightPosLoc = lightingShader.GetUniformLoc("light.pos");
             * GL.Uniform3(lightAmbientLoc, ref ambColor);
             * GL.Uniform3(lightDiffuseLoc, ref diffColor);
             * GL.Uniform3(lightSpecularLoc, ref lightColor);
             * GL.Uniform3(lightPosLoc, ref lightPos);
             *
             */
            #endregion


            //draw cube
            lightingShader.Use();

            int matDiffuseLoc  = lightingShader.GetUniformLoc("material.diffuse");
            int matSpecularLoc = lightingShader.GetUniformLoc("material.specular");
            int matShinyLoc    = lightingShader.GetUniformLoc("material.shiny");

            diffuseMap.ActivateTextureUnit();
            diffuseMap.Bind();
            GL.Uniform1(matDiffuseLoc, diffuseMap.TextureUnitAsInt);
            GL.Uniform3(matSpecularLoc, 0.5f, 0.5f, 0.5f);
            GL.Uniform1(matShinyLoc, 32.0f);


            //light colors / intensity
            Vector3 lightColor = new Vector3(1);//new Vector3((float) Math.Sin(t + 2), (float)Math.Sin(t-0.2), (float)Math.Sin(t-1));
            Vector3 diffColor  = lightColor * 0.5f;
            Vector3 ambColor   = lightColor * 0.1f;

            //light uniforms
            int lightAmbientLoc  = lightingShader.GetUniformLoc("light.ambient");
            int lightDiffuseLoc  = lightingShader.GetUniformLoc("light.diffuse");
            int lightSpecularLoc = lightingShader.GetUniformLoc("light.specular");
            int lightPosLoc      = lightingShader.GetUniformLoc("light.pos");
            GL.Uniform3(lightAmbientLoc, ref ambColor);
            GL.Uniform3(lightDiffuseLoc, ref diffColor);
            GL.Uniform3(lightSpecularLoc, ref lightColor);
            GL.Uniform3(lightPosLoc, ref lightPos);



            Matrix4        model = Matrix4.CreateTranslation(cubePos);
            Transformation cubeTransformation = new Transformation(model, cam);
            cubeTransformation.SetUniforms(lightingShader);
            containerVao.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            containerVao.Unbind();



            //draw light
            lampShader.Use();

            model  = Matrix4.CreateScale(0.1f);
            model *= Matrix4.CreateTranslation(lightPos);
            Transformation lamTransform = new Transformation(model, cam);
            lamTransform.SetUniforms(lampShader);

            lampVao.Bind();
            GL.DrawArrays(PrimitiveType.Triangles, 0, 36);
            lampVao.Unbind();

            this.SwapBuffers();
            base.OnRenderFrame(e);
        }