SDL_SetVideoMode -- Met en place un mode vidéo avec la largeur, hauteur, quantité de bit par pixel donnés.


#include "SDL.h"

SDL_Surface *SDL_SetVideoMode(int largeur, int hauteur, int quantitedebitparpixel, Uint32 flags);


Met en place un mode vidéo avec la largeur, hauteur et quantitedebitparpixel.

As of SDL 1.2.10, if width and height are both 0, it will use the width and height of the current video mode (or the desktop mode, if no mode has been set).

If bitsperpixel is 0, it is treated as the current display bits per pixel.

The flags parameter is the same as the flags field of the SDL_Surface structure. OR'd combinations of the following values are valid.


Create the video surface in system memory


Create the video surface in video memory


Enables the use of asynchronous updates of the display surface. This will usually slow down blitting on single CPU machines, but may provide a speed increase on SMP systems.


Normally, if a video surface of the requested bits-per-pixel (bpp) is not available, SDL will emulate one with a shadow surface. Passing SDL_ANYFORMAT prevents this and causes SDL to use the video surface, regardless of its pixel depth.


Give SDL exclusive palette access. Without this flag you may not always get the the colors you request with SDL_SetColors or SDL_SetPalette.


Enable hardware double buffering; only valid with SDL_HWSURFACE. Calling SDL_Flip will flip the buffers and update the screen. All drawing will take place on the surface that is not displayed at the moment. If double buffering could not be enabled then SDL_Flip will just perform a SDL_UpdateRect on the entire screen.


SDL will attempt to use a fullscreen mode. If a hardware resolution change is not possible (for whatever reason), the next higher resolution will be used and the display window centered on a black background.


Create an OpenGL rendering context. You should have previously set OpenGL video attributes with SDL_GL_SetAttribute. (IMPORTANT: Please see notes at the bottom of this page.)


Create an OpenGL rendering context, like above, but allow 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. NOTE: This option is kept for compatibility only, and will be removed in next versions. Is not recommended for new code.


Create a resizable window. When the window is resized by the user a SDL_VIDEORESIZE event is generated and SDL_SetVideoMode can be called again with the new size.


If possible, SDL_NOFRAME causes SDL to create a window with no title bar or frame decoration. Fullscreen modes automatically have this flag set.

Note: Whatever flags SDL_SetVideoMode could satisfy are set in the flags member of the returned surface.

Note: A bitsperpixel of 24 uses the packed representation of 3 bytes/pixel. For the more common 4 bytes/pixel mode, use a bitsperpixel of 32. Somewhat oddly, both 15 and 16 will request a 2 bytes/pixel mode, but different pixel formats.

Note: Use SDL_SWSURFACE if you plan on doing per-pixel manipulations, or blit surfaces with alpha channels, and require a high framerate. When you use hardware surfaces (SDL_HWSURFACE), SDL copies the surfaces from video memory to system memory when you lock them, and back when you unlock them. This can cause a major performance hit. (Be aware that you may request a hardware surface, but receive a software surface. Many platforms can only provide a hardware surface when using SDL_FULLSCREEN.) SDL_HWSURFACE is best used when the surfaces you'll be blitting can also be stored in video memory.

Note: If you want to control the position on the screen when creating a windowed surface, you may do so by setting the environment variables "SDL_VIDEO_CENTERED=center" or "SDL_VIDEO_WINDOW_POS=x,y". You can set them via SDL_putenv.

Return Value

The framebuffer surface, or NULL if it fails. The surface returned is freed by SDL_Quit and should not be freed by the caller. Note: This rule includes consecutive calls to SDL_SetVideoMode (i.e. resize or rez change) - the pre-existing surface will be released automatically.


You should have previously set OpenGL video attributes with SDL_GL_SetAttribute

Need to be clarified. Some have found that enabling OpenGL attributes before the video mode has been set causes the application to simply ignore those attributes, while enabling attributes after the video mode has been set works fine. Hopefully this will be clarified soon. Maybe a bad flags parameter : for OpenGL mode, use only SDL_OPENGL (and SDL_FULLSCREEN if needed) nothing else.

See Also

SDL_LockSurface, SDL_SetColors, SDL_Flip, SDL_Surface, SDL_envvars

SDLDoc-fr/SDL_SetVideoMode (last edited 2008-08-16 21:15:13 by SalokineTerata)