C++ SDL What does the | do?

后端 未结 4 1983
無奈伤痛
無奈伤痛 2021-01-24 13:37
screen = SDL_SetVideoMode(1000,1000,32, SDL_HWSURFACE | SDL_FULLSCREEN);

What does the | do in SDL_HWSURFACE | SDL_FULLSCREEN

4条回答
  •  没有蜡笔的小新
    2021-01-24 13:54

    The other answers have explained it's a bitwise OR, but you probably want to know how that works:

    The flags are passed as a binary number, like 00001000 or 01000000, and each bit represents an individual flag. So the first bit (0) means HW_SURFACE is off, and the second bit (1) means FULLSCREEN is on. (Note that these are examples, I'm not sure about the actual bits.)

    So what the bitwise OR function does is combine those two flags by comparing each bit and saying "Is this bit OR this bit 1?" and if either is 1, it will set the result to 1. This will provide the result 01001000 which can be parsed by SDL to set the appropriate flags.

提交回复
热议问题