Ejemplo n.º 1
0
        protected override void OnLoad(EventArgs e)
        {
            prog = new ShaderProgram(Shader.FromFile(vertPath), Shader.FromFile(fragPath));

            textureWall      = new Texture(System.Drawing.Image.FromFile("Data/wall.jpg"), 0, "wall");
            textureContainer = new Texture(System.Drawing.Image.FromFile("Data/container2.png"), 1, "container");



            vbo = new VertexBuffer <float>();
            vbo.Bind();
            vbo.BufferData(vertices);


            vao = new VertexArray();
            vao.Bind();

            ibo = new IndexBuffer();
            ibo.Bind();
            ibo.BufferData(indices);

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 5 * 4, 0);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(1, 2, VertexAttribPointerType.Float, false, 5 * 4, 3 * 4);
            GL.EnableVertexAttribArray(1);

            vao.Unbind();
            ibo.Unbind();
            vbo.Unbind();
            prog.Use();

            GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
        }
Ejemplo n.º 2
0
            internal TerrainBlock(Terrain owner, List <int> indices, BoundingBox box, int subdivision)
            {
                bounds = box;

                if (subdivision < owner.Subdivisions)
                {
                    Vector3 new_size = box.Size / 2;
                    new_size.y = box.Size.y;
                    float offset = box.Size.x / 4;

                    children = new List <TerrainBlock>();

                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset)
                    }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, offset)
                    }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset)
                    }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset)
                    }, subdivision + 1));
                }
                else
                {
                    List <int> mil = new List <int>();
                    for (int i = 0; i < indices.Count; i += 3)
                    {
                        var i1 = indices[i];
                        var i2 = indices[i + 1];
                        var i3 = indices[i + 2];

                        var v1 = owner.vb[i1];
                        var v2 = owner.vb[i2];
                        var v3 = owner.vb[i3];

                        var p1 = new Vector2(box.Position.x - box.Size.x / 2, box.Position.z - box.Size.z / 2);
                        var p2 = new Vector2(box.Position.x + box.Size.x / 2, box.Position.z + box.Size.z / 2);

                        if ((v1.Position.x >= p1.x && v1.Position.x <= p2.x && v1.Position.z >= p1.y && v1.Position.z <= p2.y) ||
                            (v2.Position.x >= p1.x && v2.Position.x <= p2.x && v2.Position.z >= p1.y && v2.Position.z <= p2.y) ||
                            (v3.Position.x >= p1.x && v3.Position.x <= p2.x && v3.Position.z >= p1.y && v3.Position.z <= p2.y))
                        {
                            mil.Add(i1);
                            mil.Add(i2);
                            mil.Add(i3);
                        }
                    }
                    ib = new IndexBuffer <int>();
                    ib.Allocate(mil);
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    //mil.Clear();
                }
            }
Ejemplo n.º 3
0
        public void InitializeGraphics()
        {
            if (mat == null)
            {
                owner.Resources.Load("shaders\\Grid", out mat);
            }
            if (vb == null)
            {
                vb = new VertexBuffer <VertexPositionColor>(VertexPositionColor.Descriptor);
                vb.Allocate(8);
            }
            if (ib == null)
            {
                ib = new IndexBuffer <uint>();
                ib.Allocate(24);
                ib[0] = 0;
                ib[1] = 1;
                ib[2] = 1;
                ib[3] = 2;
                ib[4] = 2;
                ib[5] = 3;
                ib[6] = 3;
                ib[7] = 0;

                ib[8]  = 4;
                ib[9]  = 5;
                ib[10] = 5;
                ib[11] = 6;
                ib[12] = 6;
                ib[13] = 7;
                ib[14] = 4;

                ib[15] = 0;
                ib[16] = 4;

                ib[17] = 1;
                ib[18] = 5;

                ib[19] = 2;
                ib[20] = 6;

                ib[21] = 3;
                ib[22] = 7;
                ib.BufferData(VboUsage.GL_STATIC_DRAW);
            }

            if (points != null)
            {
                for (int i = 0; i < 8; i++)
                {
                    vb[i] = new VertexPositionColor()
                    {
                        Position = points[i], Color = Colors.Yellow
                    };
                }
            }

            vb.BufferData(VboUsage.GL_DYNAMIC_DRAW);
        }
