Ejemplo n.º 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();
        }
Ejemplo n.º 2
0
        private void Windows_Paint(object sender, PaintEventArgs e)
        {
            _Context.MakeCurrent();

            {
                _Context.DrawBuffers(new Ratchet.Drawing.OpenGL.glContext.DrawBufferMode[] { Ratchet.Drawing.OpenGL.glContext.DrawBufferMode.GL_COLOR_ATTACHMENT0 });

                _Framebuffer.BindFramebuffer(Ratchet.Drawing.OpenGL.glFramebuffer.BindTarget.GL_DRAW_FRAMEBUFFER);

                _Context.DrawBuffers(new Ratchet.Drawing.OpenGL.glContext.DrawBufferMode[] { Ratchet.Drawing.OpenGL.glContext.DrawBufferMode.GL_COLOR_ATTACHMENT0 });

                int positionAttribIndex = _BlurShader.GetAttribLocation("in_Position");
                int texCoordAttribIndex = _BlurShader.GetAttribLocation("in_textureCoord");
                int texSampler          = _BlurShader.GetUniformLocation("textureSampler");

                _Context.ClearColor(0.1f, 0.7f, 1.0f, 1.0f);
                _Context.Clear(Ratchet.Drawing.OpenGL.glContext.ClearTarget.GL_COLOR_BUFFER);

                // Activate Sampler 0 and bind our texture to it
                _Context.ActiveTexture(0);
                _Texture.BindTexture(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D);


                _Shader.UseProgram();
                _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(0, 4, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 6 * sizeof(float), new IntPtr(0));

                _Context.EnableVertexAttribArray(texCoordAttribIndex);
                _Context.VertexAttribPointer(1, 2, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 6 * sizeof(float), new IntPtr(4 * sizeof(float)));

                // Link the uniform "textureSampler" that is expecting a textureSampler to be bound to it
                // to 0 which is the sampler currently associated to our texture
                _Context.SetUniform(texSampler, 0);


                _Context.DrawElements(Ratchet.Drawing.OpenGL.glContext.PrimitivesType.GL_TRIANGLES, 6, Ratchet.Drawing.OpenGL.glContext.IndiceType.GL_UNSIGNED_INT);
                _Context.Flush();
                _Framebuffer.UnbindFramebuffer(Ratchet.Drawing.OpenGL.glFramebuffer.BindTarget.GL_DRAW_FRAMEBUFFER);
            }

            // Be lazy and redraw the same center square but this time using the previous render as a texture
            {
                int positionAttribIndex = _BlurShader.GetAttribLocation("in_Position");
                int texCoordAttribIndex = _BlurShader.GetAttribLocation("in_textureCoord");
                int texSampler          = _BlurShader.GetUniformLocation("textureSampler");

                _Context.ClearColor(0.1f, 0.7f, 1.0f, 1.0f);
                _Context.Clear(Ratchet.Drawing.OpenGL.glContext.ClearTarget.GL_COLOR_BUFFER);

                // Activate Sampler 0 and bind our texture to it
                _Context.ActiveTexture(0);
                _FramebufferColorBuffer.BindTexture(Ratchet.Drawing.OpenGL.glTexture.BindTarget.GL_TEXTURE_2D);


                _BlurShader.UseProgram();
                _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(0, 4, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 6 * sizeof(float), new IntPtr(0));

                _Context.EnableVertexAttribArray(texCoordAttribIndex);
                _Context.VertexAttribPointer(1, 2, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 6 * sizeof(float), new IntPtr(4 * sizeof(float)));

                // Link the uniform "textureSampler" that is expecting a textureSampler to be bound to it
                // to 0 which is the sampler currently associated to our texture
                _Context.SetUniform(texSampler, 0);

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

            _Context.SwapBuffers();
        }