java - glReadPixels() fails to fill ByteBuffer -
well, i'm trying take screenshot window in opengl using lwjgl. here's code:
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() , pixels.limit() tells there nothing in buffer // ... } }
and...
i've tried various versions of code, placing "screenshot" block before display.update(). , using combinations of glreadbuffer(gl_back/gl_front) , gldrawbuffer(gl_back/gl_front) no avail.
i've disabled opengl states , rendering, blank screen appears , tried using glreadpixels. blank screen supposes in buffer, nothing in buffer.
glgeterror() doesn't produce error.
i have similar c+ version works fine.
i'm running windows 7, opengl 4.10 , lwjgl version 2.7.1 on nvidia corporation geforce gts 450/pci/sse2.
so, what's problem? ideas? in advance.
pixels.position() , pixels.limit() tells there nothing in buffer
do they? think more foolproof method @ contents of buffer.
also, display.update
swaps buffers. contents of buffer undefined after swap. should either read front buffer (not idea) or read buffer before swapping.
Comments
Post a Comment