Ejemplo n.º 4
0
            internal TerrainBlock(int x_start, int y_start, int x_count, int y_count, BoundingBox box, int subdivision, Terrain owner)
            {
                bounds = box;
                if (subdivision < owner.Subdivisions)
                {
                    x_count /= 2;
                    y_count /= 2;
                    Vector3 new_size = box.Size / 2;
                    new_size.y = box.Size.y;
                    float offset = box.Size.x / 4;

                    children = new List <TerrainBlock>();

                    children.Add(new TerrainBlock(x_start, y_start, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset)
                    }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, offset)
                    }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start + y_count, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset)
                    }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start, y_start + y_count, x_count, y_count, new BoundingBox()
                    {
                        Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset)
                    }, subdivision + 1, owner));
                }
                else
                {
                    ib = new IndexBuffer <int>();
                    ib.Allocate(6 * (x_count) * (y_count));
                    int index = 0;
                    for (int i = 0; i < y_count; i++)
                    {
                        for (int j = 0; j < x_count; j++)
                        {
                            int i1 = (y_start + i) * owner.heightmap.Width + x_start + j;
                            int i2 = (y_start + i) * owner.heightmap.Width + x_start + j + 1;
                            int i3 = (y_start + i + 1) * owner.heightmap.Width + x_start + j + 1;
                            int i4 = (y_start + i + 1) * owner.heightmap.Width + x_start + j;

                            ib[index++] = i1;
                            ib[index++] = i3;
                            ib[index++] = i2;

                            ib[index++] = i1;
                            ib[index++] = i4;
                            ib[index++] = i3;
                        }
                    }
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    ib.FreeClientData();
                }
            }
Ejemplo n.º 5
0
        protected override void Build()
        {
            vb = new VertexBuffer <Vector3>(Vector3.Descriptor);

            vb.Allocate(8);
            ib = new IndexBuffer <ushort>();
            ib.Allocate(4 * 6);

            vb[0] = new Vector3(-0.5f, -0.5f, -0.5f);
            vb[1] = new Vector3(0.5f, -0.5f, -0.5f);
            vb[2] = new Vector3(0.5f, 0.5f, -0.5f);
            vb[3] = new Vector3(-0.5f, 0.5f, -0.5f);

            vb[4] = new Vector3(-0.5f, -0.5f, 0.5f);
            vb[5] = new Vector3(0.5f, -0.5f, 0.5f);
            vb[6] = new Vector3(0.5f, 0.5f, 0.5f);
            vb[7] = new Vector3(-0.5f, 0.5f, 0.5f);

            ib[0] = 0;
            ib[1] = 1;
            ib[2] = 2;
            ib[3] = 3;

            ib[4] = 4;
            ib[5] = 0;
            ib[6] = 3;
            ib[7] = 7;

            ib[8]  = 5;
            ib[9]  = 4;
            ib[10] = 7;
            ib[11] = 6;

            ib[12] = 1;
            ib[13] = 5;
            ib[14] = 6;
            ib[15] = 2;

            ib[16] = 6;
            ib[17] = 7;
            ib[18] = 3;
            ib[19] = 2;

            ib[20] = 0;
            ib[21] = 4;
            ib[22] = 5;
            ib[23] = 1;

            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            // Client data is no longer needed. Free it!
            vb.FreeClientData();
            ib.FreeClientData();
        }
