Domanda

Should be a simple question for SDL experts. I am confused about the following two seemingly equivalent functions and wondering when to use which

SDL_Surface * SDL_SetVideoMode (int width, int height, int bpp, Uint32 flags);
SDL_Surface * SDL_CreateRGBSurface (Uint32 flags,
        int width, int height, int depth,
        Uint32 Rmask, Uint32 Gmask, Uint32 Bmask, Uint32 Amask);

What's the fundamental difference between the above two?

It's mentioned here that SDL_CreateRGBSurface has to be called after SDL_SetVideoMode. Why is that so?

È stato utile?

Soluzione

SDL_SetVideoMode creates a window. This surface will be visible on the screen.

SDL_CreateRGBSurface creates off-screen image. SDL_CreateRGBSurface is used, for example, when you load images from disk. You need to blit it to the screen in order to see them.

Altri suggerimenti

They are completely different functions.

SDL_SetVideoMode creates the video surface (a.k.a. application screen) and show it to the user.

SDL_CreateRGBSurface creates an empty surface.

After calling SDL_SetVideoMode, if successful, a screen will be shown to the user and you will have (returned by the function, or by calling SDL_GetVideoSurface) the video surface, the screen surface.

SDL_CreateRGBSurface simply creates an empty surface that you can play with it.

Some usage example would be: your application starts and you initialize the video, then you create an empty surface and manipulate it somehow, and finally you blit it to the video surface and the user will see the surface that you manipulated (remember to flip the screen surface, SDL_Flip).

It's important to know what a SDL_Surface is. Since you don't asked I assume you know.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top