Shader code for show selected part of image


I only want to show second half portion of an image in my glcontrol, in a condition that only 0.7 to 0. 9 of second half is want to see in glControl. For that I have done like below. But it shows portion of first half of image too. Please help to correct the shader code.

      public void CreateShaders()
    /***********Vert Shader********************/
    vertShader = GL.CreateShader(ShaderType.VertexShader);
    GL.ShaderSource(vertShader, @"attribute vec3 a_position;
                                varying vec2 vTexCoordIn; 

                                void main() {
                       vTexCoordIn=( a_position.xy+1)/2 ;                                 
                       gl_Position = vec4(a_position,1);

    /***********Frag Shader ****************/
    fragShader = GL.CreateShader(ShaderType.FragmentShader);
    GL.ShaderSource(fragShader, @"precision highp float;

uniform sampler2D sTexture;
varying vec2 vTexCoordIn;
void main ()
vec2 vTexCoord=vec2(vTexCoordIn.x,vTexCoordIn.y);
float rightsliderStartval=0.7;//0.5 to 1.0
float rightsliderEndval=0.9;//1.0 to 0.5
float rightsliderDelta=rightsliderEndval-rightsliderStartval;

vec4 color= texture2D(sTexture, vec2((0.5+vTexCoord.x)-(rightsliderStartval-0.5)-(1.0-rightsliderEndval), vTexCoord.y));
gl_FragColor = color;


Welcome to the forums.

No, that’s not how this works. We’re not on your programming team.

Try to solve the problem yourself. After you’ve looked into the possible causes of that problem, if you have specific technical questions related to OpenGL, then ask those questions here. See the Forum Posting Guidelines for tips in composing your posts to maximize your chance of getting useful feedback.

1 Like