好吧,我正在尝试使用 LWJGL 为 OpenGL 中的窗口截屏。这是代码:
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() 之前放置“Screenshot”块。并且使用 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 版。
所以有什么问题?有任何想法吗?提前致谢。