opengl - OpenGL:纹理未正确对齐
问题描述
我对 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;
}
我正在使用上传纹理
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);
}
不幸的是,我最终得到了这样的结果:
但实际上它应该看起来像这样(在搅拌机中):
可以找到纹理:这是纹理
所以一切都是弯曲的,并且有点遵循对角线。该模型是用搅拌机制作的,因此具有适当的纹理坐标。我还设法将模型和纹理加载到另一个引擎中。但不在我的。有谁知道如何解决这个问题?
解决方案
推荐阅读
- c++ - 我如何在标准输出的特定位置写入?
- java - 通过使用 Java 8 将元素添加到链表中来比较数组列表和链表
- php - 如何更改 PDO(SELECT / WHERE)获取查询返回的关联数组中的字段名称?
- r - 如何在 R 中为粒子运动设置动画
- ssis - 如何使用 SSIS 配置管理器?即轻松将开发或测试或生产配置设置为流程?
- ruby-on-rails - 是否有可能以编程方式从 sidekiq 作业中检索批处理 ID 或从批处理中获取活动/待处理作业 ID?
- angular - 在 Azure 中部署私有 npm 包
- tensorflow - 了解 TF 2.0 beta 中的图表
- spring-boot - 没有找到具有自定义 Jackson ObjectMapper 的类的描述
- netlify - Netlify:如果此文件夹上的更改部署到不同的存储库(?)