在两个单独的glcontrols上并排显示图像的一半-openTK [英] Show half portion of image side by side on two separate glcontrols - openTK

查看:94
本文介绍了在两个单独的glcontrols上并排显示图像的一半-openTK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个纹理和两个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.我已经尝试通过引用此链接.但无法正确获得.

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

推荐答案

代替着色器中的条件逻辑,它可以更轻松地创建2个控件并重新定位几何体(或更改视口/相机),约束.

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.

更新 我提出以下方法来完成您的任务:

Update I propose following approach to accomplish your task:

  • 创建2个矩形,每个矩形代表一个完整的视图区域
  • 在每个的Paint处理程序中 glControl
    • 位置/比例矩形或调整视口(相机)根据相关上拉控件中的值
    • 应用着色器
    • 绘制矩形
    • 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

      这篇关于在两个单独的glcontrols上并排显示图像的一半-openTK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