I' working on some OpenGl tutorials using Glut and I come across
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
I understand what it does but what I don't understand is how it does it?
Looking at the definitions :
GLUT_DOUBLE 0x0002
GLUT_RGB 0x0000
GLUT_DEPTH 0x0010
and I can see that there is a OR bit wise operation in the functions' arguments.
How does this bitwise operation work on the macros above ? What are the values that they represent, physical address from the memory?
Right now I'm just displaying some shapes that rotate in a 400x400 px window, and disabling any of that arguments did not seem to have any visual effect.
Thanks!
Two of those constants, GLUT_DOUBLE
and GLUT_DEPTH
, each contain one set bit:
GLUT_DOUBLE = 0x0002 = 0b0000 0000 0000 0010
GLUT_DEPTH = 0x0010 = 0b0000 0000 0001 0000
Combining those constants with a bitwise OR creates a new value with both of those bits set, and it's possible to check whether those bits are set in the resulting value using e.g.
if ((display_mode & GLUT_DOUBLE) != 0) { ... }
GLUT_RGB
is zero. Including it has no effect on the result; I suspect it represents a setting that is true by default.
The specific numbers used don't have any deeper significance. They're just used as a way of combining a bunch of on/off options in a single integer argument.