SDL_SetVideoMode(3)

🌸 NAME 🌸

SDL_SetVideoMode β€” bestie, this is the one that sets up your video mode with the width, height and bits-per-pixel you asked for. (It's from the SDL API Reference manual, section 3, iykyk.)


✨ SYNOPSIS ✨

#include "SDL.h"

SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);

πŸ’… DESCRIPTION πŸ’…

Okay so picture this: you wanna set up a video mode, and you've got a width, a height, and a bits-per-pixel, and this function is literally just that. That's the whole assignment. Slay.

Tiny lil plot twist tho: if bpp is 0, it gets treated as the current display bits per pixel. So zero is not "no pixels", it's "whatever we're already on". Periodt.

The flags parameter? Same energy as the flags field of the SDL_Surface structure. You can OR together combinations of these and they're all valid:

πŸŽ€ The Flags πŸŽ€

  • SDL_SWSURFACE β€” makes the video surface live in system memory.
  • SDL_HWSURFACE β€” makes the video surface live in video memory. Fancy.
  • SDL_ASYNCBLIT β€” turns on asynchronous updates of the display surface. Ngl this will usually slow down blitting on single CPU machines, but on SMP systems it may give you a speed boost. It's giving "depends on your setup".
  • SDL_ANYFORMAT β€” so normally, if a video surface with the bits-per-pixel (bpp) you requested isn't available, SDL will emulate one with a shadow surface. Passing SDL_ANYFORMAT stops that whole thing and makes SDL use the video surface anyway, regardless of its pixel depth. No shadow, no problem.
  • SDL_HWPALETTE β€” gives SDL exclusive palette access. Without this flag you may not always get the colors you request with SDL_SetColors or SDL_SetPalette. So if your colors are acting up... this is why bestie 😭
  • SDL_DOUBLEBUF β€” enables hardware double buffering, and it's only valid with SDL_HWSURFACE. Calling SDL_Flip will flip the buffers and update the screen. All your drawing takes place on the surface that isn't being displayed at the moment. If double buffering couldn't be enabled, then SDL_Flip just does an SDL_UpdateRect on the entire screen instead. It still works, it's just not the glowy version.
  • SDL_FULLSCREEN β€” SDL will attempt to use a fullscreen mode. If a hardware resolution change isn't possible (for whatever reason, we don't ask), the next higher resolution gets used and the display window is centered on a black background. Main character fullscreen energy.
  • SDL_OPENGL β€” creates an OpenGL rendering context. Heads up: you should have already set your OpenGL video attributes with SDL_GL_SetAttribute beforehand. Do your homework first πŸ’œ
  • SDL_OPENGLBLIT β€” creates an OpenGL rendering context like the one above, but it also allows normal blitting operations. The screen (2D) surface may have an alpha channel, and SDL_UpdateRects must be used for updating changes to the screen surface.
  • SDL_RESIZABLE β€” creates a resizable window. When the user resizes it, a SDL_VIDEORESIZE event gets generated, and you can call SDL_SetVideoMode again with the new size. Very "go with the flow" of you.
  • SDL_NOFRAME β€” if possible, SDL_NOFRAME makes SDL create a window with no title bar and no frame decoration. Fullscreen modes automatically have this flag set, no need to ask.
Note: whatever flags SDL_SetVideoMode could satisfy get set in the flags member of the returned surface. So like, check the receipt, not the request.
Note: the bpp parameter is the number of bits per pixel, so a bpp of 24 uses the packed representation of 3 bytes/pixel. For the more common 4 bytes/pixel mode, use a bpp of 32. And somewhat oddly β€” yes we're all side-eyeing it β€” both 15 and 16 will request a 2 bytes/pixel mode, but with different pixel formats. Not me being confused by that the first time πŸ™ˆ

πŸ‘‘ RETURN VALUE πŸ‘‘

You get the framebuffer surface, or NULL if it fails. That returned surface is freed by SDL_Quit() and should nt be freed by the caller β€” so hands off, bestie, do not free it yourself πŸ’€


πŸ”₯ SEE ALSO πŸ”₯

  • SDL_LockSurface
  • SDL_SetColors
  • SDL_Flip
  • SDL_Surface

And that's the whole page, fr fr πŸ¦‹ This was SDL, from the SDL API Reference, dated Tue 11 Sep 2001, 23:01. Go set up that video mode, you've got this πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from