NAME
SDL_SetVideoMode- Set up a video mode with the specified width, height and
bits-per-pixel.
SYNOPSIS
#include "SDL.h"
SDL_Surface *SDL_SetVideoMode(int width, int height, int bpp, Uint32 flags);
DESCRIPTION
Set up a video mode with the specified width, height and bits-per-pixel.
If bpp 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.
SDL_SWSURFACE
Create the video surface in system memory
SDL_HWSURFACE
Create the video surface in video memory
SDL_ASYNCBLIT
Enables the use of asynchronous to the display surface. This will usually slow
down blitting on single CPU machines, but may provide a speed increase on SMP
systems.
SDL_ANYFORMAT
Normally, if a video surface of the requested depth (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 depth.
SDL_HWPALETTE
Give SDL exclusive palette access. Without this flag you may not always get the
the colors you request with SDL_SetColors.
SDL_DOUBLEBUF
Enable double buffering; only valid with SDL_HWSURFACE. Calling SDL_Flip will
flip the buffers and update the screen. If double buffering could not be enabled
then SDL_Flip will just perform a SDL_UpdateRect on the entire screen.
SDL_FULLSCREEN
SDL will attempt to use a fullscreen mode
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.
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, 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.
RETURN VALUE
The framebuffer surface, or NULL if it fails.
SEE ALSO
SDL_LockSurface, SDL_SetColors, SDL_Flip, SDL_Surface
|
Now that SDL has been initialized for drawing graphics to the screen, the
program must setup a Window (or get a display buffer) to draw in. In SDL display
buffers are referred to as surfaces. Surfaces have several different uses - many
of which will be covered in later tutorials. For this tutorial, however, the SDL
"surface" will refer to a window.
SDL Surfaces are declared as a pointer to type SDL_Surface. In order to draw to
the screen, the program must first get a valid SDL_Surface using
SDL_SetVideoMode. SDL_SetVideoMode takes four parameters: the width of the
requested mode, the height, the bitdepth, and a set of flags(or options) about
the mode.
The following are options that may be passed to SDL_SetVideoMode:
SDL_SWSURFACE: Requests a software surface. Software surfaces are in system
memory, and are not generally as fast as hardware surfaces.
SDL_HWSURFACE: If possible, this surface will be stored video memory. Operations
to hardware surfaces can be much faster than software surfaces.
SDL_ANYFORMAT: This allows the creation of a surface in any depth format. The
bitdepth parameter is the then the preferred format.
SDL_HWPALETTE: Most of the time, you will be using true color visuals and will
not need to worry about the hardware palette. However, when using palettes, this
parameter requests that SDL have full control over the current hardware palette.
SDL_DOUBLEBUF: Create a doublbuffered surface. This option will be covered in a
later tutorial.
SDL_FULLSCREEN: Create a full screen visual. This will set the video mode to the
one request by the width and height parameters - and give your application
complete control over what the user sees. Most game software will use this
option.
SDL_OPENGL: Creates an OpenGL surface. To be covered in a later tutorail.
SDL_RESIZABLE: Creates a resizable window. To be covered in a later tutorial.
SDL_NOFRAME: Create a window with no frame. To be covered in a later tutorial.
Today, I am going to demonstrate using a simple Software surface that will
support any bit depth. This is created using the following code:
SDL_Surface* screen;
...
screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_ANYFORMAT);
if( !screen ) {
fprintf(stderr, "Couldn't create a surface: %s\\n",
SDL_GetError());
return -1;
}
This code will create a software SDL surface of width 640, height 480, and a
preferred bit depth of 16 bits per pixel. Note: It is generally a good idea to
check that SDL_SetVideoMode does indeed return a proper surface.
|