Beispiel #1
0
        void LoadTextures()
        {
            // Generate textures
            GLES20.GlGenTextures(2, _textures, 0);

            // Load input bitmap
            var bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Lenna);

            _imageWidth  = bitmap.Width;
            _imageHeight = bitmap.Height;
            Renderer.UpdateTextureSize(_imageWidth, _imageHeight);

            // Upload to texture
            GLES20.GlBindTexture(GLES20.GlTexture2d, _textures [0]);
            GLUtils.TexImage2D(GLES20.GlTexture2d, 0, bitmap, 0);

            // Set texture parameters
            GLToolbox.InitTexParams();
        }
Beispiel #2
0
        public void RenderTexture(int texId)
        {
            // Bind default FBO
            GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, 0);

            // Use our shader program
            GLES20.GlUseProgram(_program);
            GLToolbox.CheckGLError("glUseProgram");

            // Set viewport
            GLES20.GlViewport(0, 0, _viewWidth, _viewHeight);
            GLToolbox.CheckGLError("glViewport");

            // Disable blending
            GLES20.GlDisable(GLES20.GlBlend);

            // Set the vertex attributes
            GLES20.GlVertexAttribPointer(_texCoordHandle, 2, GLES20.GlFloat, false,
                                         0, _texVertices);
            GLES20.GlEnableVertexAttribArray(_texCoordHandle);
            GLES20.GlVertexAttribPointer(_posCoordHandle, 2, GLES20.GlFloat, false,
                                         0, _posVertices);
            GLES20.GlEnableVertexAttribArray(_posCoordHandle);
            GLToolbox.CheckGLError("vertex attribute setup");

            // Set the input texture
            GLES20.GlActiveTexture(GLES20.GlTexture0);
            GLToolbox.CheckGLError("glActiveTexture");
            GLES20.GlBindTexture(GLES20.GlTexture2d, texId);
            GLToolbox.CheckGLError("glBindTexture");
            GLES20.GlUniform1i(_texSamplerHandle, 0);

            // Draw
            GLES20.GlClearColor(0.0f, 0.0f, 0.0f, 1.0f);
            GLES20.GlClear(GLES20.GlColorBufferBit);
            GLES20.GlDrawArrays(GLES20.GlTriangleStrip, 0, 4);
        }
Beispiel #3
0
        public void Init()
        {
            // Create program
            _program = GLToolbox.CreateProgram(VertexShader, FragmentShader);

            // Bind attributes and uniforms
            _texSamplerHandle = GLES20.GlGetUniformLocation(_program,
                                                            "tex_sampler");
            _texCoordHandle = GLES20.GlGetAttribLocation(_program, "a_texcoord");
            _posCoordHandle = GLES20.GlGetAttribLocation(_program, "a_position");

            // Setup coordinate buffers
            _texVertices = ByteBuffer.AllocateDirect(
                TexVertices.Length * FloatSizeBytes)
                           .Order(ByteOrder.NativeOrder()).AsFloatBuffer();

            _texVertices.Put(TexVertices).Position(0);

            _posVertices = ByteBuffer.AllocateDirect(
                PosVertices.Length * FloatSizeBytes)
                           .Order(ByteOrder.NativeOrder()).AsFloatBuffer();

            _posVertices.Put(PosVertices).Position(0);
        }