Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: readPixels then drawPixels fails, why?

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2000
    Location
    Tracy, California
    Posts
    6

    readPixels then drawPixels fails, why?

    Hi, I am trying to capture the contents of a window and then draw them back to the same window. Later, it will not necessarily be the same frame buffer to which i write, but before I get there, I need to know why the following doesn't work. Can anyone comment on it? Before the code executes, there is a glut window up with a pretty image on it. At the end of this snippet, the screen is black. (I put in a glClear() to see if I was redrawing correctly). Any help would be hugely appreciated. I hope this isn't too simple a question for this forum. Sorry for so much code, but I wanted the whole picture to be give if possible. The window is indeed of type RGB.


    GLint blend_enabled;
    GLint depth_enabled;
    GLint fog_enabled;
    GLint texture2d_enabled;
    GLint texture1d_enabled;
    GLint saved_matrix_mode;

    screenPixels = (GLubyte*)
    malloc(4 * glutGet(GLUT_WINDOW_WIDTH) *
    glutGet(GLUT_WINDOW_HEIGHT) *
    sizeof(GLfloat));

    glReadBuffer(GL_FRONT);
    printf("readPixels begun\n");
    glReadPixels(0,0,glutGet(GLUT_WINDOW_WIDTH),
    glutGet(GLUT_WINDOW_HEIGHT), GL_RGBA, GL_UNSIGNED_BYTE,
    screenPixels);
    printf("readPixels finished\n");

    /* this is to speed up a bit*/
    if(blend_enabled = glIsEnabled(GL_BLEND))
    glDisable(GL_BLEND);
    if(depth_enabled = glIsEnabled(GL_DEPTH_TEST))
    glDisable(GL_DEPTH_TEST);
    if(fog_enabled = glIsEnabled(GL_FOG))
    glDisable(GL_FOG);
    if(texture2d_enabled = glIsEnabled(GL_TEXTURE_2D))
    glDisable(GL_TEXTURE_2D);
    if(texture1d_enabled = glIsEnabled(GL_TEXTURE_1D))
    glDisable(GL_TEXTURE_1D);

    glGetIntegerv(GL_MATRIX_MODE, &saved_matrix_mode);
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluOrtho2D(0.0, (GLfloat) glutGet(GLUT_WINDOW_WIDTH),
    0.0, (GLfloat) glutGet(GLUT_WINDOW_HEIGHT));
    glRasterPos2i(0, 0);

    glDrawBuffer(GL_FRONT);
    printf("drawPixels begun\n");
    glClear(GL_COLOR_BUFFER_BIT);
    glDrawPixels(glutGet(GLUT_WINDOW_WIDTH),
    glutGet(GLUT_WINDOW_HEIGHT), GL_RGBA, GL_UNSIGNED_BYTE,
    screenPixels);
    printf("drawPixels finished\n");

    free(screenPixels);

    glPopMatrix();
    glMatrixMode(saved_matrix_mode);

    if(depth_enabled)
    glEnable(GL_DEPTH_TEST);
    if(fog_enabled)
    glEnable(GL_FOG);
    if(texture2d_enabled)
    glEnable(GL_TEXTURE_2D);
    if(texture1d_enabled)
    glEnable(GL_TEXTURE_1D);
    my views are not my employers all the time

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jul 2000
    Location
    Nice, France
    Posts
    222

    Re: readPixels then drawPixels fails, why?

    Look at your mail chef !

Posting Permissions

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