Ejemplo n.º 1
0
        public void Save()
        {
            B = new VAO(Vertexes.Count);
            P = new Vector3[Vertexes.Count];
            N = new Vector3[Vertexes.Count];
            C = new Color4[Vertexes.Count];
            T = new Vector2[Vertexes.Count];
            for (int i = 0; i < Vertexes.Count; i++)
            {
                P[i] = Vertexes[i].Position;
                N[i] = Vertexes[i].Normal;

                C[i].R = Vertexes[i].Color.R * Defuse.R;
                C[i].G = Vertexes[i].Color.G * Defuse.G;
                C[i].B = Vertexes[i].Color.B * Defuse.B;
                C[i].A = Vertexes[i].Color.A * Defuse.A;

                T[i] = Vertexes[i].TextureCoords;
            }
            if (AutoNormal)
            {
                for (int i = 0; i < Vertexes.Count; i = i + 3)
                {
                    Vector3 n = EG.GetTriangleNormal(P[i], P[i + 1], P[i + 2]);
                    n.Normalize();
                    N[i]     = n;
                    N[i + 1] = n;
                    N[i + 2] = n;
                }
            }



            BP = new VBO();
            BP.SetData(P);
            B.AttachVBO(0, BP, 3, OpenTK.Graphics.OpenGL4.VertexAttribPointerType.Float, 0);

            BN = new VBO();
            BN.SetData(N);
            B.AttachVBO(1, BN, 3, OpenTK.Graphics.OpenGL4.VertexAttribPointerType.Float, 0);

            BC = new VBO();
            BC.SetData(C);
            B.AttachVBO(2, BC, 4, OpenTK.Graphics.OpenGL4.VertexAttribPointerType.Float, 0);

            BT = new VBO();
            BT.SetData(T);
            B.AttachVBO(3, BT, 2, OpenTK.Graphics.OpenGL4.VertexAttribPointerType.Float, 0);
        }
Ejemplo n.º 2
0
        public static void DrawTriangle(Vector3 vec, Vector3 vec1, Vector3 vec2, Color4 color)
        {
            P[0] = vec;
            P[1] = vec1;
            P[2] = vec2;

            C[0] = color;
            C[1] = color;
            C[2] = color;

            Vector3 normal = EG.GetTriangleNormal(vec, vec1, vec2);

            N[0] = normal;
            N[1] = normal;
            N[2] = normal;

            BP.SubData(P);
            BN.SubData(N);
            BC.SubData(C);
            //BT.SubData(T);
            UpdateStates(new Color4(0.1f, 0.1f, 0.1f, 1.0f), Color4.White);
            B.Draw(PrimitiveType.Triangles, 3);
        }
Ejemplo n.º 3
0
        private static void Wnd_RenderFrame(object sender, FrameEventArgs e)
        {
            val           += 0.04f;
            EG.LightEnable = true;

            {
                ShadowFraemBuffer.Use();
                //GL.DrawBuffer(DrawBufferMode.None);

                GL.Viewport(0, 0, 4098, 4098);
                GL.Clear(ClearBufferMask.DepthBufferBit);

                EG.MatrixMode(MatrixType.Projection);
                EG.LoadIndenty();
                EG.MultMatrix(Matrix4.CreateOrthographicOffCenter(-10, 10, -10, 10, -10, 20));


                EG.MatrixMode(MatrixType.View);
                EG.LoadIndenty();
                EG.MultMatrix(Matrix4.LookAt(new Vector3(1f, 19f, 1f), new Vector3(0f), Vector3.UnitY));

                EG.MatrixMode(MatrixType.Model);
                EG.LoadIndenty();


                Matrix4 bias_new = new Matrix4(
                    new Vector4(0.5f, 0f, 0f, 0f),
                    new Vector4(0f, 0.5f, 0f, 0f),
                    new Vector4(0f, 0f, 0.5f, 0f),
                    new Vector4(0.5f, 0.5f, 0.5f, 1f));

                EG.Bias = (EG.Model * (EG.View * EG.Projection)) * bias_new;



                EG.NotDefultProgram      = ShadowShader;
                EG.NotDefultUpdateStates = () =>
                {
                    Matrix4 onResult = (EG.Model * (EG.View * EG.Projection));
                    //  Matrix4 onResult = EG.Model * (EG.View * EG.Projection);
                    GL.UniformMatrix4(ShadowShader.GetUniformLocation("depthMVP"), false, ref onResult);
                };
                RenderWorld();
            }



            {
                GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
                GL.Viewport(0, 0, wnd.Width, wnd.Height);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);



                EG.NotDefultProgram = null;


                GL.ActiveTexture(TextureUnit.Texture5);
                GL.BindTexture(TextureTarget.Texture2D, ShadowFraemBuffer.DepthTextureObject);
                EG.ShadowMap = 5;



                EG.MatrixMode(MatrixType.Projection);
                EG.LoadIndenty();
                EG.MultMatrix(Matrix4.CreatePerspectiveFieldOfView((float)Math.PI / 4, (float)wnd.Width / (float)wnd.Height * (float)1.0f, 0.1f, 1000f));


                EG.MatrixMode(MatrixType.View);
                EG.LoadIndenty();
                EG.MultMatrix(Matrix4.LookAt(-5f, 5f, -5f, 0f, 0f, 0f, 0f, 1f, 0f));

                EG.MatrixMode(MatrixType.Model);
                EG.LoadIndenty();


                RenderWorld();

                GL.BindTexture(TextureTarget.Texture2D, 0);
            }



            ErrorCode code = GL.GetError();

            if (code != ErrorCode.NoError)
            {
                Console.WriteLine(code);
            }

            wnd.SwapBuffers();
        }
Ejemplo n.º 4
0
 public void Draw()
 {
     EG.UpdateStates(Ambient, Specular);
     B.Draw(RenderType, Vertexes.Count);
 }