Q:

Opengl glubyte array to integer value

I've got RGB values stored in a GLubyte array of size 3 and wondering how can I represent the RGB color values as a single integer, so what i want is to combine all 3 values to create an integer representation of the color, can someone explain how to do this?

A:

You can use bit shifts to produce the integer:
GLuint get_number(GLubyte const* ptr) {
    // magic numbers for shift sizes are safe because GL types have fixed sizes
    // (8 for GLubyte and 32 for GLuint)
    return ptr[0] << 16 + ptr[1] << 8 + ptr[2];
}

And to fill an array back you can use bitmasks:
void get_bytes(GLuint number, GLubyte* out) {
    out[0] = (number & 0xFF0000) >> 16;
    out[1] = (number & 0x00FF00) >> 8;
    out[2] = number & 0x0000FF;
}