Ejemplo n.º 6
0
        public BoneDebugger([NotNull, ItemNotNull] IReadOnlyList <BoneNode> boneList, [NotNull] SimpleColor simpleColor)
        {
            _simpleColor = simpleColor;
            _boneList    = boneList;

            var vertexBuffer = new VertexBuffer();
            var indexBuffer  = new IndexBuffer();

            var boneCount = boneList.Count;

            var vertices = new Vector3[boneCount];

            for (var i = 0; i < boneCount; ++i)
            {
                vertices[i] = boneList[i].CurrentPosition;
            }

            _vertices = vertices;

            var indices = new uint[(boneCount - 1) * 2];
            var c       = 0;

            foreach (var bone in boneList)
            {
                var parent = bone.Parent;

                if (parent == null)
                {
                    continue;
                }

                indices[c * 2]     = (uint)parent.Index;
                indices[c * 2 + 1] = (uint)bone.Index;

                ++c;

                if (c >= boneCount - 1)
                {
                    break;
                }
            }

            vertexBuffer.BufferData(vertices, BufferUsageHint.StreamDraw);
            indexBuffer.BufferData(indices, BufferUsageHint.StaticDraw);

            _vertexBuffer = vertexBuffer;
            _indexBuffer  = indexBuffer;
        }
Ejemplo n.º 7
0
        internal AxesDebugger([NotNull] SimpleColor simpleColor)
        {
            _simpleColor = simpleColor;

            var vertices = new[] {
                new Vector3(0, 0, 0),
                new Vector3(1, 0, 0),
                new Vector3(0, 1, 0),
                new Vector3(0, 0, 1)
            };
            var indices = new uint[] {
                0, 1, 0, 2, 0, 3
            };

            var vertexBuffer = new VertexBuffer();
            var indexBuffer  = new IndexBuffer();

            vertexBuffer.BufferData(vertices, BufferUsageHint.StaticDraw);
            indexBuffer.BufferData(indices, BufferUsageHint.StaticDraw);

            _vertexBuffer = vertexBuffer;
            _indexBuffer  = indexBuffer;
        }
Ejemplo n.º 8
0
        public AnimationRenderer([NotNull] Game game,
                                 [NotNull] PrettyMesh bodyMesh, [NotNull] PrettyAvatar bodyAvatar, [NotNull, ItemNotNull] IReadOnlyList <BoneNode> bodyBoneList,
                                 [NotNull] PrettyMesh headMesh, [NotNull] PrettyAvatar headAvatar, [NotNull, ItemNotNull] IReadOnlyList <BoneNode> headBoneList,
                                 [NotNull] BodyAnimation animation)
        {
            _game         = game;
            _bodyMesh     = bodyMesh;
            _bodyAvatar   = bodyAvatar;
            _bodyBoneList = bodyBoneList;
            _headMesh     = headMesh;
            _headAvatar   = headAvatar;
            _headBoneList = headBoneList;
            _animation    = animation;

            #region Body

            var bodyVertexBuffer = new VertexBuffer();
            var bodyIndexBuffer  = new IndexBuffer();

            var bodyVertices = new PosNorm[bodyMesh.Vertices.Length];
            var bodyIndices  = new uint[bodyMesh.Indices.Length];

            for (var k = 0; k < bodyVertices.Length; ++k)
            {
                bodyVertices[k] = new PosNorm {
                    Position = bodyMesh.Vertices[k].ToOpenTK().FixCoordSystem(),
                    Normal   = bodyMesh.Normals[k].ToOpenTK().FixCoordSystem()
                };
            }

            _originalBodyVertices = bodyVertices;
            _bodyVertices         = (PosNorm[])bodyVertices.Clone();

            for (var k = 0; k < bodyIndices.Length; ++k)
            {
                bodyIndices[k] = bodyMesh.Indices[k];
            }

            bodyVertexBuffer.BufferData(bodyVertices, BufferUsageHint.StreamDraw);
            bodyIndexBuffer.BufferData(bodyIndices, BufferUsageHint.StaticDraw);

            _bodyVertexBuffer = bodyVertexBuffer;
            _bodyIndexBuffer  = bodyIndexBuffer;

            #endregion

            #region Head

            var headVertexBuffer = new VertexBuffer();
            var headIndexBuffer  = new IndexBuffer();

            var headVertices = new PosNorm[headMesh.Vertices.Length];
            var headIndices  = new uint[headMesh.Indices.Length];

            for (var k = 0; k < headVertices.Length; ++k)
            {
                headVertices[k] = new PosNorm {
                    Position = headMesh.Vertices[k].ToOpenTK().FixCoordSystem(),
                    Normal   = headMesh.Normals[k].ToOpenTK().FixCoordSystem()
                };
            }

            _originalHeadVertices = headVertices;
            _headVertices         = (PosNorm[])headVertices.Clone();

            for (var k = 0; k < headIndices.Length; ++k)
            {
                headIndices[k] = headMesh.Indices[k];
            }

            headVertexBuffer.BufferData(headVertices, BufferUsageHint.StreamDraw);
            headIndexBuffer.BufferData(headIndices, BufferUsageHint.StaticDraw);

            _headVertexBuffer = headVertexBuffer;
            _headIndexBuffer  = headIndexBuffer;

            #endregion
        }
