Using below code I can display an image in openGL control. Which is in rectangular shape. Now I want to project top and bottom area of this rectangular to a cylindrical shape.I mean need to perform a rectangular to cylidrical projection on openGL. How can I achieve this?
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; varying vec2 vTexCoord;
void main ()
{
// vec4 color = texture2D (sTexture, vTexCoord);
vec2 x =vTexCoord - vec2(0.5);
float r = length(x);//radious
float u = r*atan( vTexCoord.x/sqrt(r*r-(vTexCoord.x*vTexCoord.x )));
float v = (r*vTexCoord.y)/sqrt(r*r );
vec4 color = texture2D(sTexture, vec2(u, v));
gl_FragColor = color;
}");
GL.CompileShader(fragShader);
}
Hope making some changes on vTexCoord of shader code will do the result.