3. 上层API和底层代码的联系
3.1). General
SDL_Init -- Initializes SDL
SDL_InitSubSystem -- Initialize subsystems
SDL_QuitSubSystem -- Shut down a subsystem
SDL_Quit -- Shut down SDL
SDL_WasInit -- Check which subsystems are initialized
SDL_GetError -- Get SDL error string
SDL_envvars -- SDL environment variables
3.2). Video
3类操作:
1). 矩形填充[简单,没什么好说的]
2). 像素操作
基本过程:
a). 侦测Surface是否锁住
b). 锁住Surface
注意锁的过程是可递归的,因此,锁和解锁需要严格匹配
c). 操作像素数据
下一行的计算方式: y * pitch + x
d). 解锁Surface
3). Blit
int SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect);
a). srcrect中的w,h决定矩形大小,dstrect决定拷贝的坐标,其中w,h被忽视掉
b). srcrect为NULL代表源Surface全部拷贝,而dstrect为NULL代表目的坐标为(0,0)
c). 不能在锁住的Surface调用blit
d). The final blit rectangle is saved in dstrect after all clipping is performed (srcrect is not modified).
e). SDL_SRCAPLHA/SDL_SRCCOLORKEY对该函数的影响:
if (source surface has SDL_SRCALPHA set) {
if (source surface has alpha channel (that is, format->Amask != 0))
blit using per-pixel alpha, ignoring any colour key
else {
if (source surface has SDL_SRCCOLORKEY set)
blit using the colour key AND the per-surface alpha value
else
blit using the per-surface alpha value
}
} else {
if (source surface has SDL_SRCCOLORKEY set)
blit using the colour key
else
ordinary opaque rectangular blit
}
更新与显示,有2种方式:
1). 直接矩形更新显示
a). void SDL_UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h);
b). void SDL_UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects);
2). 双缓冲
a). int SDL_Flip(SDL_Surface *screen);
只能在支持SDL_DOUBLEBUF的情况使用,在vertical retrace时候交换video buffer
alpha混合,2种方式:
1). per-surface混合
2). per-pixel混合
在Blit时,a混合的具体行为:
a). RGBA->RGB with SDL_SRCALPHA
使用源Surface的a通道,忽略SDL_SRCCOLORKEY和per-surface alpha
b). RGBA->RGB without SDL_SRCALPHA
直接拷贝源Surface的RGB,忽略source alpha channel and the per-surface alpha
c). RGB->RGBA with SDL_SRCALPHA
使用per-surface alpha,如果存在SDL_SRCCOLORKEY,仅不是该color key的颜色被拷贝,a通道的像素被当成不透明处理
d). RGB->RGBA without SDL_SRCALPHA
RGB直接覆盖,如果存在SDL_SRCCOLORKEY,仅不是该color key的颜色被拷贝
e). RGBA->RGBA with SDL_SRCALPHA
使用源Surface的a值混合,目的Surface的a值不作改变,且SDL_SRCCOLORKEY被忽视
f). RGBA->RGBA without SDL_SRCALPHA
直接copy源Surface的RGBA,如果存在SDL_SRCCOLORKEY,则只有不是color key的值被拷贝
g). RGB->RGB with SDL_SRCALPHA
使用per-surface alpha,如果存在SDL_SRCCOLORKEY,仅不是该color key的颜色被拷贝
h). RGB->RGB without SDL_SRCALPHA
RGB直接覆盖,如果存在SDL_SRCCOLORKEY,则只有不是color key的值被拷贝
Note: Note that RGBA->RGBA blits (with SDL_SRCALPHA set) keep the alpha of the destination surface. This means that you cannot compose two arbitrary RGBA surfaces this way and get the result you would expect from "overlaying" them; the destination alpha will work as a mask.
per-pixel优先于per-surface
SDL_GetVideoSurface -- returns a pointer to the current display surface
SDL_GetVideoInfo -- returns a pointer to information about the video hardware
SDL_VideoDriverName -- Obtain the name of the video driver
SDL_ListModes -- Returns a pointer to an array of available screen dimensions for the given format and video flags
SDL_VideoModeOK -- Check to see if a particular video mode is supported.
SDL_SetVideoMode -- Set up a video mode with the specified width, height and bits-per-pixel.
SDL_UpdateRect -- Makes sure the given area is updated on the given screen.
SDL_UpdateRects -- Makes sure the given list of rectangles is updated on the given screen.
SDL_Flip -- Swaps screen buffers
SDL_SetColors -- Sets a portion of the colormap for the given 8-bit surface.
SDL_SetPalette -- Sets the colors in the palette of an 8-bit surface.
SDL_SetGamma -- Sets the color gamma function for the display
SDL_GetGammaRamp -- Gets the color gamma lookup tables for the display
SDL_SetGammaRamp -- Sets the color gamma lookup tables for the display
SDL_MapRGB -- Map a RGB color value to a pixel format.
SDL_MapRGBA -- Map a RGBA color value to a pixel format.
SDL_GetRGB -- Get RGB values from a pixel in the specified pixel format.
SDL_GetRGBA -- Get RGBA values from a pixel in the specified pixel format.
SDL_CreateRGBSurface -- Create an empty SDL_Surface
SDL_CreateRGBSurfaceFrom -- Create an SDL_Surface from pixel data
SDL_FreeSurface -- Frees (deletes) a SDL_Surface
SDL_LockSurface -- Lock a surface for directly access.
SDL_UnlockSurface -- Unlocks a previously locked surface.
SDL_LoadBMP -- Load a Windows BMP file into an SDL_Surface.
SDL_SaveBMP -- Save an SDL_Surface as a Windows BMP file.
SDL_SetColorKey -- Sets the color key (transparent pixel) in a blittable surface and RLE acceleration.
如果设置了ColorKey,在Blit时,碰到该颜色则不做任何copy,即当作透明色
SDL_SetAlpha -- Adjust the alpha properties of a surface
SDL_SetClipRect -- Sets the clipping rectangle for a surface.
设置剪切矩形
SDL_GetClipRect -- Gets the clipping rectangle for a surface.
SDL_ConvertSurface -- Converts a surface to the same format as another surface.
SDL_BlitSurface -- This performs a fast blit from the source surface to the destination surface.
SDL_FillRect -- This function performs a fast fill of the given rectangle with some color
SDL_DisplayFormat -- Convert a surface to the display format
SDL_DisplayFormatAlpha -- Convert a surface to the display format
SDL_WarpMouse -- Set the position of the mouse cursor.
SDL_CreateCursor -- Creates a new mouse cursor.
SDL_FreeCursor -- Frees a cursor created with SDL_CreateCursor.
SDL_SetCursor -- Set the currently active mouse cursor.
SDL_GetCursor -- Get the currently active mouse cursor.
SDL_ShowCursor -- Toggle whether or not the cursor is shown on the screen.
SDL_GL_LoadLibrary -- Specify an OpenGL library
SDL_GL_GetProcAddress -- Get the address of a GL function
SDL_GL_GetAttribute -- Get the value of a special SDL/OpenGL attribute
SDL_GL_SetAttribute -- Set a special SDL/OpenGL attribute
SDL_GL_SwapBuffers -- Swap OpenGL framebuffers/Update Display
SDL_CreateYUVOverlay -- Create a YUV video overlay
SDL_LockYUVOverlay -- Lock an overlay
SDL_UnlockYUVOverlay -- Unlock an overlay
SDL_DisplayYUVOverlay -- Blit the overlay to the display
SDL_FreeYUVOverlay -- Free a YUV video overlay
SDL_GLattr -- SDL GL Attributes
SDL_Rect -- Defines a rectangular area
SDL_Color -- Format independent color description
SDL_Palette -- Color palette for 8-bit pixel formats
SDL_PixelFormat -- Stores surface format information
SDL_Surface -- Graphical Surface Structure
SDL_VideoInfo -- Video Target information
SDL_Overlay -- YUV video overlay
3.3). Window Management[FIXME:不用实现]
SDL_WM_SetCaption -- Sets the window tile and icon name.
SDL_WM_GetCaption -- Gets the window title and icon name.
SDL_WM_SetIcon -- Sets the icon for the display window.
SDL_WM_IconifyWindow -- Iconify/Minimise the window
SDL_WM_ToggleFullScreen -- Toggles fullscreen mode
SDL_WM_GrabInput -- Grabs mouse and keyboard input.
3.4). Events
Introduction
SDL Event Structures.
Event Functions.
3.5). Joystick[FIXME:不用实现]
SDL_NumJoysticks -- Count available joysticks.
SDL_JoystickName -- Get joystick name.
SDL_JoystickOpen -- Opens a joystick for use.
SDL_JoystickOpened -- Determine if a joystick has been opened
SDL_JoystickIndex -- Get the index of an SDL_Joystick.
SDL_JoystickNumAxes -- Get the number of joystick axes
SDL_JoystickNumBalls -- Get the number of joystick trackballs
SDL_JoystickNumHats -- Get the number of joystick hats
SDL_JoystickNumButtons -- Get the number of joysitck buttons
SDL_JoystickUpdate -- Updates the state of all joysticks
SDL_JoystickGetAxis -- Get the current state of an axis
SDL_JoystickGetHat -- Get the current state of a joystick hat
SDL_JoystickGetButton -- Get the current state of a given button on a given joystick
SDL_JoystickGetBall -- Get relative trackball motion
SDL_JoystickClose -- Closes a previously opened joystick
3.6). Audio
SDL_AudioSpec -- Audio Specification Structure
SDL_OpenAudio -- Opens the audio device with the desired parameters.
SDL_PauseAudio -- Pauses and unpauses the audio callback processing
SDL_GetAudioStatus -- Get the current audio state
SDL_LoadWAV -- Load a WAVE file
SDL_FreeWAV -- Frees previously opened WAV data
SDL_AudioCVT -- Audio Conversion Structure
SDL_BuildAudioCVT -- Initializes a SDL_AudioCVT structure for conversion
SDL_ConvertAudio -- Convert audio data to a desired audio format.
SDL_MixAudio -- Mix audio data
SDL_LockAudio -- Lock out the callback function
SDL_UnlockAudio -- Unlock the callback function
SDL_CloseAudio -- Shuts down audio processing and closes the audio device.
3.7). CD-ROM[FIXME:不用实现]
SDL_CDNumDrives -- Returns the number of CD-ROM drives on the system.
SDL_CDName -- Returns a human-readable, system-dependent identifier for the CD-ROM.
SDL_CDOpen -- Opens a CD-ROM drive for access.
SDL_CDStatus -- Returns the current status of the given drive.
SDL_CDPlay -- Play a CD
SDL_CDPlayTracks -- Play the given CD track(s)
SDL_CDPause -- Pauses a CDROM
SDL_CDResume -- Resumes a CDROM
SDL_CDStop -- Stops a CDROM
SDL_CDEject -- Ejects a CDROM
SDL_CDClose -- Closes a SDL_CD handle
SDL_CD -- CDROM Drive Information
SDL_CDtrack -- CD Track Information Structure
3.8). Multi-threaded Programming[语义和pthread基本类似,不用更改和重新实现]
SDL_CreateThread -- Creates a new thread of execution that shares its parent's properties.
SDL_ThreadID -- Get the 32-bit thread identifier for the current thread.
SDL_GetThreadID -- Get the SDL thread ID of a SDL_Thread
SDL_WaitThread -- Wait for a thread to finish.
SDL_KillThread -- Gracelessly terminates the thread.
SDL_CreateMutex -- Create a mutex
SDL_DestroyMutex -- Destroy a mutex
SDL_mutexP -- Lock a mutex
SDL_mutexV -- Unlock a mutex
SDL_CreateSemaphore -- Creates a new semaphore and assigns an initial value to it.
SDL_DestroySemaphore -- Destroys a semaphore that was created by SDL_CreateSemaphore.
SDL_SemWait -- Lock a semaphore and suspend the thread if the semaphore value is zero.
SDL_SemTryWait -- Attempt to lock a semaphore but don't suspend the thread.
SDL_SemWaitTimeout -- Lock a semaphore, but only wait up to a specified maximum time.
SDL_SemPost -- Unlock a semaphore.
SDL_SemValue -- Return the current value of a semaphore.
SDL_CreateCond -- Create a condition variable
SDL_DestroyCond -- Destroy a condition variable
SDL_CondSignal -- Restart a thread wait on a condition variable
SDL_CondBroadcast -- Restart all threads waiting on a condition variable
SDL_CondWait -- Wait on a condition variable
SDL_CondWaitTimeout -- Wait on a condition variable, with timeout
3.9). Time[不用重新实现]
SDL_GetTicks -- Get the number of milliseconds since the SDL library initialization.
SDL_Delay -- Wait a specified number of milliseconds before returning.
SDL_AddTimer -- Add a timer which will call a callback after the specified number of milliseconds has elapsed.
SDL_RemoveTimer -- Remove a timer which was added with SDL_AddTimer.
SDL_SetTimer -- Set a callback to run after the specified number of milliseconds has elapsed.
4. SDL_ttf的字体渲染
是对FreeType的一个封装
font family:
font faces:
For example, "Palatino Regular" and "Palatino Italic" are two distinct faces from the same famous family, called "Palatino" itself.
#A font file contains a set of glyphs; each one can be stored as a bitmap, a vector representation or any other scheme (most scalable formats use a combination of mathematical representation and control data/programs). These glyphs can be stored in any order in the font file, and is typically accessed through a simple glyph index.
#The font file contains one or more tables, called a character map (or charmap in short), which is used to convert character codes for a given encoding (e.g. ASCII, Unicode, DBCS, Big5, etc..) into glyph indices relative to the font file. A single font face may contain several charmaps. For example, most TrueType fonts contain an Apple-specific charmap as well as a Unicode charmap, which makes them usable on both Mac and Windows platforms.
基本流程:
1). 获取字体文件
2). Include和库
编码基本流程:
a). 初始化
TTF_Init();
b). Loading font 文件
TTF_OpenFont(file, ptsize);
c). 渲染文字
TTF_RenderText_XXX();
3种渲染方式:
Solid : Use this mode for FPS and other fast changing updating text displays.
Shaded : Use this when you need nice text, and can live with a box
Blended: Use this when you want high quality, and the text isn't changing too fast.
阅读(2791) | 评论(1) | 转发(0) |