Ejemplo n.º 9
0
        public override Model Build()
        {
            Model ret = new Model();

            var w2 = width / 2;
            var h2 = height / 2;
            var d2 = depth / 2;

            ret.VertexBuffer = new VertexBuffer <VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
            ret.VertexBuffer.Allocate(24);
            var vb = ret.VertexBuffer;
            var ib = new IndexBuffer <uint>();

            //ib.Allocate(36);

            Vector3[] pos = new Vector3[8];
            pos[0] = new Vector3(-w2, h2, d2);
            pos[1] = new Vector3(w2, h2, d2);
            pos[2] = new Vector3(w2, h2, -d2);
            pos[3] = new Vector3(-w2, h2, -d2);

            pos[4] = new Vector3(-w2, -h2, d2);
            pos[5] = new Vector3(w2, -h2, d2);
            pos[6] = new Vector3(w2, -h2, -d2);
            pos[7] = new Vector3(-w2, -h2, -d2);


            ret.Parts.Add(
                new ModelPart()
            {
                IndexBuffer = ib
            }
                );

            vb[0] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(0, 0)
            };

            vb[1] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(1, 0)
            };

            vb[2] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(1, 1)
            };
            vb[3] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal   = Vector3.Up,
                TexCoord = new Vector2(0, 1)
            };

            vb[4] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(0, 0)
            };

            vb[5] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(1, 0)
            };

            vb[6] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(1, 1)
            };
            vb[7] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal   = Vector3.Down,
                TexCoord = new Vector2(0, 1)
            };

            vb[8] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[9] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[10] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[11] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal   = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[12] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[13] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };


            vb[14] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[15] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal   = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[16] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[17] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[18] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };
            vb[19] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal   = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[23] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[22] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[21] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };
            vb[20] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal   = Vector3.East,
                TexCoord = new Vector2()
            };

            int offset = 0;

            ib.Allocate(36);
            for (int i = 0; i < 6; i++)
            {
                offset = AddFaces(i * 4, offset, ib);
            }

            vb.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);
            ib.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);

            return(ret);
        }
Ejemplo n.º 10
0
            internal TerrainBlock(int x_start, int y_start, int x_count, int y_count,  BoundingBox box, int subdivision, Terrain owner)
            {
                bounds = box;
                if (subdivision < owner.Subdivisions)
                {
                    x_count /= 2;
                    y_count /= 2;
                    Vector3 new_size = box.Size / 2;
                    new_size.y = box.Size.y;
                    float offset = box.Size.x / 4;

                    children = new List<TerrainBlock>();

                    children.Add(new TerrainBlock(x_start, y_start, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset) }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, offset) }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start + x_count, y_start + y_count, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset) }, subdivision + 1, owner));
                    children.Add(new TerrainBlock(x_start, y_start + y_count, x_count, y_count, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset) }, subdivision + 1, owner));
                }
                else
                {
                    ib = new IndexBuffer<int>();
                    ib.Allocate(6 * (x_count) * (y_count));
                    int index = 0;
                    for (int i = 0; i < y_count; i++)
                    {
                        for (int j = 0; j < x_count; j++)
                        {
                            int i1 = (y_start + i) * owner.heightmap.Width + x_start + j;
                            int i2 = (y_start + i) * owner.heightmap.Width + x_start + j + 1;
                            int i3 = (y_start + i + 1) * owner.heightmap.Width + x_start + j + 1;
                            int i4 = (y_start + i + 1) * owner.heightmap.Width + x_start + j;

                            ib[index++] = i1;
                            ib[index++] = i3;
                            ib[index++] = i2;

                            ib[index++] = i1;
                            ib[index++] = i4;
                            ib[index++] = i3;
                        }
                    }
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    ib.FreeClientData();
                }
            }
