Issue reading OpenGL double buffer on Harmattan device



  • While implementing color based picking (http://www.lighthouse3d.com/opengl/picking/index.php3?color1) I ran across a difference between the device and desktop environment when reading colors from the double buffer. Whenever I read a pixel from the double buffer on the device I get a 0,0,0 color (= my fill color). It works properly on the desktop with the same code. Any ideas?

    The device in question is N9. The app is a QGLWidget based one with the following setup:

    @
    setAutoFillBackground(false);
    setAttribute(Qt::WA_OpaquePaintEvent);
    setAttribute(Qt::WA_NoSystemBackground);
    setAttribute(Qt::WA_NativeWindow);
    setAttribute(Qt::WA_PaintOnScreen, true);
    setAttribute(Qt::WA_StyledBackground,false);
    setAutoBufferSwap(false);

    glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_CULL_FACE);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glClearColor(0, 0, 0, 0);
    glClearStencil(0);
    glDepthFunc(GL_LEQUAL);
    

    @

    Reading the pixel data is done as follows:

    @
    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT, viewport);

    // OpenGL handles y coordinated inverted; calculate it from viewport info
    int invertedY = viewport[3] - y;
    
    // read the 3-byte RGB pixel
    GLubyte pixel[3];
    glReadPixels(x, invertedY, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)pixel);
    

    @

    Cheers,

    • Matti


  • Okay a bit of a RTFM issue on my part, glReadPixels() format should have been GL_RGBA .. but another issue remains, the pixel data read back does not match what was written: I render an object with color 255,255,192 and when I read a pixel back it becomes 255,255,198? Isn't the buffer natively 32bit color or how come this change in the color? Going to have to do some precicion downshifting I guess to distinguish my pick colors..



  • In OpenGL you have no control over how the actual implementation deals with colors. The vendor may have made some tweaks in their drivers to gain some performance on their specific hardware, especially on embedded devices.
    The internal color representation might not be full precision 32 bits RGBA and your read back can therefore be slightly off. There are some GL extensions (on the desktop) that allow you to require a full precision 32 bits buffer but I am not sure that this is available with OpenGL ES.



  • Right, suspected something like this. Well, I'm going to shift things down to 5-bit precision, that should do it while still giving plenty of pick color choices.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.