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


            int positionAttribIndex = _Shader.GetAttribLocation("in_Position");
            int texCoordAttribIndex = _Shader.GetAttribLocation("in_textureCoord");
            int texSampler          = _Shader.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.SwapBuffers();
        }
Example #3
0
        private void Window_Paint(object sender, PaintEventArgs e)
        {
            _Context.MakeCurrent();


            int positionAttribIndex = _Shader.GetAttribLocation("in_Position");
            int colorAttribIndex    = _Shader.GetAttribLocation("in_Color");


            _Context.ClearColor(0.1f, 0.7f, 1.0f, 1.0f);
            _Context.Clear(Ratchet.Drawing.OpenGL.glContext.ClearTarget.GL_COLOR_BUFFER);
            _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(positionAttribIndex, 4, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 8 * sizeof(float), new IntPtr(0));

            _Context.EnableVertexAttribArray(colorAttribIndex);
            _Context.VertexAttribPointer(colorAttribIndex, 4, Ratchet.Drawing.OpenGL.glContext.VertexAttributeType.GL_FLOAT, false, 8 * sizeof(float), new IntPtr(4 * sizeof(float)));

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