Ejemplo n.º 11
0
            internal TerrainBlock(Terrain owner, List<int> indices, BoundingBox box, int subdivision)
            {
                bounds = box;

                if (subdivision < owner.Subdivisions)
                {
                    Vector3 new_size = box.Size / 2;
                    new_size.y = box.Size.y;
                    float offset = box.Size.x / 4;

                    children = new List<TerrainBlock>();

                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, offset) }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, offset) }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(offset, 0, -offset) }, subdivision + 1));
                    children.Add(new TerrainBlock(owner, indices, new BoundingBox() { Size = new_size, Position = box.Position + new Vector3(-offset, 0, -offset) }, subdivision + 1));

                }
                else
                {
                    List<int> mil = new List<int>();
                    for (int i = 0; i < indices.Count; i += 3)
                    {
                        var i1 = indices[i];
                        var i2 = indices[i + 1];
                        var i3 = indices[i + 2];

                        var v1 = owner.vb[i1];
                        var v2 = owner.vb[i2];
                        var v3 = owner.vb[i3];

                        var p1 = new Vector2(box.Position.x - box.Size.x / 2, box.Position.z - box.Size.z / 2);
                        var p2 = new Vector2(box.Position.x + box.Size.x / 2, box.Position.z + box.Size.z / 2);

                        if ((v1.Position.x >= p1.x && v1.Position.x <= p2.x && v1.Position.z >= p1.y && v1.Position.z <= p2.y) ||
                            (v2.Position.x >= p1.x && v2.Position.x <= p2.x && v2.Position.z >= p1.y && v2.Position.z <= p2.y) ||
                            (v3.Position.x >= p1.x && v3.Position.x <= p2.x && v3.Position.z >= p1.y && v3.Position.z <= p2.y))
                        {
                            mil.Add(i1);
                            mil.Add(i2);
                            mil.Add(i3);
                        }
                    }
                    ib = new IndexBuffer<int>();
                    ib.Allocate(mil);
                    ib.BufferData(VboUsage.GL_STATIC_DRAW);
                    //mil.Clear();
                }
            }
