コード例 #1
0
ファイル: Program.cs プロジェクト: xuri02/Xuri-OpenGl-CPP
        public Program()
        {
            InternalInit();

            Console.WriteLine("Shaders: " + ShaderPos + "\n	[" + vertexShader + ", " + fragmentShader + "]");

            shader = new Shader((this.ShaderPos + this.vertexShader), (this.ShaderPos + this.fragmentShader));
            shader.bind();
            PrintStatus('S', shader.GetShaderID(), "-> Shader", 9, 1);

            directionLocation = GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.direction");
            sunColor          = new Vector3(.8f);
            sunDirection      = new Vector3(0f, -1f, 0f);
            var z    = new Vector3(0.0000001f);
            int zero = 0;

            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.diffuse"), ref sunColor);
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.specular"), ref z);
            sunColor *= 0.2F;
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_directional_light.ambient"), ref sunColor);
            //GL.Uniform1iv(GL.GetUniformLocation(shader.GetShaderID(), "u_use_sun"),1,(int*)&zero));

            Vector3 pointColor = new Vector3(0, 0, 30);

            //pointColor *= 0;
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.diffuse"), ref pointColor);
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.specular"), ref pointColor);
            pointColor *= 0.2F;
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.ambient"), ref pointColor);
            GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.linear"), 0.027f);
            GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_point_light.quadratic"), 0.0028f);
            pointLightPosition = new Vector4(1f, 1f, 10f, 1f);
            pointLightLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_point_light.position");

            spotColor = new Vector3(2);
            //spotColor *= 0;
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.diffuse"), ref spotColor);
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.specular"), ref spotColor);
            spotColor *= 0.1F;
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.ambient"), ref spotColor);
            Vector3 spotLightPosition = new Vector3(0.0F);

            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.position"), ref spotLightPosition);
            spotLightPosition.Z = 1.0f;
            GL.Uniform3(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.direction"), ref spotLightPosition);
            GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.innerCone"), 0.99f);
            GL.Uniform1(GL.GetUniformLocation(shader.GetShaderID(), "u_spot_light.outerCone"), 0.98f);

            string path = (ModelsPos);
            string ext  = (".bmf");
            int    idx  = 0;

            foreach (var p in new DirectoryInfo(path).GetFiles())
            {
                if (p.Extension == ext)
                {
                    Console.WriteLine("Loading: " + p + '\n');
                    var   t     = p.FullName;
                    Model model = new Model(t, shader);
                    model.Init();
                    models.Add(model);
                    var Matrix4X = new mat4(1.0F);
                    Matrix4X = glm.translate(Matrix4X, new vec3(100 * (idx++), 0, 0));
                    Matrix4X = glm.scale(Matrix4X, new vec3(.2f));
                    mats.Add(Matrix4X.M());
                }
            }

            camModelRender = glm.scale(new mat4(1.0F), new vec3(.2f)).M();

            //model_rotate      = scale(model_rotate, Vector3(.1F));

            camera = new FPSCamera(90.0F, 1000, 800);
            camera.Translate(new Vector3(0, 0, 5.0f));
            camera.update();

            modelViewProj = camera.GetViewProj() * camModelRender;

            modelViewProjMatrixLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_modelViewProj");

            modelViewLocation    = GL.GetUniformLocation(this.shader.GetShaderID(), "u_modelView");
            invModelViewLocation = GL.GetUniformLocation(this.shader.GetShaderID(), "u_invModelView");

            //GL.PolygonMode (GL_FRONT_AND_BACK,GL_LINE);

            float camaraSpeed = 60.0F;

            GL.Enable(EnableCap.DepthTest);
        }