架构师_程序员_码农网

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

搜索
查看: 8935|回复: 1

[windows] windosXP下【SDL的编程】VC环境搭建

[复制链接]
发表于 2017-6-1 08:49:54 | 显示全部楼层 |阅读模式
北京上课了讲师指出,SDL(simple DirectMedia Layer)是一个可跨平台的开源库,在windosXP下也可以搭建。
PC:Mircrosoft Windows XP Service Pack3
Platform:Mircrosoft Visual C++ 6.0
SourceCode:SDL-devel-1.2.14-VC6.zip
步骤
    1. 解压SDL-devel-1.2.14-VC6.zip.将解压后的lib文件夹里把SDL.lib SDLmain.lib拷贝到VC6.0安装目录的lib文件夹下面。
    2. 将SDL.dll拷贝到系统盘的WINDOWS/SYSTEM32目录下(如果你要将之后生成的SDL应用程序转移到其他没有配置SDL环境的机器上用的话,请将SDL.dll一起拷贝)。
    3. 在VC6.0安装目录的include文件夹下面新建一个SDL的目录,并将SDL-devel-1.2.14-VC6.zip解压后的include里的文件拷贝到这个SDL目录下面。
    4. 打开VC6,新建一个project->win32 Application.打开project目录下面的那个setting,选中C/C++,Category里选中Code Generation,Use run-time library使用Multithread DLL.
    5. 继续在上面的setting中选中Link,Category里选中input,在Object/library modules中填入SDL.lib SDLmain.lib
    6. 在VC项目中新建一个cpp,并添加到项目中,编译,运行.
相关链接
1.SDL http://www.libsdl.org/download-1.2.php
测试代码
  1. #include <stdlib.h>
  2. #include "SDL/SDL.h"

  3. SDL_Surface *screen;

  4. void render()
  5. {        
  6.     // Lock surface if needed
  7.     if (SDL_MUSTLOCK(screen))   
  8.         if (SDL_LockSurface(screen) < 0)   
  9.             return;

  10.     // Ask SDL for the time in milliseconds
  11.     int tick = SDL_GetTicks();

  12.     // Declare a couple of variables
  13.     int i, j, yofs, ofs;

  14.     // Draw to screen
  15.     yofs = 0;
  16.     for (i = 0; i < 480; i++)
  17.     {
  18.         for (j = 0, ofs = yofs; j < 640; j++, ofs++)
  19.         {
  20.             ((unsigned int*)screen->pixels)[ofs] = i * i + j * j + tick;
  21.         }
  22.         yofs += screen->pitch / 4;
  23.     }

  24.     // Unlock if needed
  25.     if (SDL_MUSTLOCK(screen))   
  26.         SDL_UnlockSurface(screen);

  27.     // Tell SDL to update the whole screen
  28.     SDL_UpdateRect(screen, 0, 0, 640, 480);         
  29. }


  30. // Entry point
  31. int main(int argc, char *argv[])
  32. {
  33.     // Initialize SDL's subsystems - in this case, only video.
  34.     if ( SDL_Init(SDL_INIT_VIDEO) < 0 )   
  35.     {
  36.         fprintf(stderr, "Unable to init SDL: %s\n", SDL_GetError());
  37.         exit(1);
  38.     }

  39.     // Register SDL_Quit to be called at exit; makes sure things are
  40.     // cleaned up when we quit.
  41.     atexit(SDL_Quit);
  42.          
  43.     // Attempt to create a 640x480 window with 32bit pixels.
  44.     screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);
  45.      
  46.     // If we fail, return error.
  47.     if ( screen == NULL )   
  48.     {
  49.         fprintf(stderr, "Unable to set 640x480 video: %s\n", SDL_GetError());
  50.         exit(1);
  51.     }

  52.     // Main loop: loop forever.
  53.     while (1)
  54.     {
  55.         // Render stuff
  56.         render();

  57.         // Poll for events, and handle the ones we care about.
  58.         SDL_Event event;
  59.         while (SDL_PollEvent(&event))   
  60.         {
  61.             switch (event.type)   
  62.             {
  63.             case SDL_KEYDOWN:
  64.                 break;
  65.             case SDL_KEYUP:
  66.                 // If escape is pressed, return (and thus, quit)
  67.                 if (event.key.keysym.sym == SDLK_ESCAPE)
  68.                     return 0;
  69.                 break;
  70.             case SDL_QUIT:
  71.                 return(0);
  72.             }
  73.         }
  74.     }
  75.     return 0;
  76. }
复制代码





上一篇:如何迈向成为架构师的第一步
下一篇:.net/c# log4net日志无法写入到文件
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
发表于 2017-6-1 09:25:22 | 显示全部楼层
给你排版了一下
码农网,只发表在实践过程中,遇到的技术难题,不误导他人。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

免责声明:
码农网所发布的一切软件、编程资料或者文章仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。本站信息来自网络,版权争议与本站无关。您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。如有侵权请邮件与我们联系处理。

Mail To:help@itsvse.com

QQ|手机版|小黑屋|架构师 ( 鲁ICP备14021824号-2 )|网站地图

GMT+8, 2025-3-21 22:46

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表