Ejemplo n.º 12
0
        private void GenerateDome()
        {
            int vertices = Segments * Segments * 2 + 1;
            int indices  = Segments * 6 + (Segments - 1) * 2 * Segments * 6;


            vb = new VertexBuffer <SkydomeVertex>(SkydomeVertex.Descriptor);
            ib = new IndexBuffer <uint>();
            vb.Allocate(vertices);
            ib.Allocate(indices);
            int index = 0;

            float vang_inc = (float)(Math.PI / 2) / Segments;
            float hang_inc = (float)(2 * Math.PI) / Segments;

            float hang = hang_inc;
            float vang = vang_inc;

            for (int i = 0; i < Segments; i++, vang += vang_inc)
            {
                float v_c = (float)Math.Cos(vang);
                float v_s = (float)Math.Sin(vang);
                for (int j = 0; j < Segments * 2; j++, hang += hang_inc)
                {
                    float   h_c = (float)Math.Cos(hang);
                    float   h_s = (float)Math.Sin(hang);
                    Vector3 pos = new Vector3(h_c * v_s, v_c, h_s * v_s);
                    vb[index++] = new SkydomeVertex()
                    {
                        Position = pos,
                        Normal   = -pos.Normalize()
                    };
                }
                hang = 0;
            }
            vb[index] = new SkydomeVertex()
            {
                Normal   = Vector3.Down,
                Position = new Vector3(0, 1f, 0)
            };
            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            vb.FreeClientData();
            index = 0;
            for (int i = 0; i < Segments * 2; i++)
            {
                ib[index++] = (uint)vertices - 1;
                ib[index++] = (uint)i;
                ib[index++] = (uint)(i + 1) % (Segments * 2);                 // Wraparound
            }
            for (int i = 0; i < Segments - 1; i++)
            {
                for (int j = 0; j < Segments * 2; j++)
                {
                    int offset_1 = i * Segments * 2;
                    int offset_2 = i * Segments * 2 + Segments * 2;
                    int j2       = (j + 1) % (Segments * 2);

                    ib[index++] = (uint)(offset_1 + j);
                    ib[index++] = (uint)(offset_2 + j);
                    ib[index++] = (uint)(offset_1 + j2);

                    ib[index++] = (uint)(offset_2 + j);
                    ib[index++] = (uint)(offset_2 + j2);
                    ib[index++] = (uint)(offset_1 + j2);
                }
            }
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.FreeClientData();
        }
Ejemplo n.º 13
0
Archivo: Box.cs Proyecto: r-bel/glorg2
        protected override void Build()
        {
            vb = new VertexBuffer<Vector3>(Vector3.Descriptor);

            vb.Allocate(8);
            ib = new IndexBuffer<ushort>();
            ib.Allocate(4 * 6);

            vb[0] = new Vector3(-0.5f, -0.5f, -0.5f);
            vb[1] = new Vector3(0.5f, -0.5f, -0.5f);
            vb[2] = new Vector3(0.5f, 0.5f, -0.5f);
            vb[3] = new Vector3(-0.5f, 0.5f, -0.5f);

            vb[4] = new Vector3(-0.5f, -0.5f, 0.5f);
            vb[5] = new Vector3(0.5f, -0.5f, 0.5f);
            vb[6] = new Vector3(0.5f, 0.5f, 0.5f);
            vb[7] = new Vector3(-0.5f, 0.5f, 0.5f);

            ib[0] = 0;
            ib[1] = 1;
            ib[2] = 2;
            ib[3] = 3;

            ib[4] = 4;
            ib[5] = 0;
            ib[6] = 3;
            ib[7] = 7;

            ib[8] = 5;
            ib[9] = 4;
            ib[10] = 7;
            ib[11] = 6;

            ib[12] = 1;
            ib[13] = 5;
            ib[14] = 6;
            ib[15] = 2;

            ib[16] = 6;
            ib[17] = 7;
            ib[18] = 3;
            ib[19] = 2;

            ib[20] = 0;
            ib[21] = 4;
            ib[22] = 5;
            ib[23] = 1;

            vb.BufferData(VboUsage.GL_STATIC_DRAW);
            ib.BufferData(VboUsage.GL_STATIC_DRAW);
            // Client data is no longer needed. Free it!
            vb.FreeClientData();
            ib.FreeClientData();
        }
Ejemplo n.º 14
0
        public void InitializeGraphics()
        {
            if(mat == null)
                owner.Resources.Load("shaders\\Grid", out mat);
            if (vb == null)
            {
                vb = new VertexBuffer<VertexPositionColor>(VertexPositionColor.Descriptor);
                vb.Allocate(8);
            }
            if (ib == null)
            {
                ib = new IndexBuffer<uint>();
                ib.Allocate(24);
                ib[0] = 0;
                ib[1] = 1;
                ib[2] = 1;
                ib[3] = 2;
                ib[4] = 2;
                ib[5] = 3;
                ib[6] = 3;
                ib[7] = 0;

                ib[8] = 4;
                ib[9] = 5;
                ib[10] = 5;
                ib[11] = 6;
                ib[12] = 6;
                ib[13] = 7;
                ib[14] = 4;

                ib[15] = 0;
                ib[16] = 4;

                ib[17] = 1;
                ib[18] = 5;

                ib[19] = 2;
                ib[20] = 6;

                ib[21] = 3;
                ib[22] = 7;
                ib.BufferData(VboUsage.GL_STATIC_DRAW);
            }

            if (points != null)
            {
                for (int i = 0; i < 8; i++)
                {
                    vb[i] = new VertexPositionColor() { Position = points[i], Color = Colors.Yellow };
                }
            }

            vb.BufferData(VboUsage.GL_DYNAMIC_DRAW);
        }
