画像の一部だけを取り、それをLWJGLのテクスチャに変換する方法があるかどうか知りたいのですが。これが、画像をロードしてテクスチャとして使用するための基本的なコードです。PNGデコーダーはtwlライブラリからのものです。助けてくれてありがとう。
int floorTexture = glGenTextures();
{
InputStream in = null;
try {
in = new FileInputStream("res/floor.png");
PNGdecoder decoder = new PNGdecoder(in);
ByteBuffer buffer = BufferUtils.createByteBuffer(4 * decoder.getWidth() * decoder.getHeight());
decoder.decode(buffer, decoder.getWidth() * 4, Format.RGBA);
buffer.flip();
in.close();
glBindTexture(GL_TEXTURE_2D, floorTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, decoder.getWidth(), decoder.getHeight(), 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
glBindTexture(GL_TEXTURE_2D, 0);
} catch (FileNotFoundException ex) {
System.err.println("Failed to find the texture files.");
Display.destroy();
System.exit(1);
} catch (IOException ex) {
System.err.println("Failed to load the texture files.");
Display.destroy();
System.exit(1);
}
}