public static void Initialize(float radiusBottom, float radiusTop, float height, float slices)
        {
            if (Vertices.Length == 0)
            {
                int buffer = GL.GenBuffer();
                sphereVao = new VertexBufferObject(buffer);
                sphereVao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 24, 0);
                sphereVao.AddAttribute(1, 3, VertexAttribPointerType.Float, false, 24, 12);
                sphereVao.Initialize();

                List <float> list = new List <float>();
                Vertices = GetVertices(radiusBottom, radiusTop, height, slices);
                for (int i = 0; i < Vertices.Length; i++)
                {
                    var mat = Matrix4.CreateRotationX(MathHelper.DegreesToRadians(90));
                    Vertices[i].Position = Vector3.TransformPosition(Vertices[i].Position, mat);
                    Vertices[i].Normal   = Vector3.TransformNormal(Vertices[i].Normal, mat);

                    list.Add(Vertices[i].Position.X);
                    list.Add(Vertices[i].Position.Y);
                    list.Add(Vertices[i].Position.Z);
                    list.Add(Vertices[i].Normal.X);
                    list.Add(Vertices[i].Normal.Y);
                    list.Add(Vertices[i].Normal.Z);
                }

                float[] data = list.ToArray();
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);
            }
            else
            {
                //  sphereVao.Initialize();
                // DefaultShaderProgram.Link();
            }
        }
            public void Init()
            {
                Vao = new VertexBufferObject();
                Vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 32, 0);
                Vao.AddAttribute(1, 3, VertexAttribPointerType.Float, false, 32, 12);
                Vao.AddAttribute(2, 2, VertexAttribPointerType.Float, false, 32, 24);
                Vao.Initialize();

                UpdateVertexData();
            }
Beispiel #3
0
        public static void Init()
        {
            if (Length == 0)
            {
                int buffer = GL.GenBuffer();
                vao = new VertexBufferObject(buffer);
                vao.AddAttribute(0, 2, VertexAttribPointerType.Float, false, 16, 0);
                vao.AddAttribute(1, 2, VertexAttribPointerType.Float, false, 16, 8);
                vao.Initialize();

                Vector2[] positions = new Vector2[4]
                {
                    new Vector2(-1.0f, 1.0f),
                    new Vector2(-1.0f, -1.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, -1.0f),
                };

                Vector2[] texCoords = new Vector2[4]
                {
                    new Vector2(0.0f, 1.0f),
                    new Vector2(0.0f, 0.0f),
                    new Vector2(1.0f, 1.0f),
                    new Vector2(1.0f, 0.0f),
                };

                List <float> list = new List <float>();
                for (int i = 0; i < 4; i++)
                {
                    list.Add(positions[i].X);
                    list.Add(positions[i].Y);
                    list.Add(texCoords[i].X);
                    list.Add(texCoords[i].Y);
                }

                Length = 4;

                float[] data = list.ToArray();

                GL.BindBuffer(BufferTarget.ArrayBuffer, buffer);
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);
                GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            }
        }
Beispiel #4
0
        public void Init(bool forceUpdate)
        {
            if (Camera == null)
            {
                return;
            }

            if (Length == 0 || forceUpdate)
            {
                int buffer      = GL.GenBuffer();
                int indexBuffer = GL.GenBuffer();
                vao = new VertexBufferObject(buffer, indexBuffer);
                vao.AddAttribute(0, 3, VertexAttribPointerType.Float, false, 12, 0);
                vao.Initialize();

                float farPlane  = Camera.ZFar;
                float nearPlane = Camera.ZNear;
                float tan       = (float)Math.Tan(Camera.Fov / 2);
                float aspect    = Camera.AspectRatio;

                float nearHeight = nearPlane * tan;
                float nearWidth  = nearHeight * aspect;
                float farHeight  = farPlane * tan;
                float farWidth   = farHeight * aspect;

                Vector3[] vertices = new Vector3[8];
                // near bottom left
                vertices[2][0] = -nearWidth; vertices[2][1] = -nearHeight; vertices[2][2] = -nearPlane;
                // near bottom right
                vertices[3][0] = nearWidth; vertices[3][1] = -nearHeight; vertices[3][2] = -nearPlane;

                // near top left
                vertices[1][0] = -nearWidth; vertices[1][1] = nearHeight; vertices[1][2] = -nearPlane;
                // near top right
                vertices[0][0] = nearWidth; vertices[0][1] = nearHeight; vertices[0][2] = -nearPlane;

                // far bottom left
                vertices[6][0] = -farWidth; vertices[6][1] = -farHeight; vertices[6][2] = -farPlane;
                // far bottom right
                vertices[7][0] = farWidth; vertices[7][1] = -farHeight; vertices[7][2] = -farPlane;

                // far top left
                vertices[4][0] = -farWidth; vertices[5][1] = farHeight; vertices[5][2] = -farPlane;
                // far top right
                vertices[5][0] = farWidth; vertices[4][1] = farHeight; vertices[4][2] = -farPlane;

                List <float> list = new List <float>();
                for (int i = 0; i < vertices.Length; i++)
                {
                    list.Add(vertices[i].X);
                    list.Add(vertices[i].Y);
                    list.Add(vertices[i].Z);
                }

                Length = vertices.Length;

                float[] data = list.ToArray();
                GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * data.Length, data, BufferUsageHint.StaticDraw);

                GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexBuffer);
                GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(Indices.Length * sizeof(int)), Indices, BufferUsageHint.StaticDraw);
            }
        }