CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Nov 2005
    Posts
    102

    read pixels from back buffer

    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:
    Code:
    	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 when i don't use a glut window to render too...
    		glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
    
    	}
    Then in my render function i do:

    Code:
    void DisplayFunc(void)
    {
      static float alpha = 0;
    
      /* 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);
    }
    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.

    Anyone any idea what i'm doing wrong...??
    Last edited by vivendi; January 21st, 2012 at 07:53 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured