在3DS VAO上映射纹理原来是镜像的 [英] Mapping texture on 3DS VAO turns out mirrored

查看:69
本文介绍了在3DS VAO上映射纹理原来是镜像的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在教程之后实现了3ds模型加载器. 目前,我的程序使用VAO来显示内容.到目前为止,这对于简单的多维数据集和图块均有效.纹理显示正确.

I implemented a 3ds modelloader following this tutorial. Currently my program uses VAOs do display things. This worked so far for simple cubes and tiles. Textures were displaying correctly.

但是,当我将3DS模型加载到VAO中时,情况就不同了.该模型在顶点方面看起来是正确的,但是由于某种原因,纹理沿Y轴镜像.

However, when I load the 3DS model into a VAO its a different sotry. The model looks correct concerning the vertices, but the texture is mirrored along the Y axis for some reason.

这就是我阅读紫外线的方法:

This is how i read the UV:

case 0x4140:

qty = reader.ReadUInt16();        // 2 bytes

UV[] texcoords = new UV[qty];

for (i = 0; i < qty; i++)
{
    texcoords[i] = new UV
    {
        U = reader.ReadSingle(),  // 4 bytes
        V = reader.ReadSingle()   // 4 bytes
    };
}

tb = new TexCoordBuffer(texcoords);

还有紫外线:

[StructLayout(LayoutKind.Sequential)]
struct UV
{
    public float U { get; set; }
    public float V { get; set; }
}

创建属性:

GL.EnableVertexAttribArray(2);
texCoordBuffer.Bind();
GL.VertexAttribPointer(2, 2, VertexAttribPointerType.Float, false, Vector2.SizeInBytes, 0);
GL.BindAttribLocation(shaderHandle, 2, "in_texture");

如何创建"纹理:

GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.LinearMipmapNearest);

GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Replace);

GL.TexImage2D(
    TextureTarget.Texture2D,
    0,
    PixelInternalFormat.Rgba,
    bmpData.Width,
    bmpData.Height,
    0,
    PixelFormat.Bgra,
    PixelType.UnsignedByte,
    bmpData.Scan0);

GL.GenerateMipmap(GenerateMipmapTarget.Texture2D);

结果是这样的:左侧为示例,右侧为我的版本:

This is how it turns out: Example left, my version right:

推荐答案

是的,在为OpenGL导入模型时应翻转V纹理坐标. 3DS模型和OpenGL中的UV贴图不同. OpenGL纹理坐标应为(U; 1-V)

Yes you should flip V texture coordinate when importing model for OpenGL. UV maps in 3DS model and OpenGL are different. OpenGL texture coordinates should be (U; 1-V)

这可以在导入模型代码中解决,也可以通过在3D建模软件中选择相应的UV翻转选项来解决.

This can be fixed either in import model code or by selecting corresponding option for flipping UV in your 3D modelling software.

您可以查看答案和评论以了解此相关问题中的此行为: https://stackoverflow.com/a /8621571/405681

You can take a look at answer and comments to understand this behavior in this related question: https://stackoverflow.com/a/8621571/405681

这篇关于在3DS VAO上映射纹理原来是镜像的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