SDL作图

来源:互联网 发布:淘宝甩手掌柜工具箱 编辑:程序博客网 时间:2024/05/02 02:46

SDL


  
题1:要求用SDL编程进行绘图,如下图所示,该图形由坐标系、一个矩形和两个椭圆构成,其屏幕的背景色为白色。 
 实验十五:SDL
#include
#include
#include
#include
#include
int main()
{
  SDL_Surface*s;  int r;
  intret=SDL_Init(SDL_INIT_VIDEO);
 if(ret<0){printf("init error!\r\n");exit(-1);};
 s=SDL_SetVideoMode(640,480,16,SDL_SWSURFACE); 
 if(s==NULL){printf("setvideomodeerror!\r\n");exit(-1);};
 atexit(SDL_Quit);

 SDL_FillRect(s,NULL,SDL_MapRGB(s->format,255,255,255));//背景色
 Draw_HLine(s,200,240,440,SDL_MapRGB(s->format,0,0,0));
 Draw_VLine(s,320,180,300,SDL_MapRGB(s->format,255,0,0));
 Draw_Ellipse(s,240,180,76,56,SDL_MapRGB(s->format,0,0,255));
 Draw_FillEllipse(s,400,300,76,56,SDL_MapRGB(s->format,0,0,255));
 Draw_FillRect(s,200,250,100,80,SDL_MapRGB(s->format,255,255,0));
  
 SDL_UpdateRect(s,0,0,0,0);
 SDL_Delay(5000);
  return0;
  //gcc drawline.c -o drawline -I/usr/include/SDL -lSDL-lSDL_draw
}
题2:要求完成阶梯状图形,效果如下图所示:
实验十五:SDL
#include
#include
#include
#include
#include
void ShowBMP(char*pn,SDL_Surface *s,int x,int y)
{
  SDL_Surface*i;
  SDL_Rectdest;
 i=SDL_LoadBMP(pn);
 if(i==NULL){printf("load BMP error!\r\n");exit(-1);};
 dest.x=x;
 dest.y=y;
 dest.w=i->w;
 dest.h=i->h;
 SDL_BlitSurface(i,NULL,s,&dest);
 SDL_UpdateRects(s,1,&dest);
}
int main()
{
  SDL_Surface*s;
  intr;
  intret=SDL_Init(SDL_INIT_VIDEO);
 if(ret<0){printf("init error!\r\n");exit(-1);};
 s=SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
 if(s==NULL){printf("setvideomodeerror!\r\n");exit(-1);};
 atexit(SDL_Quit);
  intx,y,i,j;
 SDL_FillRect(s,NULL,SDL_MapRGB(s->format,0,255,0));
 SDL_UpdateRect(s,0,0,0,0);

 for(i=0;i<5;i++)
   for(j=0;j<5;j++)
   {
     x=i*48;
     y=j*32;
      if(i==j) ShowBMP("black.bmp",s,x,y);
       elseShowBMP("white.bmp",s,x,y);
    }
//ShowBMP("white.bmp",s,0,0);
 SDL_Delay(5000);
  return0;
}

0 0