我有一个纹理和两个glControls。我需要在glControl2上显示纹理的前半部分,在glControl1上显示纹理的后半部分。 另外,我在纹理的左端放置了两个numericupdown控件(范围从0到0.5),在纹理的右端放置了另外两个numericupdown控件(范围从0.5到1.0)。当我在纹理的左端选择0. 4和0. 5时,我必须在glControl2上显示0. 4和0. 5之间的区域。 而且,如果我在纹理的右端选择0. 8和1,则必须在glControl1上显示0. 8和1之间的区域。0。我已经尝试过参考此link。但是无法正确获取。
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);
}