Java LWJGL OpenGL纹理图集出血

时间:2013-12-17 08:10:16

标签: java opengl textures voxel atlas

我一直在尝试在LWJGL中制作基于体素的游戏,但我遇到了一个问题!

我的体素的纹理会渗透到纹理图集上的相邻纹理中。

我不想使用纹理数组或在纹理周围创建边框。

这是我的代码......

public class SpriteSheet
{
private int terrainID;

public SpriteSheet(float blockResolution)
{
try
{
PNGDecoder decoder = new PNGDecoder(new FileInputStream("res/Terrain.png"));

int width = decoder.getWidth();
int height = decoder.getHeight();

int bytesPerPixel = 4;

ByteBuffer buffer = BufferUtils.createByteBuffer(bytesPerPixel * width * height);

decoder.decode(buffer, width * bytesPerPixel, PNGDecoder.RGBA);

buffer.flip();

terrainID = glGenTextures();

glBindTexture(GL_TEXTURE_2D, terrainID);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);

glBindTexture(GL_TEXTURE_2D, terrainID);

}
catch(IOException e)
{
e.printStackTrace();
}
}

public void dispose()
{
glDeleteTextures(terrainID);
}
}

我做错了什么,我正在使用GL_CLAMP_TO_EDGE我以为会解决它?

我没有使用mipmap。

与图片类似问题的网址:https://gamedev.stackexchange.com/questions/46963/how-to-avoid-texture-bleeding-in-a-texture-atlas

0 个答案:

没有答案
相关问题