Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6160181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:15:26+00:00 2026-05-23T21:15:26+00:00

Well, I’m trying to take a screenshot for a window in OpenGL using LWJGL.

  • 0

Well, I’m trying to take a screenshot for a window in OpenGL using LWJGL. Here’s the 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() and pixels.limit() tells us that there is nothing in the buffer
        // ...
    }
}

And…

  • I’ve already tried various versions of the code, like placing the “Screenshot” block before Display.update(). And using combinations of glReadBuffer(GL_BACK/GL_FRONT) and glDrawBuffer(GL_BACK/GL_FRONT) to no avail.

  • I’ve disabled all OpenGL states and rendering, so that only a blank screen appears and tried using glReadPixels. A blank screen supposes to be in the buffer, but nothing is in the buffer.

  • glGetError() doesn’t produce any error.

  • I have a similar C+ version that works fine.

  • I’m running Windows 7, OpenGL 4.10 and LWJGL version 2.7.1 on NVIDIA Corporation GeForce GTS 450/PCI/SSE2.

So, what’s the problem? Any ideas? Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T21:15:26+00:00Added an answer on May 23, 2026 at 9:15 pm

    pixels.position() and pixels.limit() tells us that there is nothing in the buffer

    Do they? I think a more foolproof method would be to look at the contents of the buffer.

    Also, Display.update swaps buffers. The contents of the back buffer are undefined after a swap. So you should either read from the front buffer (not a good idea) or read the back buffer before swapping.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well im here because i have a problem. i have code that was created
well I'm trying to create a great playlist of music, only using a sigle
Well, I got problem here with opengl ES stuff (just started to learn about
Well, this must be a silly one. Here below is a can-not-be-simpler code in
Well the problem is that I was using code like this: new Date().toJSON().slice(0, 10)
Well...I feel absolutely stupid. Here's why: I have been using some library functions I
Well this is my problem, Im trying to write a code in AppleScript in
well, I am trying to include a header file in my project, while the
Well, I was trying to fix this program, and I keep getting the errors
Well, I have to revive a question that was answered here before. I've made

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.