纹理映射的奇怪问题
我试图在加载到 Java 中的四边形 3D 世界上使用预先生成的 PNG 文件中的纹理坐标,并使用 LWJGL 的 slick-util 扩展进行加载。
纹理文件为 192x96 像素,且格式正确。它由 6x3 32x32 块组成。
3d 四边形的宽度和长度均为 1.5f。它们间隔适当。
我在获取正确的纹理坐标时遇到问题。当我将 0.0f 到 0.333333f 作为 y 坐标时,我得到的高度略高于显示的顶部图块的高度。然而,如果我输入 0.0f-0.25f,我会得到正好 1/3,这是我的图块的高度。我还没有找到 X 坐标的神奇数字,但也许有人可以向我解释为什么根据纹理坐标 96 的 1/4 是 24,或者我做错了什么?我怀疑这可能是我的四边形尺寸和纹理之间的冲突。
立方体的顶部使用纹理坐标 (0.0, 0.0f)、(0.0, 0.333333f)、(0.166666f, 0.333333f)、(0.166666f, 0.0f),从左上角逆时针移动到右上角。同样,主要纹理文件是 32x32 的图块,排列成 192x96(96 是高度)。
请注意,我在其中一个图块的顶部放置了一条白线以查看其边框,在其底部放置了一条黑线,然后在其下方的下一个图块的顶部放置了一条白线。纹理“渗透”得太深。正如您所看到的,其他纹理有自己更奇怪的坐标。
假设图像的顶部是 1.0 而不是底部来排列纹理坐标,会产生奇数正方形,在四边形应该在的中心有一个矩形孔。
我正在使用 TEX_ENV GL_MODULATE。
I am attempting to use texture coordinates from a pre-generated PNG file on a 3d world of quads loaded into Java with LWJGL's slick-util extension.
The texture file is 192x96pixels, and properly formatted. It's composed of 6x3 32x32 tiles.
The 3d quads are 1.5f wide and long. They are spaced apart properly.
I am having issues getting the right texture coordinates. When I put 0.0f to 0.333333f as the y coordinates, I get slightly more than the top tile's height displayed. However, if I put 0.0f-0.25f, I get exactly 1/3rd, which is my tile's height. I have yet to find a magic number for the X coordinates, but maybe someone could explain to me why 1/4 of 96 is 24 according to textures coordinates, or what I'm doing wrong? I'm suspecting it could be a clash between my quad size and textures.
The tops of the cubes are using the texture coordinates (0.0, 0.0f), (0.0, 0.333333f), (0.166666f, 0.333333f), (0.166666f, 0.0f), which is applied moving anticlockwise from the top left to the top right. Again, the main texture file is 32x32 tiles arranged to make 192x96(96 is the height).
Notice I placed a white line at the top of one of the tiles to see its border, and black line at it's bottom, then a white line for the top of the next one below it. The texture 'bleeds' too far down. The other textures have their own even stranger coordinates, as you can see.
Arranging texture coordinates with the assumption the top of the image is 1.0 rather than the bottom produces odd squares with a rectangular hole in the center where quads should be.
I am using TEX_ENV GL_MODULATE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
纹理大小通常是 2 的幂。我怀疑有人将 192x96 纹理调整为 256x128 或 256x256 纹理。但这并不能真正解释您发现的值...但是,我认为,如果您将纹理大小调整为 256x256(增加大小,不要缩放!)并基于此计算纹理坐标,您的问题就会消失离开。
Texture sizes are usually a power of 2. I suspect something resized your 192x96 texture as a 256x128 or 256x256 texture. This doesn't really explain the values you found however... But, I think, if you resize your texture to 256x256(increase the size, don't scale!) and calculate your texture coordinates based on that, your problem will go away.
我不了解 java,但使用 Objective C 和 openGL ES 中的图像图集,您需要使纹理小于您从图集中选择它们时所指的纹理。
您是否在纹理图像之间留有足够的间隙以防止“渗色”?
I don't know about java but with my image atlases in objective C and openGL ES you need to make the textures smaller than what you are referring to when selecting them from the atlas.
Have you left a sufficient gap between the texture images to prevent 'bleeding?