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 7128637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:09:33+00:00 2026-05-28T11:09:33+00:00

I want to read the pixels from the back buffer. But all i get

  • 0

I want to read the pixels from the back buffer. But all i get so far is a black screen (the clear color).

The thing is, is that i don’t need a glut window to draw to. Once i have the pixel information, then i pass that to another program which will draw the image for me.

My init function looks like this:

// No main function, so no real argv argc
char fakeParam[] = "nothing"; 
char *fakeargv[] = { fakeParam, NULL }; 
int fakeargc = 1; 

glutInit( &fakeargc, fakeargv );
GLenum err = glewInit();

if (GLEW_OK != err)
{
    MessageBoxA(NULL, "Failed to initialize OpenGL", "ERROR", NULL);
}
else
{
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);

    // Not sure if this call is needed since i don't use a glut window to render too..
    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);

}

Then in my render function i do:

void DisplayFunc(void)
{
  /* Clear the buffer, clear the matrix */
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  // TEAPOT
  glTranslatef(0.0f, 0.0f, -5.0f); // Translate back 5 units
  glRotatef(rotation_degree, 1.0f, 1.0f, 0.0f); // Rotate according to our rotation_degree value

  glFrontFace(GL_CW);
  glutSolidTeapot(1.0f); // Render a teapot
  glFrontFace(GL_CCW);

  glReadBuffer(GL_BACK);
  glReadPixels(0, 0, (GLsizei)1024, (GLsizei)768, GL_RGB, GL_UNSIGNED_BYTE, pixels);

  int r = glGetError();
}

This is basically all i do. At the end of the last function is where i’m trying to read all the pixels. But the output is just a black image. glGetError() doesn’t give any errors.

Anyone any idea what the problem could be…???

  • 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-28T11:09:34+00:00Added an answer on May 28, 2026 at 11:09 am

    I want to read the pixels from the back buffer. But all i get so far is a black screen (the clear color).

    The thing is, is that i don’t need a glut window to draw to. Once i have the pixel information, then i pass that to another program which will draw the image for me.

    It doesn’t work like that. The backbuffer is not some kind of off-screen rendering area, it’s part of on-screen window. Actually the whole doublebuffer concept only makes sense for on-screen windows. Each pixel of a double buffered window has two color values, but only one depth, stencil, etc.; upon buffer swap just the pointer to the back and front pixel plane are exchanged. But because we’re still talking about a window, when rasterizing all fragments go through the pixel ownership test, i.e. are checked for, if they are actually visible on screen. If not, they’re not rendered.

    But your problems go further: You don’t even create a window, so you don’t have an OpenGL context at all. Your calling of OpenGL commands has no effect whatsoever. glReadPixels doesn’t return you anything, because there’s nothing to read from.

    The bad news is, that the only way to get a context with GLUT is, by creating a window. The good news is, you don’t have to use GLUT. People, why don’t you get this: GLUT is not part of OpenGL, it’s a quick and dirty framework for writing small tutorials, nothing more.

    What you want is either:

    • not a window, but a PBuffer, i.e. a off screen drawable, that doesn’t got through pixel ownership tests.

    or

    • A hidden window with a OpenGL context created on it, and in this context a Frame Buffer Object for an off-screen rendering target.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to read pixels from an off-screen (not backed by a CAEAGLLayer) Framebuffer.
I want to read line n1->n2 from file foo.c into the current buffer. I
I want to read a rectangular area, or whole screen pixels. As if screenshot
I have a text file. I want read that file. But In that if
I want to read the contents of a URL but don't want to hang
I want to read all items of a feed in C#. The solutions I've
I want to read and write from serial using events/interrupts. Currently, I have it
I want to read UTF-8 input in Perl, no matter if it comes from
I want to read each line from a text file and store them in
please help me. I want to print some reports from .NET app. I read

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.