Exemple #1
0
            private void SetColorAttribute(GraphicsContext ctx)
            {
                if (ArrayBuffer != null)
                {
                    ArrayBufferObjectBase.IArraySection arraySection = ArrayBuffer.GetArraySection(ArraySectionIndex);

                    int arrayLength = (int)arraySection.ItemType.GetArrayLength();
                    int arrayStride = arraySection.Stride.ToInt32();

                    // Bind the array buffer
                    ctx.Bind(ArrayBuffer);

                    // Set vertex pointer
                    Gl.ColorPointer(
                        arrayLength, arraySection.ItemType.GetColorPointerType(), arrayStride,
                        arraySection.Pointer
                        );
                    // Enable vertex attribute
                    Gl.EnableClientState(EnableCap.ColorArray);
                }
                else
                {
                    Gl.DisableClientState(EnableCap.ColorArray);
                }
            }
Exemple #2
0
            public Activation(MapVertexBuffer source)
            {
                _positionLock = new MemoryLock(source._positions);
                _colorLock    = new MemoryLock(source._colors);
                _textureLock  = new MemoryLock(source._textures);

                Gl.VertexPointer(2, VertexPointerType.Float, 0, _positionLock.Address);
                Gl.EnableClientState(EnableCap.VertexArray);
                Gl.ColorPointer(4, ColorPointerType.UnsignedByte, 0, _colorLock.Address);
                Gl.EnableClientState(EnableCap.ColorArray);
                Gl.TexCoordPointer(2, TexCoordPointerType.Float, 0, _textureLock.Address);
                Gl.EnableClientState(EnableCap.TextureCoordArray);
            }
        public void Render()
        {
            //Gl.Rotate(angle, 0.0f, 0.0f, 1.0f);
            using (MemoryLock vertexArrayLock = new MemoryLock(quadPosition))
                using (MemoryLock vertexColorLock = new MemoryLock(arrayColor)) {
                    // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                    // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                    Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                    Gl.EnableClientState(EnableCap.VertexArray);

                    Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                    Gl.EnableClientState(EnableCap.ColorArray);

                    Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                }
        }
