-1

所以,我只是想为两个与视口大小相同的三角形绘制纹理,但它会破坏图像并使其扭曲,我尝试调整图像文件的大小和所有内容,但似乎没有任何效果。下面是映射纹理并绘制三角形的代码。

 public void Render()
    {
        Texture texture = _textureManager.Get("splash");
        Gl.glEnable(Gl.GL_TEXTURE_2D);
        Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.Id);

        double height = 720;
        double width = 1280;

        double x = 0;
        double y = 0;
        double z = 0;

        float topUV = 0;
        float bottomUV = 1;
        float leftUV = 0;
        float rightUV = 1;

        Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
        Gl.glBegin(Gl.GL_TRIANGLES);
        {
            Gl.glTexCoord2d(leftUV, topUV);
            Gl.glVertex3d(x - width, y + height, z);
            Gl.glTexCoord2d(rightUV, topUV);
            Gl.glVertex3d(x + width, y + height, z);
            Gl.glTexCoord2d(leftUV, bottomUV);
            Gl.glVertex3d(x - width, y - height, z);

            Gl.glTexCoord2d(rightUV, topUV);
            Gl.glVertex3d(x + width, y + height, z);
            Gl.glTexCoord2d(rightUV, bottomUV);
            Gl.glVertex3d(x + width, y - height, z);
            Gl.glTexCoord2d(leftUV, bottomUV);
            Gl.glVertex3d(x - width, y - height, z);
        }
        Gl.glEnd();

    }

这是原始图像: 在此处输入图像描述

结果如下: 在此处输入图像描述

图像为 1920 x 1080,视口为 1280 x 720,但我不太确定这是否重要,因为我尝试调整图像大小但似乎没有任何效果。

4

1 回答 1

0

好的,所以我最终将图像从中心切成两半并加载两个图像,然后我使用了四个三角形。这可能不是最优雅的解决方案,但它工作得很好。我猜这与图像的尺寸有关。(我还更改了纹理坐标和所有顶点的参数,以便在 Stack Overflow 的上下文中更直接)。

public void Render()
    {
        //Draw Left Half
        Texture texture = _textureManager.Get("splash1");
        Gl.glEnable(Gl.GL_TEXTURE_2D);
        Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.Id);


        Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
        Gl.glBegin(Gl.GL_TRIANGLES);
        {
            Gl.glTexCoord2d(0, 0);//top left
            Gl.glVertex2f(-1280 , 720);

            Gl.glTexCoord2d(1, 0);//middle top
            Gl.glVertex2f(0, 720);

            Gl.glTexCoord2d(0, 1);//bottom left
            Gl.glVertex2f(-1280, -720);


            Gl.glTexCoord2d(0, 1);//bottom left
            Gl.glVertex2f(-1280, -720);

            Gl.glTexCoord2d(1, 0);//middle right top
            Gl.glVertex2f(0, 720);

            Gl.glTexCoord2d(1, 1);//bottom middle
            Gl.glVertex2f(0, -720);
        }
        Gl.glEnd();

        //Draw Right Half
        texture = _textureManager.Get("splash2");
        Gl.glBindTexture(Gl.GL_TEXTURE_2D, texture.Id);

        Gl.glBegin(Gl.GL_TRIANGLES);
        {
            Gl.glTexCoord2d(0, 0);//middle top
            Gl.glVertex2f(0, 720);

            Gl.glTexCoord2d(1, 0);//top right
            Gl.glVertex2f(1280, 720);

            Gl.glTexCoord2d(0, 1);//bottom middle
            Gl.glVertex2f(0, -720);

            Gl.glTexCoord2d(1, 0);//top right
            Gl.glVertex2f(1280, 720);

            Gl.glTexCoord2d(0, 1);//bottom middle
            Gl.glVertex2f(0, -720);

            Gl.glTexCoord2d(1, 1);//bottom right
            Gl.glVertex2f(1280, -720);
        }
        Gl.glEnd();
    }
于 2014-11-04T23:52:37.513 回答