简体   繁体   English

纹理映射的奇怪问题

[英]Strange issues with texture mapping

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. 我正在尝试使用通过LWJGL的slick-util扩展加载到Java中的Quads的3d世界上的预生成PNG文件中的纹理坐标。

The texture file is 192x96pixels, and properly formatted. 纹理文件为192x96像素,并且格式正确。 It's composed of 6x3 32x32 tiles. 它由6x3 32x32瓦片组成。

The 3d quads are 1.5f wide and long. 3d方形块的宽度为1.5f。 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. 当我将0.0f设置为0.333333f作为y坐标时,我得到的值略大于显示的顶部图块的高度。 However, if I put 0.0f-0.25f, I get exactly 1/3rd, which is my tile's height. 但是,如果我将0.0f-0.25f放进去,我得到的精确度就是1/3,即我瓷砖的高度。 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? 我还没有找到X坐标的幻数,但是也许有人可以向我解释,为什么根据纹理坐标,96的1/4是24,还是我做错了? 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. 多维数据集的顶部使用纹理坐标(0.0,0.0f),(0.0、0.333333f),(0.166666f,0.333333f),(0.166666f,0.0f),该纹理坐标从左上角到右上角。 Again, the main texture file is 32x32 tiles arranged to make 192x96(96 is the height). 再次,主要纹理文件是32x32瓦片,排列为192x96(96是高度)。

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. 在假设图像的顶部为1.0而不是底部的情况下排列纹理坐标会生成奇数正方形,其中心应有一个四边形的矩形孔。

I am using TEX_ENV GL_MODULATE. 我正在使用TEX_ENV GL_MODULATE。

Texture sizes are usually a power of 2. I suspect something resized your 192x96 texture as a 256x128 or 256x256 texture. 纹理大小通常是2的幂。我怀疑有些东西会将您的192x96纹理调整为256x128或256x256纹理。 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. 但是,这并不能真正解释您找到的值...但是,我认为,如果将纹理的大小调整为256x256(增大大小,不缩放!)并据此计算纹理坐标,问题就会解决。远。

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. 我不了解Java,但是在目标C和openGL ES中使用图像图集时,您需要使纹理比从图集中选择它们时要参考的要小。

Have you left a sufficient gap between the texture images to prevent 'bleeding? 您在纹理图像之间是否留有足够的间隙以防止“出血”?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM