OpenGL:纹理未正确对齐

OpenGL:纹理未正确对齐,opengl,lwjgl,texture-mapping,Opengl,Lwjgl,Texture Mapping,我对OpenGL(在LWJGL中)和纹理映射有问题。我正在使用加载ARGB图像 public static ByteBuffer toByteArray(BufferedImage image) { int[] pixels = new int[image.getWidth() * image.getHeight()]; image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidt

我对OpenGL(在LWJGL中)和纹理映射有问题。我正在使用加载ARGB图像

public static ByteBuffer toByteArray(BufferedImage image) {
    int[] pixels = new int[image.getWidth() * image.getHeight()];
    image.getRGB(0, 0, image.getWidth(), image.getHeight(), pixels, 0, image.getWidth());
    ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
    for (int y = 0; y < image.getHeight(); y++) {
        for (int x = 0; x < image.getWidth(); x++) {
            int pixel = pixels[y * image.getWidth() + x];
            buffer.put((byte) ((pixel >> 16) & 0xFF)); // Red component
            buffer.put((byte) ((pixel >> 8) & 0xFF)); // Green component
            buffer.put((byte) ((pixel >> 0) & 0xFF)); // Blue component
            buffer.put((byte) ((pixel >> 24) & 0xFF)); // Alpha component.
        }
    }
    buffer.flip();
    return buffer;
}
不幸的是,我的结局是这样的:

但实际上它应该是这样的(在搅拌机中):

可以找到纹理:


所以一切都是弯曲的,有点像对角线。该模型由混合器制作,因此具有适当的纹理坐标。我还设法将模型和纹理加载到另一个引擎中。但不是在我的。有人知道如何解决这个问题吗?

我对他们进行了三角测量。图像也使用GL_三角形绘制。我避免使用四边形。啊,对不起。该模型已经在blender中使用其算法规范化为三角形。我从波前OBJ中读取已经定义的三角形。这似乎奏效了。但是我当然会检查的,你能解释一下我们在图像中看到了什么吗?在不知道现场的情况下很难判断。你能展示一下搅拌机里的场景和纹理吗?嘿,尼科。它基本上是一个带桌子的房间。正如您所期望的,我在blender中添加了一个场景图像和一个到烘焙纹理的链接(没有表格和矩阵-这些是单独的对象)。四面墙、天花板和地板都映射到了纹理。好的,谢谢。我得到了它。错误在于加载波前obj。在从面条目检索正确的顶点纹理坐标时发生了一个一个接一个的错误。这是一个提示,在这里的评论,似乎被删除。
int[] textureIds = new int[textures.size()];
GL11.glGenTextures(textureIds);
int i = 0;
for (Texture texture : textures.values()) {
    int textureId = textureIds[i++];
    GL13.glActiveTexture(GL13.GL_TEXTURE0);
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, textureId);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
    GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
    GL11.glPixelStorei(GL11.GL_UNPACK_ALIGNMENT, 4);

    BufferedImage data = texture.load();
    ByteBuffer bytes = Texture.toByteArray(data);
    GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, data.getWidth(), data.getHeight(), 0, GL11.GL_RGBA,
        GL11.GL_UNSIGNED_BYTE, bytes);
    // GL30.glGenerateMipmap(GL11.GL_TEXTURE_2D);
    texture.setTextureId(textureId);

    GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
}