Exemple #4
0
        public static void Draw(PrimitiveType type)
        {
            using (var colorArrayLock = new MemoryLock(_colors.ToArray()))
                using (var vertexArrayLock = new MemoryLock(_verts.ToArray()))
                    using (var normalArrayLock = new MemoryLock(_normals.ToArray()))
                    {
                        Gl.VertexPointer(3, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.ColorPointer(4, ColorPointerType.Float, 0, colorArrayLock.Address);
                        Gl.EnableClientState(EnableCap.ColorArray);

                        Gl.NormalPointer(NormalPointerType.Float, 0, normalArrayLock.Address);
                        Gl.EnableClientState(EnableCap.NormalArray);

                        Gl.DrawArrays(type, 0, _verts.Count / 3);
                    }
        }
Exemple #5
0
        private void Es1_Render()
        {
            // Old school OpenGL 1.1
            // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
            using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                {
                    // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                    // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                    Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                    Gl.EnableClientState(EnableCap.VertexArray);

                    Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                    Gl.EnableClientState(EnableCap.ColorArray);

                    Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                }
        }
        private void GlControl_Render(object sender, OpenGL.GlControlEventArgs e)
        {
            var senderControl = sender as GlControl;

            senderControl.Animation     = true;
            senderControl.AnimationTime = 1;

            int vpx = 0;
            int vpy = 0;
            int vpw = senderControl.ClientSize.Width;
            int vph = senderControl.ClientSize.Height;

            Gl.Viewport(vpx, vpy, vpw, vph);
            Gl.ClearColor(0.39f, 0.58f, 0.92f, 1);
            Gl.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

            cycle();
            if (chip.draw)
            {
                Draw(chip.display);
            }

            if (Gl.CurrentVersion >= Gl.Version_110)
            {
                // Old school OpenGL 1.1
                // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
                using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                    using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                    {
                        // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                        // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                        Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                        Gl.EnableClientState(EnableCap.ColorArray);

                        Gl.DrawArrays(PrimitiveType.Triangles, 0, _ArrayPosition.Length / 2);
                    }
            }
        }
Exemple #7
0
        private void GlControl_Render(object sender, OpenGL.GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            // FIXME I wonder why the viewport is affected when the GlControl is hosted in WPF windows.
            int vpx = -senderControl.ClientSize.Width;
            int vpy = -senderControl.ClientSize.Height;
            int vpw = senderControl.ClientSize.Width * 2;
            int vph = senderControl.ClientSize.Height * 2;

            Gl.Viewport(vpx, vpy, vpw, vph);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            if (Gl.CurrentVersion >= Gl.Version_110)
            {
                // Old school OpenGL 1.1
                // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
                using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                    using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                    {
                        // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                        // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                        Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                        Gl.EnableClientState(EnableCap.ColorArray);

                        Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                    }
            }
            else
            {
                // Old school OpenGL
                Gl.Begin(PrimitiveType.Triangles);
                Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
                Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
                Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
                Gl.End();
            }
        }
Exemple #8
0
        private void RenderControl_Render_GL(object sender, GlControlEventArgs e)
        {
            Control senderControl = (Control)sender;

            Gl.Viewport(0, 0, senderControl.ClientSize.Width, senderControl.ClientSize.Height);
            Gl.Clear(ClearBufferMask.ColorBufferBit);

            // Animate triangle
            Gl.MatrixMode(MatrixMode.Modelview);
            Gl.LoadIdentity();
            Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f);

            if (Gl.CurrentVersion >= Gl.Version_110)
            {
                // Old school OpenGL 1.1
                // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
                using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                    using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                    {
                        // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                        // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                        Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                        Gl.EnableClientState(EnableCap.VertexArray);

                        Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                        Gl.EnableClientState(EnableCap.ColorArray);

                        Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                    }
            }
            else
            {
                // Old school OpenGL
                Gl.Begin(PrimitiveType.Triangles);
                Gl.Color3(1.0f, 0.0f, 0.0f); Gl.Vertex2(0.0f, 0.0f);
                Gl.Color3(0.0f, 1.0f, 0.0f); Gl.Vertex2(0.5f, 1.0f);
                Gl.Color3(0.0f, 0.0f, 1.0f); Gl.Vertex2(1.0f, 0.0f);
                Gl.End();
            }
        }
Exemple #9
0
        public void Render()
        {
            // Setup model-view matrix (as previously)

            // Model-view matrix selector
            Gl.MatrixMode(MatrixMode.Modelview);
            // Load (reset) to identity
            Gl.LoadIdentity();
            // Multiply with rotation matrix (around Z axis)
            Gl.Rotate(_Angle, 0.0f, 0.0f, 1.0f);

            // Draw triangle using immediate mode

            // Setup & enable client states to specify vertex arrays, and use Gl.DrawArrays instead of Gl.Begin/End paradigm
            using (MemoryLock vertexArrayLock = new MemoryLock(_ArrayPosition))
                using (MemoryLock vertexColorLock = new MemoryLock(_ArrayColor))
                {
                    // Note: the use of MemoryLock objects is necessary to pin vertex arrays since they can be reallocated by GC
                    // at any time between the Gl.VertexPointer execution and the Gl.DrawArrays execution

                    // Set current client memory pointer for position: a vertex of 2 floats
                    Gl.VertexPointer(2, VertexPointerType.Float, 0, vertexArrayLock.Address);
                    // Position is used for drawing
                    Gl.EnableClientState(EnableCap.VertexArray);

                    // Set current client memory pointer for color: a vertex of 3 floats
                    Gl.ColorPointer(3, ColorPointerType.Float, 0, vertexColorLock.Address);
                    // Color is used for drawing
                    Gl.EnableClientState(EnableCap.ColorArray);

                    // Note: enabled client state and client memory pointers are a GL state, and theorically they could be
                    // set only at creation time. However, memory should be pinned for application lifetime.

                    // Start drawing triangles (3 vertices -> 1 triangle)
                    // Note: vertex attributes are streamed from client memory to GPU
                    Gl.DrawArrays(PrimitiveType.Triangles, 0, 3);
                }
        }