I am having trouble figuring out how to properly use the flags for the gfx_capabilities. Can someone show me how? i.e. How the flags are supposed to be used.
Note: I am using C++ and the Allegro Library (I know that last on should be obvious, but I never know.)
Thanks,
Dragonsoulj
This:
if((gfx_capabilities & GFX_CAN_TRIPLE_BUFFER) && (gfx_capabilities & GFX_HW_FILL)) { do_whatever(); }
Or:
if((gfx_capabilities & (GFX_CAN_TRIPLE_BUFFER | GFX_HW_FILL))) { do_whatever(); }
Each flag is determined by whether or not a certain bit is set in gfx_capabilities. To check if a certain bit is set you use the logical and (&) operator with the righthand operand being a number that has the bits set that you want.
The logical or (|) can be used to combine the bits of 2 numbers into 1. If you have a number that has the first two bits set and another with the third and fourth bits set and or them together you will get a number with the first four bits set.
Is there any way to set a bit yourself?
Is there any way to set a bit yourself?
You can set it, but it won't mean anything. This variable is only there to tell you what's actually available. You should treat it as if its read only.
Thanks. I think that clears it up. I will see if my code will work using them.
Note that Todd's two examples are not equivalent though.
Hmm, I can't see the difference.
Hmm, I can't see the difference.
The second is true if either flag is set, the first if both are set.
Would it be true if you do something like (gfx_capabilities & (GFX_CAN_TRIPLE_BUFFER | GFX_HW_FILL)) > 0?
No it would be true if the result was equal to the combination of both flags:
if ( gfx_capabilities & (GFX_CAN_TRIPLE_BUFFER | GFX_HW_FILL) == (GFX_CAN_TRIPLE_BUFFER | GFX_HW_FILL) ){ .. }
The second is true if either flag is set, the first if both are set.
Okay, I see now. Thanks.