DRAFT


For Backward Compatibility Only

SDL_SetVideoMode

Use this compatibility function to create a window and get a surface from it.

Syntax

SDL_Surface* SDL_SetVideoMode(int    width,
                              int    height,
                              int    bitsperpixel,
                              Uint32 flags)

Function Parameters

width

the desired width of the window, in pixels

height

the desired height of the window, in pixels

bitsperpixel

the desired bits per pixel of the returned surface; see Remarks for details

flags

see Remarks for details

Return Value

Returns a surface associated with the window or NULL on failure; call SDL_GetError() for more information.

Code Examples

#include <iostream>
#include "SDL.h"

// Initialize SDL and the video subsystem
SDL_Init(SDL_INIT_VIDEO);

// Set the video mode
SDL_Surface* myVideoSurface = SDL_SetVideoMode(640, 480, 16, SDL_FULLSCREEN);

// Print out some information about the video surface
if (myVideoSurface != NULL) {
    std::cout << "The current video surface bits per pixel is " << (int)myVideoSurface->format->BitsPerPixel << std::endl;
}
else {
    std::cerr << "Video initialization failed: " << SDL_GetError() << std::endl;
}

// Shut down the SDL and all its subsystems
SDL_Quit();

You can add your code example here

Remarks

This function enables the SDL 1.2 compatibility functions.

See SDL_CreateWindow() and SDL_GetWindowSurface() in SDL 1.3 for similar functionality.

As of SDL 1.2.10, if width and height are both 0, SDL_SetVideoMode() 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. A bitsperpixel of 24 uses the packed representation of 3 bytes per pixel. For the more common 4 bytes per pixel mode, please use a bitsperpixel of 32. Somewhat oddly, both 15 and 16 bits per pixel modes will request a 2 bytes per pixel mode, but with different pixel formats.

flags may be any of the following OR'd together:

SDL_ANYFORMAT

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.

SDL_HWPALETTE

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

SDL_FULLSCREEN

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.

SDL_OPENGL

Create an OpenGL rendering context. You should have previously set OpenGL video attributes with SDL_GL_SetAttribute().

SDL_OPENGLBLIT

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.

SDL_RESIZABLE

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.

SDL_NOFRAME

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

There are more listed in the compat header. Should any others be included here?

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 also set them via SDL_putenv().

This function should be called in the main thread of your application.

Some have found that enabling OpenGL attributes like SDL_GL_STENCIL_SIZE (the stencil buffer size) 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.

Also note that, in Windows, setting the video mode resets the current OpenGL context. You must execute again the OpenGL initialization code (set the clear color or the shade model, or reload textures, for example) after calling SDL_SetVideoMode(). In Linux, however, it works fine, and the initialization code only needs to be executed after the first call to SDL_SetVideoMode() (although there is no harm in executing the initialization code after each call to SDL_SetVideoMode(), for example for a multiplatform application).

SDL 1.3 Replacement(s)

This function has been replaced by the following in SDL 1.3: SDL_CreateWindow, SDL_GetWindowSurface


CategoryAPI, CategoryCompat

SDL_SetVideoMode (last edited 2011-11-13 19:40:49 by SheenaSmith)

Feedback
Please include your contact information if you'd like to receive a reply.
Submit