且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在LWJGL中使用带有ByteBuffer的glTexImage2D时的空纹理

更新时间:2022-03-24 05:11:46

如果您使用

ByteBuffer buffer = ByteBuffer.wrap(data);

缓冲区不是direct

你必须使用 BufferUtils.createByteBuffer

You have to use BufferUtils.createByteBuffer:

ByteBuffer buffer = BufferUtils.createByteBuffer(data.length);
buffer.put(data);
buffer.flip();

说明:

BufferUtils.createByteBuffer 分配具有指定容量的直接本机排序的bytebuffer。

BufferUtils.createByteBuffer allocates a direct native-ordered bytebuffer with the specified capacity.

put(vboData)从当前位置开始将数据传输到缓冲区(在这种情况下,这是缓冲区的起点)。缓冲区位置增加数据的大小。所以新的缓冲区位置在新数据的末尾。

put(vboData) transfers the the data to the buffer, beginning at the current position (which is the start of the buffer in this case). The buffer position is incremented by the size of the data. So the new buffer position is at the end of the new data.

flip()设置限制(长度) )缓冲区到当前位置,然后将位置设置为零。

flip() sets the limit (length) of the buffer to the current position and then the position is set to zero.