lwjgl ウィンドウに npot テクスチャを表示しようとしています。結果は次のとおりです。
テクスチャは 4 回繰り返され、上下が逆になり、横線によって歪んでいます。明らかに、これは意図した結果ではありません。関連するソースコードであると私が感じるものは次のとおりです。
テクスチャをロードするユーティリティ メソッド:
// load the image
BufferedImage image = null;
try {
image = ImageIO.read(new File(path));
}
// exit on error
catch (IOException exception) {
Utility.errorExit(exception);
}
// add the image's data to a bytebuffer
ByteBuffer buffer = BufferUtils.createByteBuffer(image.getWidth() * image.getHeight() * 4);
for(int x = 0; x < image.getWidth(); x++) {
for(int y = 0; y < image.getHeight(); y++) {
int pixel = image.getRGB(x, y);
buffer.put((byte) ((pixel >> 16) & 0xFF)); // red
buffer.put((byte) ((pixel >> 8) & 0xFF)); // green
buffer.put((byte) (pixel & 0xFF)); // blue
buffer.put((byte) 0xFF); // alpha
}
}
// flip the buffer
buffer.flip();
// generate and bind the texture
int handle = GL11.glGenTextures();
GL11.glBindTexture(GL31.GL_TEXTURE_RECTANGLE, handle);
//Setup wrap mode
GL11.glTexParameteri(GL31.GL_TEXTURE_RECTANGLE, GL11.GL_TEXTURE_WRAP_S, GL12.GL_CLAMP_TO_EDGE);
GL11.glTexParameteri(GL31.GL_TEXTURE_RECTANGLE, GL11.GL_TEXTURE_WRAP_T, GL12.GL_CLAMP_TO_EDGE);
//Setup texture scaling filtering
GL11.glTexParameteri(GL31.GL_TEXTURE_RECTANGLE, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL31.GL_TEXTURE_RECTANGLE, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
// set the texture data
GL11.glTexImage2D(GL31.GL_TEXTURE_RECTANGLE, 0, GL11.GL_RGBA8, image.getWidth(), image.getHeight(), 0,
GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE, buffer);
// return the handle
return handle;
テクスチャをサンプラーにバインドするユーティリティ メソッド:
// set the sampler's texture unit
GL20.glUniform1i(samplerLocation, GL13.GL_TEXTURE0 + textureUnit);
// bind the texture to the texture unit
GL13.glActiveTexture(GL13.GL_TEXTURE0 + textureUnit);
GL11.glBindTexture(GL31.GL_TEXTURE_RECTANGLE, textureID);
フラグメント シェーダー:
#version 150
#extension GL_ARB_texture_rectangle : enable
uniform sampler2DRect sampler;
in vec2 vTexture;
out vec4 color;
void main()
{
color = texture2DRect(sampler, vTexture);
}
関連すると思われる最後の情報は、テクスチャ座標です。
- 左下ポイント: (0, 0)
- 左上点: (0, 600)
- 右上点: (800, 600)
- 右下点 (800, 0)
私は複数のことを間違っていると思います。私が提供できる情報が他にもあると思われる場合は、コメント セクションに投稿してください。ありがとう!
PSテクスチャが手動で読み込まれると言う理由は、テクスチャの読み込みに Slick-Util を使用することに慣れているためですが、Slick-Util は npot テクスチャをサポートしていないと聞いたため、この特定のテクスチャには使用できませんでした。