Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » GFX Capabilities

Credits go to Thomas Fjellstrom and Todd Cope for helping out!
This thread is locked; no one can reply to it. rss feed Print
GFX Capabilities
Dragonsoulj
Member #7,678
August 2006

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

Todd Cope
Member #998
November 2000
avatar

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.

Dragonsoulj
Member #7,678
August 2006

Is there any way to set a bit yourself?

Thomas Fjellstrom
Member #476
June 2000
avatar

Quote:

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.

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Dragonsoulj
Member #7,678
August 2006

Thanks. I think that clears it up. I will see if my code will work using them.

Peter Wang
Member #23
April 2000

Note that Todd's two examples are not equivalent though.

Todd Cope
Member #998
November 2000
avatar

Hmm, I can't see the difference.

Evert
Member #794
November 2000
avatar

Quote:

Hmm, I can't see the difference.

The second is true if either flag is set, the first if both are set.

Ron Ofir
Member #2,357
May 2002
avatar

Would it be true if you do something like (gfx_capabilities & (GFX_CAN_TRIPLE_BUFFER | GFX_HW_FILL)) > 0?

kazzmir
Member #1,786
December 2001
avatar

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) ){
  ..
}

Todd Cope
Member #998
November 2000
avatar

Quote:

The second is true if either flag is set, the first if both are set.

Okay, I see now. Thanks.

Go to: