| Spirrwell (9) | |
|
Sorry I couldn't think of a better title, but hopefully you'll understand. I've worked with the SDL library for quite some time and whenever you have to set the video mode, there are flags that that tell whether to go fullscreen, use OpenGL, or whatever such as SDL_OPENGL | SDL_FULLSCREEN. What I want to know is how would I break down these flags if I wanted to know if the Uint32 variable contained the flag for fullscreen or if it contained the flag for something else? | |
|
|
|
| EssGeEich (1007) | ||||
Let's take a look at it:
Enough? ^ Beware: You cannot use random values for SDL_OPENGL and SDL_FULLSCREEN and so on. They must be left-shifted of at least a bit from each other, like:
| ||||
|
Last edited on
|
||||
| Peter87 (3908) | |||||
You could also compare against 0 instead of the flag if you prefer.
or you could leave out the comparasion agains zero because that is the default integer to bool conversion anyway.
If you don't want to use a variable and just check it inside an if statement it would like like if ((Flags & SDL_OPENGL) == SDL_OPENGL), orif ((Flags & SDL_OPENGL) != 0), orif (Flags & SDL_OPENGL).EDIT: EssGeEich's way is better if you have combined flags with more than one bit set. const Uint32 OPENGL_AND_FULLSCREEN = SDL_OPENGL | SDL_FULLSCREEN;Now this would not work. bool IsOpenGLAndFullScreen = (Flags & OPENGL_AND_FULLSCREEN);IsOpenGLAndFullScreen would be set to true if at least one of the two flags are true. By using EssGeEich's way it would work correctly. bool IsOpenGLAndFullScreen = (Flags & OPENGL_AND_FULLSCREEN) == OPENGL_AND_FULLSCREEN;
| |||||
|
Last edited on
|
|||||
| Spirrwell (9) | |
|
Oh thank you that worked perfectly! SDL_OPENGL and SDL_FULLSCREEN aren't values I set, they're values set by the SDL library, but that's useful information if I wanted to do something like that. | |
|
|
|
| EssGeEich (1007) | |
|
Yeah, I told you in case you wanted to do your enumeration. Almost everyone uses this kind of enumeration for bitmasks, so it should work almost everywhere. Also feel free to use Peter87's code: It works almost the same, and it's shorter. | |
|
Last edited on
|
|