【问题标题】:Perspective-correct - Trapezoid - 2D - OpenGL GLSL透视正确 - 梯形 - 2D - OpenGL GLSL
【发布时间】:2013-10-08 21:00:30
【问题描述】:

我在 OpenGL 中绘制带纹理的梯形并出现仿射问题:

http://upload.wikimedia.org/wikipedia/commons/5/57/Perspective_correct_texture_mapping.jpg

我希望我的纹理透视正确。

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

http://i.stack.imgur.com/O0AnC.png

我粘贴我当前的代码项目:

  • c++:

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

  • 顶点:

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

  • 片段:

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

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

【问题讨论】:

标签: opengl glsl perspective


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 2011-08-19
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多