Chinaunix首页 | 论坛 | 博客
  • 博客访问: 8296199
  • 博文数量: 1413
  • 博客积分: 11128
  • 博客等级: 上将
  • 技术积分: 14685
  • 用 户 组: 普通用户
  • 注册时间: 2006-03-13 10:03
个人简介

follow my heart...

文章分类

全部博文(1413)

文章存档

2013年(1)

2012年(5)

2011年(45)

2010年(176)

2009年(148)

2008年(190)

2007年(293)

2006年(555)

分类: C/C++

2006-11-24 22:28:59

Welcome to the SDL Tutorial!

for Visual Studio .NET

Written by

  • Brian
  • Erik

SDL Version is 1.2.5 as of writing this tutorial.

Browse to the lib SDL home page...
Then click on the download -> SDL 1.2 link.


Under the Win32 development libraries, download the latest version of SDL-devel VC6 package.


Create a directory in C:\ named LIB_SDL. This will be used to store all your include files, DLL flies, and libraries.
Save the zip file to this directory.


Extract the zip file to the directory, it should create a folder named with the latest version of SDL. If you open the folder, its contents should look similar to this.


Launch Microsoft Visual Studio .NET


Click on the Tools->Options. Then select the Projects->VC++ Directories. Select "Include Files" from the top right pull down and add the C:\LIB_SDL\SDL-1.2.5\include directory.  


Select the top right pull down menu again and choose "Library Files". Then add the directory C:\LIB_SDL\SDL-1.2.5\lib.

Now that this is done, the compiler will know where to look for SDL libraries and header files. These settings are global and set as default for every new project.

Go to the file menu, and select "New->Project".


Select the Visual C++ Projects folder, and scroll down and create a Win32 Project.
Enter the name of the project, and the folder where you want to save it and hit OK.


Select "Application Settings" and change the application type to Console Application
Select "Empty Project" under Additional Options.


Right-click on the name of your project in the Solution explorer and select "Properties".


Select the "code Generation" on the left. On the right, select the "Runtime Library" pull down menu and choose Multi-Threaded DLL or Multi-Threaded Debug DLL if you wish to use debugging. Hit OK.


Right click on the Project name in the solution exploer, and select "Add->Add New Item...".


Select C++ File and name it main, and hit Open.


Copy and paste this source code or manually type it in to the main.cpp file.


/* -- Include the precompiled libraries -- */
#ifdef WIN32
#pragma comment(lib, "SDL.lib")
#pragma comment(lib, "SDLmain.lib")
#endif

#i nclude "SDL.h"

int main(int argc, char **argv)
{
	printf("\nHello SDL User!\n");

	/* initialize SDL */
	if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
	{
		fprintf( stderr, "Video initialization failed: %s\n",
			SDL_GetError( ) );
		SDL_Quit( );
	}
	
	SDL_Quit( );

	return 0;
}



Select the "Build" menu and choose "Build Solution"


You need to copy the SDL.dll file from the lib directory (C:\LIB_SDL\SDL-1.2.5\lib) to your Debug directory where your freshly bulit executable now lays (c:\SDL_Test\SDL_Test\Debug) so the program may run.


From the windows menu, Click "Run" and type cmd, then hit the open button to open a command window. You will use this to run your appication.


Use cd to change to your directory:

cd C:\SDL_Test\SDL_Test\Debug, then type SDL_Test.exe and hit enter!


Congratulations! You have successfully written, compiled, and run your first SDL program. While this does not use any SDL code, it does show that SDL is successfully installed. You must change the project properties, include the libraries in the code, and copy the dll for every project you make. Use the documentation available on or from the main site to create your first programs! Enjoy!

Back to the

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=283472

阅读(2280) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~