Format of glDrawPixels ignored for PBO


It seems that when using a PBO with glDrawPixels, the latter ignores the format that I specify. First, I create the PBO:

    glGenBuffersARB( 1, &PBO_ );
    glBufferDataARB( GL_PIXEL_UNPACK_BUFFER, 256*256*4*sizeof(GLubyte), NULL, GL_DYNAMIC_DRAW );

    GLubyte* t = (GLubyte*) glMapBufferARB( GL_PIXEL_UNPACK_BUFFER, GL_WRITE_ONLY );
    for ( int i=0; i<256*256; i++ ) {
        t[i*4+0] = i % 256;
        t[i*4+1] = 0;
        t[i*4+2] = i % 256;

I know that I’m not filling in every fourth byte, but that shouldn’t matter. Now, I draw like this:

    glDrawPixels( 256, 256, GL_RGBA, GL_UNSIGNED_BYTE, 0 );

This seems to give the expected result: A purple gradient. However, these two other calls result in the same purple gradient, which I don’t expect:

    glDrawPixels( 256, 256, GL_BGRA, GL_UNSIGNED_BYTE, 0 );
    glDrawPixels( 256, 256, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0 );

It is my understanding that, with GL_PIXEL_UNPACK_BUFFER, glDrawPixels looks into the PBO for its source data. I still expect it to treat that data as it normally does. Where did I go wrong?


Depth testing ? try to clear depth buffer before your second glDrawPixels call.

Depth testing? How would that affect the results? The depth is the same for all the calls; I only modified the format parameter of glDrawPixels.

Just in case I wasn’t clear: I only ran one glDrawPixels routine, but any of the three give the same result.