SDL作图

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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值