TA的每日心情 | 开心 2019-11-11 10:36 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
SDL安装步解:
个人感言,SDL是一个非常好用的东西,好处说不清楚,就是感觉小巧玲笼,异常方便,从手感上比QT,Wx都要小一些.
这个安装是一个编译安装,也就是从源码编译开始讲起,也有直接的运行时库,推荐使用第三方库时,要从编译源码开始,因为好的运行时库可能存在一些版本问题,从平台版本到各种插件的版本都可能不同,这样就有一定的概率碰到谦容性的问题,因为编译运行时库的官方机器与您的机器的配置并不完全相同,总有一些问题可能发生.
第一步:从SDL的官方网站上下载源码:
下载地址为: http://www.libsdl.org/release/SDL-1.2.13.zip
将其解压,比如解压到D:/盘根目录下(这里只是假设,您应该建立一个方便的地方),那么D:/SDL-1.2.13下就存放有SDL的源码
第二步:从微软官方下载DirectX10的安装包与SDK
DirectX10的安装包下载地址(建议使用迅雷直接把链接输进去下):http://hnny.skycn.com/down/directx_dec2005_redist.exe
DirectX10的SDK下载地址:http://download.microsoft.com/do ... a/dxsdk_aug2007.exe
经过上面两步的安装后,就可以很好的编译SDL了,
到D:/SDL-1.2.13下,把VisualC.ZIP解压到当前目录.(也就是D:/SDL-1.2.13/VisualC/下是其内容,否则肯定编译不了)
第三步:
打开文件: D:/SDL-1.2.13/VisualC/SDL.sln ,开始编译(建议点击VS菜单:生成->批生成->全选,生成)
第四步:编译成功后,把Release版本的LIB集中起来,也就是把D:/SDL-1.2.13/VisualC/SDL/Release下的文件SDL.lib 和D:/SDL-1.2.13/VisualC/SDLmain/Release下的文件SDLmain.lib拷到D:/lib (没有该目录则新建).
把D:/SDL-1.2.13/VisualC/SDL/Release 下的SDL.DLL拷到C:/Windows/system32下(平常不建议这么做,因为就一个DLL,算了)
第五步:配置环境
打开VS菜单:工具->选项->项目和解决方案树目录下的VC++目录->添加包含文件目录: D:/SDL-1.2.13/include ->添加库文件目录: D:/lib
第六步:测试
新建一个WIN32控制台程序,在VS菜单:项目->属性->配置属性->链接器->输入:附加依赖项中加入:SDL.lib SDLmain.lib
添加一个CPP源文件:写上如下内容:
///////////////////////////////////
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include <windows.h>
/*
PLEASE NOTE: the program will require SDL.dll which is located in
dev-c++'s dll directory. You have to copy it to you
program's home directory or the path.
*/
/* The screen surface */
SDL_Surface *screen = NULL;
/* This function draws to the screen; replace this with your own code! */
static void
draw ()
{
static int direction = 0;
static int value = 0;
static int which = 0;
SDL_Rect rect;
Uint32 color;
/* Create a black background */
color = SDL_MapRGB (screen->format, 0, 0, 0);
SDL_FillRect (screen, NULL, color);
/* Determine which color the layer should have */
if (direction == 0)
{
value += 2;
if (value >= 256)
{
value = 255;
direction = 1;
}
}
else
{
value -= 2;
if (value <= 5)
{
value = 0;
direction = 0;
which++;
if (which == 5)
which = 0;
}
}
/* Draw a layer with variable color */
switch (which)
{
case 0:
color = SDL_MapRGB (screen->format, value, 0, 0);
break;
case 1:
color = SDL_MapRGB (screen->format, 0, value, 0);
break;
case 2:
color = SDL_MapRGB (screen->format, 0, 0, value);
break;
case 3:
color = SDL_MapRGB (screen->format, value, value, value);
break;
case 4:
color = SDL_MapRGB (screen->format, value, 0, value);
break;
}
rect.w = screen->w / 2;
rect.h = screen->h / 2;
rect.x = (screen->w / 2) - (rect.w / 2);
rect.y = (screen->h / 2) - (rect.h / 2);
SDL_FillRect (screen, &rect, color);
/* Make sure everything is displayed on screen */
SDL_Flip (screen);
/* Don't run too fast */
SDL_Delay (1);
}
int
main (int argc, char *argv[])
{
int done;
/* Initialize SDL */
if (SDL_Init (SDL_INIT_VIDEO) < 0)
{
MessageBox (0,TEXT("完法初始化SDL"), TEXT("Error"), MB_ICONHAND);
exit (1);
}
atexit (SDL_Quit);
/* Set 640x480 16-bits video mode */
screen = SDL_SetVideoMode (640, 480, 16, SDL_SWSURFACE | SDL_DOUBLEBUF);
if (screen == NULL)
{
MessageBox (0, TEXT("无法把其设置为640*480模式"), TEXT("Error"), MB_ICONHAND);
exit (2);
}
SDL_WM_SetCaption ("SDL MultiMedia Application", NULL);
done = 0;
while (!done)
{
SDL_Event event;
/* Check for events */
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
/* Draw to screen */
draw ();
}
return 0;
}
////////////////////////////////////////
然后生成Release版本,最后运行一下看看是不是出现下图:
{:soso__4011813854091704040_1:} |
|