作者:龙飞
1.1:准备工作。
准备一张640*480的bmp位图(back.bmp)作为背景,另外一张小一点的(比如100*100的front.bmp)作为前景。
渲染(render)是CG术语,是将以数据结构储存在计算机中的图片以人眼可观察的图片实现出来的过程。前面例子中显示一张bmp图片实际上也是渲染。对于那张bmp图片,我们经历了3过过程的处理:1、将bmp图片转化为SDL_Surface的结构格式;2、将转化后的SDL_Surface块移(blit)到SDL创建的窗口surface上;3、将这个surface显示出来,实际上就是渲染出来。
当然,前面仅仅是渲染了单帧的图片,我们这里对程序做些修改,从而实际上是连续的渲染多帧动画(虽然表面上我们并没有让画面动起来)。
1.2:演示程序的完整源代码。
#include
<
iostream
>
#include " SDL/SDL.h "
SDL_Surface * pScreen = 0 ;
SDL_Surface * pBack = 0 ;
SDL_Surface * pFront = 0 ;
void pressESCtoQuitPlus();
void loopRender();
int main( int argc, char * argv[])
{
try {
if ( SDL_Init(SDL_INIT_VIDEO) != 0 )
throw SDL_GetError();
}
catch ( const c
#include " SDL/SDL.h "
SDL_Surface * pScreen = 0 ;
SDL_Surface * pBack = 0 ;
SDL_Surface * pFront = 0 ;
void pressESCtoQuitPlus();
void loopRender();
int main( int argc, char * argv[])
{
try {
if ( SDL_Init(SDL_INIT_VIDEO) != 0 )
throw SDL_GetError();
}
catch ( const c