Ejemplo n.º 15
0
        public override Model Build()
        {
            Model ret = new Model();

            var w2 = width / 2;
            var h2 = height / 2;
            var d2 = depth / 2;

            ret.VertexBuffer = new VertexBuffer<VertexPositionTexCoordNormal>(VertexPositionTexCoordNormal.Descriptor);
            ret.VertexBuffer.Allocate(24);
            var vb = ret.VertexBuffer;
            var ib = new IndexBuffer<uint>();
            //ib.Allocate(36);

            Vector3[] pos = new Vector3[8];
            pos[0] = new Vector3(-w2, h2, d2);
            pos[1] = new Vector3(w2, h2, d2);
            pos[2] = new Vector3(w2, h2, -d2);
            pos[3] = new Vector3(-w2, h2, -d2);

            pos[4] = new Vector3(-w2, -h2, d2);
            pos[5] = new Vector3(w2, -h2, d2);
            pos[6] = new Vector3(w2, -h2, -d2);
            pos[7] = new Vector3(-w2, -h2, -d2);

            ret.Parts.Add(
                new ModelPart()
                {
                    IndexBuffer = ib
                }
                );

            vb[0] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal = Vector3.Up,
                TexCoord = new Vector2(0, 0)
            };

            vb[1] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal = Vector3.Up,
                TexCoord = new Vector2(1, 0)
            };

            vb[2] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal = Vector3.Up,
                TexCoord = new Vector2(1, 1)
            };
            vb[3] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal = Vector3.Up,
                TexCoord = new Vector2(0, 1)
            };

            vb[4] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal = Vector3.Down,
                TexCoord = new Vector2(0, 0)
            };

            vb[5] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal = Vector3.Down,
                TexCoord = new Vector2(1, 0)
            };

            vb[6] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal = Vector3.Down,
                TexCoord = new Vector2(1, 1)
            };
            vb[7] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal = Vector3.Down,
                TexCoord = new Vector2(0, 1)
            };

            vb[8] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[9] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[10] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[11] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal = Vector3.North,
                TexCoord = new Vector2(0, 0)
            };

            vb[12] = new VertexPositionTexCoordNormal()
            {
                Position = pos[0],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[13] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[14] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[15] = new VertexPositionTexCoordNormal()
            {
                Position = pos[4],
                Normal = Vector3.West,
                TexCoord = new Vector2()
            };

            vb[16] = new VertexPositionTexCoordNormal()
            {
                Position = pos[3],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[17] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[18] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };
            vb[19] = new VertexPositionTexCoordNormal()
            {
                Position = pos[7],
                Normal = Vector3.South,
                TexCoord = new Vector2()
            };

            vb[23] = new VertexPositionTexCoordNormal()
            {
                Position = pos[1],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[22] = new VertexPositionTexCoordNormal()
            {
                Position = pos[2],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };

            vb[21] = new VertexPositionTexCoordNormal()
            {
                Position = pos[6],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };
            vb[20] = new VertexPositionTexCoordNormal()
            {
                Position = pos[5],
                Normal = Vector3.East,
                TexCoord = new Vector2()
            };

            int offset = 0;
            ib.Allocate(36);
            for (int i = 0; i < 6; i++)
            {
                offset = AddFaces(i * 4, offset, ib);
            }

            vb.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);
            ib.BufferData(Glorg2.Graphics.OpenGL.VboUsage.GL_STATIC_DRAW);

            return ret;
        }