Example #1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad (e);

            String version = GL.GetString(StringName.Version);
            Console.WriteLine("GL version: " + version);

            context = GLGraphics.NewContext(Context, true);

            program = context.NewProgramFromFiles("Render.vert", "Render.frag");

            texture0 = context.NewTexture(TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
            texture0.UploadImage(sourceImage);
            sourceImage.Dispose();

            texture1 = context.NewTexture(TextureMinFilter.Nearest, TextureMagFilter.Nearest, TextureWrapMode.Clamp, TextureWrapMode.Clamp);
            texture1.UploadImage(new byte[4 * 4 * 4], 4, 4, PixelInternalFormat.Four, PixelFormat.Rgba, PixelType.UnsignedByte);

            CreateAndFillBuffers();
            paramSpec = ImmutableList<Tuple<String, Object>>.List(new Tuple<String, Object>[] {
                Tuple.Create<String, Object>("a_position", positions),
                Tuple.Create<String, Object>("a_texPos", textureCoords),
                Tuple.Create<String, Object>("u_texture0", texture0),
                Tuple.Create<String, Object>("u_texture1", texture1)});
        }
Example #2
0
        public TextureRenderer(GLGraphicsContext context, GLTexture texture)
        {
            this.context = context;

            texture = context.NewTexture(OpenTK.Graphics.OpenGL.TextureMinFilter.Nearest, OpenTK.Graphics.OpenGL.TextureMagFilter.Nearest,
                OpenTK.Graphics.OpenGL.TextureWrapMode.Clamp, OpenTK.Graphics.OpenGL.TextureWrapMode.Clamp);

            vertices = context.NewVertexBuffer<Vector3>(OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                3);
            vertices.UploadVertices(new Vector3[] {
                new Vector3(-1, -1, 0),
                new Vector3(1, -1, 0),
                new Vector3(-1, 1, 0),
                new Vector3(1, 1, 0)});

            texCoords = context.NewVertexBuffer<Vector2>(OpenTK.Graphics.OpenGL.VertexAttribPointerType.Float,
                2);
            texCoords.UploadVertices(new Vector2[] {
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(0, 1),
                new Vector2(1, 1)});

            prog = context.NewProgram(MVP_VERTEX_SHADER, TEXTURE_SHADER);

            paramSpec = ImmutableList<Tuple<String, Object>>.List(
                Tuple.Create<String, Object>("a_position", vertices),
                Tuple.Create<String, Object>("a_texPos", texCoords),
                Tuple.Create<String, Object>("u_texture0", texture));
        }