Example #1
0
        public ExampleWindow() : base("Hello Triangle (GTK#)")
        {
            SetDefaultSize(800, 600);
            SetPosition(WindowPosition.Center);

            GlWidget glWidget = new GlWidget();

            Add(glWidget);

            glWidget.SetSizeRequest(100, 100);

            DeleteEvent += delegate { Application.Quit(); };
            ShowAll();
        }
Example #2
0
        public ExampleWindow() : base("Hello Triangle (GTK# 3)")
        {
            SetDefaultSize(800, 600);
            SetPosition(WindowPosition.Center);

            GlWidget glWidget = new GlWidget();

            Add(glWidget);

            glWidget.Hexpand = true;
            glWidget.Vexpand = true;

            glWidget.SetSizeRequest(100, 100);
            glWidget.ContextCreated += GlWidget_ContextCreated;
            glWidget.Render         += GlWidget_Render;

            DeleteEvent += delegate { Application.Quit(); };
            ShowAll();
        }
Example #3
0
        private void GlWidget_Render(object sender, GlWidgetEventArgs e)
        {
            GlWidget senderControl = (GlWidget)sender;

            Gl.Viewport(0, 0, senderControl.WidthRequest, senderControl.HeightRequest);
            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();
            }
        }