0

I have a single texture and two glControls. I need to show the first half portion of texture on glControl2 and second half portion of texture on glControl1. And also I have put two numericupdown controls on left end of texture (range from 0 to 0.5) and another two numericupdown controls on right end of texture (range from 0.5 to 1.0). When I select 0. 4 and 0. 5 on left end of texture, I have to show the area between 0. 4 and 0. 5 on glControl2. And If I select 0. 8 and 1 on right end of texture, I have to show the area between 0. 8 and 1. 0 on glControl1. I have tried like by referring this link . But not getting correctly.

       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);

     }");
        GL.CompileShader(vertShader);

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

    uniform sampler2D sTexture_2;
    uniform float sSelectedRangeLeft;   
    uniform float sSelectedRangeRight;
    uniform float sSelectedRangeLeftEnd;   
    uniform float sSelectedRangeRightEnd;
    uniform int sCurrentGLControl;
    varying vec2 vTexCoordIn;
    void main ()
    {

vec2 vTexCoord=vec2(vTexCoordIn.x,vTexCoordIn.y);

float rightsliderStartval=sSelectedRangeRight;//0.5 to 1.0
float rightsliderEndval=sSelectedRangeRightEnd;//1.0 to 0.5
float rightsliderDelta=rightsliderEndval-rightsliderStartval;

float leftsliderStartval=sSelectedRangeLeftEnd;//0.0 to 0.5
float leftsliderEndval=sSelectedRangeLeft;//0.5 to 0.0
float leftsliderDelta=leftsliderEndval-leftsliderStartval;

 if(sCurrentGLControl==1)//GLControl1
 {
 vec4 colorLeft= texture2D(sTexture_2, vec2((0.5+vTexCoord.x)-(0.5-rightsliderStartval)-(1.0-rightsliderEndval), vTexCoord.y));
 gl_FragColor = colorLeft;

}
 else if(sCurrentGLControl==2) //GLControl2
 {  
 vec4 colorRight= texture2D(sTexture_2, vec2(((vTexCoord.x-0.75)*2.0) +(leftsliderStartval), vTexCoord.y));
 gl_FragColor = colorRight;  
 }
 }");
        GL.CompileShader(fragShader);
    }
nsds
  • 961
  • 4
  • 13
  • 39

1 Answers1

0

Instead of a conditional logic in the shader it seams much simpler to create 2 controls and re-position the geometry (or change a view-port / camera) according to the constrains.

enter image description here

Update I propose following approach to accomplish your task:

  • Create 2 rectangles representing a full view area each
  • In Paint handler of each glControl
    • Position/scale rectangle or adjust a view port (camera) according to values in relevant updown controls
    • Apply shader
    • Draw rectangle
igorushi
  • 1,855
  • 21
  • 19
  • Not only wants to show half portion of texture exactly. But also i want to select particular area from texture as explained in the question. – nsds Jun 25 '19 at 08:51
  • Updated the answer - tell me if it makes sense now. – igorushi Jun 25 '19 at 09:41
  • Viewport values only accept integer values. Updown controls have values range from 0. 0 to 1. 0 – nsds Jun 26 '19 at 04:48
  • By viewport I considered one of the View | Model | Projection matrices... Not sure what Viewport property do you mention but if it's integer to can divide it by width/height in order to normalize – igorushi Jul 10 '19 at 10:40