Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
透视校正-梯形-2D-OpenGL GLSL_Opengl_Glsl_Perspective - Fatal编程技术网

透视校正-梯形-2D-OpenGL GLSL

透视校正-梯形-2D-OpenGL GLSL,opengl,glsl,perspective,Opengl,Glsl,Perspective,我正在OpenGL中绘制纹理梯形,出现仿射问题: 我希望我的纹理在这个角度正确 我必须在图像空间(sw tw w)内插,我不知道怎么做: 我粘贴当前代码项目: c++: ttps://gist.github.com/danicomas/a1f5a0e6849b3ac8b51c169c2c030e37 (添加http) 顶点: ttps://gist.github.com/danicomas/fee77cf48fc5085f61a2fcf7a2c6d5de (添加http) 片段:

我正在OpenGL中绘制纹理梯形,出现仿射问题:

我希望我的纹理在这个角度正确

我必须在图像空间(sw tw w)内插,我不知道怎么做:

我粘贴当前代码项目:

  • c++:
ttps://gist.github.com/danicomas/a1f5a0e6849b3ac8b51c169c2c030e37 (添加http)

  • 顶点:
ttps://gist.github.com/danicomas/fee77cf48fc5085f61a2fcf7a2c6d5de (添加http)

  • 片段:
ttps://gist.github.com/danicomas/0bbd679d2d7da18bc61ee23b36096a16 (添加http)


我该怎么做?一些示例代码?

最后。我发现这是一个简单的解决方案

  • c++

glPushMatrix();
glBegin(GL_QUADS);

float scale_texcoord = 0.7;
float top = 0.7;

float tx = scale_texcoord * top;

glTexCoord2f(-1 / 2, -1);
glVertex2f(-1.4, -1);

glTexCoord4f(0,  0, 0, tx);
glVertex2f(-top,  1);

glTexCoord4f( tx,  0, 0, tx);
glVertex2f( top,  1);

glTexCoord2f( 1, -1);
glVertex2f( 1.4, -1);

glEnd();
glPopMatrix();
uniform sampler2D sampler;

void main()
{
 vec2 interpolated = vec2(gl_TexCoord[0].x / gl_TexCoord[0].w, gl_TexCoord[0].y);

 gl_FragColor = texture2D(sampler, vec2(interpolated.x, interpolated.y));
}

  • 片段:

glPushMatrix();
glBegin(GL_QUADS);

float scale_texcoord = 0.7;
float top = 0.7;

float tx = scale_texcoord * top;

glTexCoord2f(-1 / 2, -1);
glVertex2f(-1.4, -1);

glTexCoord4f(0,  0, 0, tx);
glVertex2f(-top,  1);

glTexCoord4f( tx,  0, 0, tx);
glVertex2f( top,  1);

glTexCoord2f( 1, -1);
glVertex2f( 1.4, -1);

glEnd();
glPopMatrix();
uniform sampler2D sampler;

void main()
{
 vec2 interpolated = vec2(gl_TexCoord[0].x / gl_TexCoord[0].w, gl_TexCoord[0].y);

 gl_FragColor = texture2D(sampler, vec2(interpolated.x, interpolated.y));
}

你的帖子和这篇文章:都很有帮助。