Пример #1
0
        private unsafe void SimpleCube_Paint(object sender, PaintEventArgs e)
        {
            _Context.MakeCurrent();
            _Lookat = mat4.LookAt(_CameraPosition, new vec3(0.1f, 0.1f, 0.1f), new vec3(0.0f, 1.0f, 0.0f));


            int positionAttribIndex = _Shader.GetAttribLocation("in_Position");
            int projectionMatrix    = _Shader.GetUniformLocation("projectionMatrix");

            _Context.DrawBuffer(Ratchet.Drawing.OpenGL.glContext.DrawBufferMode.GL_BACK);
            _Context.ClearDepth(1.0f);
            _Context.ClearColor(0.1f, 0.7f, 1.0f, 1.0f);
            _Context.Clear(Ratchet.Drawing.OpenGL.glContext.ClearTarget.GL_COLOR_BUFFER | Ratchet.Drawing.OpenGL.glContext.ClearTarget.GL_DEPTH_BUFFER);

            _Shader.UseProgram();
            mat4 matrix = _Projection * _Lookat;

            _Context.SetUniformMatrix4(projectionMatrix, false, new IntPtr(&matrix));

            _VertexBuffer.BindBuffer(Ratchet.Drawing.OpenGL.glBuffer.BindTarget.GL_ARRAY_BUFFER);
            _IndexBuffer.BindBuffer(Ratchet.Drawing.OpenGL.glBuffer.BindTarget.GL_ELEMENT_ARRAY_BUFFER);
            _Context.EnableVertexAttribArray(positionAttribIndex);
            _Context.VertexAttribPointer(positionAttribIndex, 4, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 6 * sizeof(float), new IntPtr(0));

            _Context.DrawElements(Ratchet.Drawing.OpenGL.glContext.PrimitivesType.GL_TRIANGLES, 36, Ratchet.Drawing.OpenGL.glContext.IndiceType.GL_UNSIGNED_INT);
            _Context.Flush();
            _Context.SwapBuffers();
        }