SDL 功能函数(一)

Function    PrepNuke(kilotons, target)
Synopsis    Sets up a tactical nuke and aims it at target.
Parameters    kilotons-Power rating of the desired nuke.
        target-Target of the nuke. 0 picks a random
        destination. Be carefull!

Function    SDL_Init(flags)
Synopsis    Initializes one or more subsystems of SDL.
Returns        Zero on success, a negative number on failure.
Parameters    flags-Subsystems to initialize. This is an ORed list
        of flags. Possible flags are SDL_INIT_VIDEO and
        SDL_INIT_AUDIO, among others.


Function    SDL_SetVideoMode(width, height, bpp, flags)
Synopsis    Creates a window or initalizes the video adapter to
        prepare for SDL video output.
Returns        Pointer to a valid SDL_Surface structure on success,
        NULL on failure.
Parameters    width-Width(x-resolution) of the desired video mode.
        height-Height(y-resolution) of the desired video mode.
        bpp-Desired color depth. Likely values are 8,15,16,24
        or 32. 0 lets SDL pick any supported mode.
        flags-Mode flags.Possible values are
        SDL_FULLSCREEN(requests a fullscreen video mode),
        SDL_DOUBLEBUF(requests a double buffered video setup),
        SDL_HWSURFACE(requests a hardware framebuffer for fast
        updates),
        SDL_OPENGL(requests an OpenGL context), and others.


Function    SDL_Quit()
Synopsis    Shuts down SDL cleanly, regardless of its present state.


Function    SDL_QuitSubSystem()
Synopsis    Shuts down a particular component of SDL, leaving the
        other untouched. It is safe to shut a subsystem down
        twice; SDL keeps track of its state internally.
Parameters    flags-ORed bitmask of subsystems to shut down.
        These are the same flags you would pass to SDL_Init.
        To shut down the audio subsystem without touching
        the video subsystem, you would use SDL_QuitSubSystem(
        SDL_INIT_AUDIO).

Function    SDL_Surface
Synopsis    Represents a video surface.
Members        flags-ORed bitmask of surface flags. For instance,
        the SDL_HWSURFACE bit of flags will be set if this is
        a hardware (video memory) surface. Read-only.
        format-Pointer to this surface's pixel format information
        (a SDL_PixelFormat structure).
        Read-only.
        w-Width of this surface (in pixels). Read-only.
        h-Height of this surface (in pixels). Read-only.
        pitch-Number of pixel per scanline in memory. This
        is often different from the surface's width - beware!
        Always use pitch for pixel offset calculations.
        Read-only.
        pixels-void pointer to the actual data that makes up
        this image. Read-write only after you call SDL_LockSurface.


Function    SDL_LockSurface(surf)
Synopsis    "Locks" a surface, making its pixel available for direct
        access. You can use SDL_MUSTLOCK(surf) to determine wheter a
        particular surface requires locking;
        some surfaces don't, Do not call DSL_BlitSurface on a locked
        surface.
Returns        Non-NULL on success, NULL on failure.
Parameters     surf-Surface to lock.



Function    SDL_UnlockSurface(surf)
Synopsis    "Unlocks" a surface. Use this as soon as you have finished
        drawing on a locked surface.
Parameter    surf-Surface to unlock


Struct        SDL_PixelFormat
Synpsis        Contains information about a surface's pixel composition.
Members        palette-Pointer to this surface's palette(of type
        SDL_Palette, if this is a paletted image.
        BitsPerPixel-Color depth of this surface. Possible
        values are 8,15,16,24, or 32.
        BytesPerPixel-Number of bytes needed for each pixel.
        This is usually BitPerPixel /8, rounded up to the
        nearest integer.
        Rloss—Number of bits to remove from an 8-bit red
        color value in order for it to fit in the allotted space.
        For instance, a 565 video mode allows for 5 bits of red
        color data, so the Rloss would be 3. SDL PixelFormat
        also contains Gloss, Bloss, and Aloss members for
        the green, blue, and alpha channels.
        Rshift—Number of bits to shift the red value in order
        to position it in the correct bit field. There are similar
        Gshift, Bshift, and Ashift members.
        Rmask—Bitmask for extracting the red component
        from a pixel value. There are similar Gmask, Bmask,
        and Amask members.
        colorkey—Color value for colorkey blitting. Set this
        with SDL SetColorKey. More on colorkey blitting
        later.
        alpha—Transparency value for the surface associated
        with this SDL PixelFormat structure. Set this with
        SDL SetAlpha. More on alpha blitting later.

Funciton    SDL_UpdateRect(surface, left, top, right, bottom)
Synopsis    Updates specific region of a surface. Normally used to
        make changes appear on the screen(see text above).
Parameters    surface-Surface to update. Usually the screen.
        left-Starting x coordinate of the region to update.
        If all coordinates are zero, SDL_UpdateRect will update
        the entire surface.
        top-Starting y coordinate of the region to update.
        right-Ending x coordinate of the region to update.
        bottom-Ending y coordinate of the region to update.


