我想使用opengl并排显示两个图像(一个图像在屏幕左侧,另一个在屏幕右侧)。我已经在下面的着色器代码中使用了它。它以全屏显示两个图像。但是只能看到两个图像的一部分。我应该在哪里纠正代码以在两面都显示完整图像?
private void CreateShaders()
{
/***********Vert Shader********************/
vertShader = GL.CreateShader(ShaderType.VertexShader);
GL.ShaderSource(vertShader, @"attribute vec3 a_position;
varying vec2 vTexCoord;
void main()
{
vTexCoord = (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;uniform sampler2D sTexture1;
uniform int screenwidth;
varying vec2 vTexCoord;
void main ()
{
vec4 color = texture2D (sTexture, vTexCoord); //image 1
vec4 color1=texture2D (sTexture1, vTexCoord); //image2
if(vTexCoord.x<0.5)
gl_FragColor = color;
else
gl_FragColor = color1;
}");
GL.CompileShader(fragShader);
}
答案 0 :(得分:1)
您必须在片段着色器中缩放和转换纹理坐标的<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
</bookstore>
my second xml after generation :
<bookstore>
<book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
</bookstore>
分量,
左侧为纹理坐标x
,
右边是vec2(vTexCoord.x*2.0, vTexCoord.y)
:
vec2(vTexCoord.x*2.0-1.0, vTexCoord.y))