1

I'm currently using colour picking in my application. This works on the PC, however I'm having trouble to get it working on a variety of devices.

This is probably due to the context being set up differently, depending on the device. For example, as far as I'm aware the PC is set to a colour of 888, whereas a device might default to 565.

I was wondering if there's a way in OpenGL to get the current pixel/colour format, so that I can retrieve the colour data properly?

This is the function I'm using which works fine on the PC:

inline void ProcessColourPick(GLubyte *out, KDfloat32 x, KDfloat32 y)
{
    GLint viewport[4];
    GLubyte pixel[3];

    glGetIntegerv(GL_VIEWPORT,viewport);

    //Read colour of pixel at a specific point in the framebuffer

    glReadPixels(x,viewport[3]-y,1,1,
        GL_RGB,GL_UNSIGNED_BYTE,(void *)pixel);

    out[0] = pixel[0];
    out[1] = pixel[1];
    out[2] = pixel[2];
}

Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ben
  • 84
  • 1
  • 7

2 Answers2

1

Yes, but it's a bit complicated.

Querying the bitdepth of the current framebuffer is fairly easy in ES 2.0 (note: this is also legal in Desktop GL, but this functionality was removed in GL 3.1 core. It's still accessible from a compatibility profile). You have to get the bitdepth of each color component:

GLint bitdepth; glGetIntegerv(GL_x_DEPTH, &bitdepth);

Where x is one of RED, GREEN, BLUE, or ALPHA.

Once you have the bitdepth, you can test to see if it's 565 and use appropriate pixel transfer parameters and color values.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
0

The format parameter for glReadPixels must be either GL_RGBA (always supported) or the GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES (different on different devices). It's a OpenGL ES restriction.

qehgt
  • 2,972
  • 1
  • 22
  • 36