Chinaunix首页 | 论坛 | 博客
  • 博客访问: 530571
  • 博文数量: 102
  • 博客积分: 2146
  • 博客等级: 大尉
  • 技术积分: 1146
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-09 17:32
文章分类

全部博文(102)

文章存档

2015年(14)

2014年(24)

2013年(5)

2012年(30)

2011年(16)

2010年(13)

分类: 嵌入式

2014-04-03 09:49:31

        先给出一个有趣的例子,它会在窗口标题栏上循环打印不同的标题:
  1. #include "SDL.h"

  2. int main(int argc, char* argv[])
  3. {

  4.   SDL_Window *window;
  5.   SDL_Event e;

  6.   const char *titles[] = { // just for fun, let's make the title animate like a marquee and annoy users
  7.     "t", "thi", "this w", "this win", "this windo", "this window's", "this window's ti", "this window's title",
  8.     "chis window's title is", "chih window's title is ", "chih wandnw's title is ", "c h wandnw'g title is ",
  9.     "c h a nw'g titln is ", "c h a n g i n ig ", "c h a n g i n g!", "",
  10.     "c h a n g i n g!", "", "c h a n g i n g!", "c h a n g i n g!"
  11.   };

  12.   SDL_Init(SDL_INIT_VIDEO); // Init SDL2
  13.   
  14.   // Create a window.
  15.   window = SDL_CreateWindow(
  16.     "This will surely be overwritten", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 320, 240, SDL_WINDOW_RESIZABLE
  17.   );

  18.   // Enter the main loop. Press any key or hit the x to exit.
  19.   for( ; e.type!=SDL_QUIT&&e.type!=SDL_KEYDOWN; SDL_PollEvent(&e)){
  20.     static int i = 0, t = 0;

  21.     if(!(++t%9)){ // every 9th frame...
  22.       SDL_SetWindowTitle(window, titles[i]); // loop through the
  23.       if(++i >= sizeof(titles)/sizeof(titles[0])) i = 0; // array of titles
  24.     }

  25.     SDL_Delay(10);
  26.     
  27.   }
  28.   
  29.   SDL_DestroyWindow(window);
  30.   SDL_Quit();
  31.   return 0;
  32.   
  33. }
        运行效果图:
               
        以前的代码都是基于1.2版本的,比较旧,而且代码功能上也不及2.0,这个是2.0的一个小框架。算是入门的代码,可以先学习!2.0在1.2基础上做了很多优化,2.0在显示方面尽可能获得硬件加速支持。官网上的文档写得是非常详细: ,随时可以上去查询。
         
阅读(6013) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~