如何从图像的顶部和底部 hide/remove 特定区域 - GLControl
How to hide/remove particular area from top and bottom of image - GLControl
我可以在 glControl
中使用 opengl 显示下图。有什么方法可以从 glControl
的底部和顶部均等地剪切或隐藏特定区域(比如从顶部和底部 50px)?下面是我用来计算 glControl
大小的代码。我可以通过更改视口上的值来实现吗?
private void OpenGL_Size(GLControl glControl, VideoCaptureDevice videoSource)//always in portrait mode
{
decimal RateOfResolution = (decimal)videoSource.VideoResolution.FrameSize.Width / (decimal)videoSource.VideoResolution.FrameSize.Height;
decimal screenHeightbyTwo = this._Screenheight / 2;
RateOfResolution = 1 / RateOfResolution;// portrait
openGLheight = Convert.ToInt32(screenHeightbyTwo); // height is fixed; calculate the width
openGLwidth = (Convert.ToInt32(RateOfResolution * screenHeightbyTwo));
glControl.Width = openGLwidth;
glControl.Height = openGLheight;
}
GL.Viewport(new Rectangle(0, 0, glControl.Width, glControl.Height));
着色器代码
precision highp float;
uniform sampler2D sTexture;
varying vec2 vTexCoordIn;
void main ()
{
vec4 color = texture2D(sTexture,vTexCoordIn);
gl_FragColor = color;
}
如果你想跳过纹理的某些部分,那么你可以使用discard
关键字。此命令导致片段的输出值被丢弃,并且根本不绘制片段。
precision highp float;
uniform sampler2D sTexture;
varying vec2 vTexCoordIn;
void main ()
{
if (vTexCoordIn.y < 0.1 || vTexCoordIn.y > 0.9)
discard;
vec4 color = texture2D(sTexture, vTexCoordIn);
gl_FragColor = color;
}
如果给定图片的高度和需要舍弃的区域的高度,则条件为:
float img_h_px = 432.0; // height of the image in pixel
float area_h_px = 50.0; // area height in pixel
float w = area_h_px/img_h_px;
if (vTexCoordIn.y < w || vTexCoordIn.y > (1.0-w))
discard;
我可以在 glControl
中使用 opengl 显示下图。有什么方法可以从 glControl
的底部和顶部均等地剪切或隐藏特定区域(比如从顶部和底部 50px)?下面是我用来计算 glControl
大小的代码。我可以通过更改视口上的值来实现吗?
private void OpenGL_Size(GLControl glControl, VideoCaptureDevice videoSource)//always in portrait mode
{
decimal RateOfResolution = (decimal)videoSource.VideoResolution.FrameSize.Width / (decimal)videoSource.VideoResolution.FrameSize.Height;
decimal screenHeightbyTwo = this._Screenheight / 2;
RateOfResolution = 1 / RateOfResolution;// portrait
openGLheight = Convert.ToInt32(screenHeightbyTwo); // height is fixed; calculate the width
openGLwidth = (Convert.ToInt32(RateOfResolution * screenHeightbyTwo));
glControl.Width = openGLwidth;
glControl.Height = openGLheight;
}
GL.Viewport(new Rectangle(0, 0, glControl.Width, glControl.Height));
着色器代码
precision highp float;
uniform sampler2D sTexture;
varying vec2 vTexCoordIn;
void main ()
{
vec4 color = texture2D(sTexture,vTexCoordIn);
gl_FragColor = color;
}
如果你想跳过纹理的某些部分,那么你可以使用discard
关键字。此命令导致片段的输出值被丢弃,并且根本不绘制片段。
precision highp float;
uniform sampler2D sTexture;
varying vec2 vTexCoordIn;
void main ()
{
if (vTexCoordIn.y < 0.1 || vTexCoordIn.y > 0.9)
discard;
vec4 color = texture2D(sTexture, vTexCoordIn);
gl_FragColor = color;
}
如果给定图片的高度和需要舍弃的区域的高度,则条件为:
float img_h_px = 432.0; // height of the image in pixel
float area_h_px = 50.0; // area height in pixel
float w = area_h_px/img_h_px;
if (vTexCoordIn.y < w || vTexCoordIn.y > (1.0-w))
discard;