嗯,我正在嘗試使用LWJGL爲OpenGL中的窗口截圖。下面的代碼:glReadPixels()無法填充ByteBuffer
ByteBuffer pixels = ByteBuffer.allocateDirect(800*600*4);
pixels.order(ByteOrder.nativeOrder());
while(!Display.isCloseRequested()) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
render();
Display.update();
// "Screenshot" block
if(Keyboard.isKeyDown(Keyboard.KEY_Q)) {
pixels.clear();
glReadPixels(0, 0, 800, 600, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
pixels.flip();
// pixels.position() and pixels.limit() tells us that there is nothing in the buffer
// ...
}
}
而且......
我已經嘗試過的代碼的各種版本,如Display.update之前放置了「截圖」塊()。並使用glReadBuffer(GL_BACK/GL_FRONT)和glDrawBuffer(GL_BACK/GL_FRONT)的組合無濟於事。
我禁用了所有的OpenGL狀態和渲染,因此只顯示一個空白屏幕並嘗試使用glReadPixels。一個空白屏幕假設在緩衝區中,但沒有任何內容在緩衝區中。
glGetError()不會產生任何錯誤。
我有一個類似的C +版本,工作正常。
我在NVIDIA Corporation GeForce GTS 450/PCI/SSE2上運行Windows 7,OpenGL 4.10和LWJGL 2.7.1版。
那麼,什麼問題?有任何想法嗎?提前致謝。