Function    SDL_LoadBMP(filename)
Synopsis    Loads a.bmp image file from disk into an SDL surface.
Returns        Pointer to a newly allocated SDL_Surface containing
        the loaded image.
Parameters    filename-Name of the bitmap file to load.


Function    SDL_BlitSurface(src, srcect, dest, destrect)
Synopsis    Blits all or part of one surface(the source) onto
        another (the destination).
Parameters    src-Source surface. Pointer to a valid SDL_Surface
        structure.
        srcect-Region of the source surface to copy. This
        is a pinter to an SDL_Rect structure. If this is NULL,
        SDL will try to copy the entire surface.
        dest-Destination surface.
        destrect-Region of the destionation surface to
        replace with the source surface. The width and height
        of the destionation surface don't matter; SDL only
        cares about the s and y coordinates.


Struture    SDL_Rect
Synopsis    Specifies regions of pixels. Used for clipping and blitting.
Members     x-starting x corrdinate.
        y-starting y corrdinate.
        w-width of the region, in pixels.
        h-height of the region, in pixels.


Function    SDL_SetColorKey(surface, flags, colorkey)
Synopsis    Adjusts the colorkey information ofr an SDL_Surface.
Parameters    surface-Surfce to modity.
        flags-ORed bitmask of colorkey flags.
        SDL_SRCCOLORKEY enables colorkey blitting for this
        surface. SDL_RLEACCEL enables run-length
        acceleration, which can speed up colorkey operations
        (but can alse slow down SDL_LockSurface significatly).
        colorkey-If SDL_SRCCOLORKEY is set, this specifies the
        pixel value to use as colorkey.


Function    SDL_SetAlpha(surface, flags, alpha)
Synopsis    Enables alpha blending on a particular surface.
Parameters    surface-The surface to modify.
        flags-ORed list of alpha blending flags.
        SDL_SRCALPHA enable alpha blending, and
        SDL_RLEACCEL enable RLE acceleration (with the
        same ramifications described under SDL_SetColorKey).
        alpha-Perj-surface alpha value. 255 represents complete
        opacity, and 0 represents complete transparency.

来自programming linux games

中文的在ubuntu论坛上见到过一些

#include #include //用键盘控制精灵移动 int main(int argc, char ** argv) { SDL_Surface * screen; //主表面 SDL_Surface * image; //用来放MM-----的图片信息(像素) SDL_Surface * PlayerImage; //用来测试的图片 SDL_Event event; Uint32 BeginTicks, EndTicks; SDL_Rect PRect, BRect; //PRect对应精灵的移动的小图位置(实现动画),BRect对应精灵在屏幕的位置。 unsigned char PlayerStarts = 0; unsigned char PlayerIndex = 0; bool bAppRun = true; //初始化SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { fprintf(stderr, "SDL_Init %s\n", SDL_GetError()); return -1; } //初始化成功设置退出要调用的函数SDL_Quit atexit(SDL_Quit); //创建一个640X480 16-bit 模式的主表面 16位可以让MM的效果好看一点 screen = SDL_SetVideoMode(230, 230, 16, SDL_SWSURFACE); if (screen == NULL) { fprintf(stderr, "Couldn't set 640x480x8 video mode %s\n", SDL_GetError()); return -1; } //读取MM图片信息,并创建一个表面,并把数据填入该表面中。 image = SDL_LoadBMP("./mm.bmp"); //请在终端里运行该程序 if (image == NULL) { fprintf(stderr, "Couldn't load MM, %s\n", SDL_GetError()); //遗憾你不能显示MM了,不过你可以用图片浏览程序看。 return -1; } //读取player.bmp PlayerImage = SDL_LoadBMP("./player.bmp"); //请在终端里运行该程序 if (image == NULL) { fprintf(stderr, "Couldn't load MM, %s\n", SDL_GetError()); //遗憾你不能显示MM了,不过你可以用图片浏览程序看。 return -1; } //读取第一个像素 Uint8 key = *((Uint8 *)PlayerImage->pixels); //设置色键 SDL_SetColorKey(PlayerImage, SDL_SRCCOLORKEY, key); //有了MM的表面了,就可以显示了。 //将MM的表面画在我们的主表面上,用MM来作为背景 if (SDL_BlitSurface(image, NULL, screen, NULL) < 0) { //解释一下NULL,第一个是按照image的尺寸显示,第二个是默认显示。你也可以指定大小,不过要用到SDL_Rect你可以看一看帮助。 fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError()); //看看提示吧 return -1; } PRect.x = 0; //初始化动画显示的图片。 PRect.y = 0; PRect.w = 32; PRect.h = 48; BRect.x = 0; //初始化精灵的位置。 BRect.y = 0; BRect.w = 32; BRect.h = 48; //贴上测试用的表面 if (SDL_BlitSurface(PlayerImage, &PRect, screen, &BRect) w, image->h); BeginT
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值