Sign in Join
Wiki copytemporary

FPC and SDL/zh CN: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11## 简介
22
33关于SDL的详细信息和文档,请访问 [SDL homepage](http://www.libsdl.org). This page is going to explain how to use SDL with Free Pascal, where to obtain the pascal headers etc.
44
55## 取得FPC 的 SDL 头文件
66
77After installing SDL itself on your system you'll need pascal headers to be able to use SDL with FPC. Since version 2.2.2, most SDL units are included with FPC itself. You can of course also download them from JEDI-SDL in case you need some bug fix or a unit not in the version shipped with FPC.
88
99### 来自 JEDI-SDL 的 SDL 头文件
1010
1111查看 [JEDI-SDL Home Page](http://jedi-sdl.pascalgamedevelopment.com/). 你能下载到 [JEDI-SDLv1.0 Beta](http://prdownloads.sourceforge.net/jedi-sdl/JEDI-SDLv1.zip?download)..
1212
1313You can also download and browse current CVS sources, see [JEDI-SDL SourceForge CVS](http://sourceforge.net/cvs/?group_id=43805) for instructions. In short, just do
1414
15-`  cvs -d:pserver:anonymous@jedi-sdl.cvs.sourceforge.net:/cvsroot/jedi-sdl login `
15+```text
16+ cvs -d:pserver:anonymous@jedi-sdl.cvs.sourceforge.net:/cvsroot/jedi-sdl login
17+```
1618
1719(when prompted for a password, simply press the Enter key)
1820
19-`  cvs -z3 -d:pserver:anonymous@jedi-sdl.cvs.sourceforge.net:/cvsroot/jedi-sdl co JEDI-SDLv1.0`
21+```text
22+ cvs -z3 -d:pserver:anonymous@jedi-sdl.cvs.sourceforge.net:/cvsroot/jedi-sdl co JEDI-SDLv1.0
23+```
2024
2125After you downloaded (and eventually unpacked) JEDI-SDL sources, you want to be able to use these units in your programs. For the simplest scenario, just add the following lines to your fpc.cfg file:
2226
23-` -Fi<jedi-sdl-path>/JEDI-SDLv1.0/SDL/Pas`\
24-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL/Pas`\
25-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Mixer/Pas`\
26-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Image/Pas`\
27-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Net/Pas`\
28-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_ttf/Pas`\
29-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/smpeg/Pas`\
30-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SFont/Pas`\
31-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Sound/Pas`\
32-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDLMonoFonts/Pas`\
33-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDLSpriteEngine/Pas`\
34-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/Cal3D/Pas`\
35-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/ODE/Pas`\
36-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDLCtrls/Pas`\
37-` -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_flic/Pas`
27+```text
28+ -Fi<jedi-sdl-path>/JEDI-SDLv1.0/SDL/Pas
29+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL/Pas
30+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Mixer/Pas
31+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Image/Pas
32+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Net/Pas
33+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_ttf/Pas
34+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/smpeg/Pas
35+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SFont/Pas
36+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_Sound/Pas
37+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDLMonoFonts/Pas
38+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDLSpriteEngine/Pas
39+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/Cal3D/Pas
40+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/ODE/Pas
41+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDLCtrls/Pas
42+ -Fu<jedi-sdl-path>/JEDI-SDLv1.0/SDL_flic/Pas
43+```
3844
3945(where \<jedi-sdl-path\> is the path where you placed jedi-sdl sources).
4046
4147或者, 你复制所有的 *.pas 和 *.inc 文件到你指定的目录,并且你必须把你选定的目录修正到 fpc.cfg.
4248
4349测试那些……, 你可以编译和运行许多Demo 程序, 例如下面这样.
4450
45-` cd <jedi-sdl-path>/JEDI-SDLv1.0/SDLSpriteEngine/Demos/Oxygene/`\
46-` fpc -Sd Oxygene.dpr`\
47-` ./Oxygene`
51+```text
52+ cd <jedi-sdl-path>/JEDI-SDLv1.0/SDLSpriteEngine/Demos/Oxygene/
53+ fpc -Sd Oxygene.dpr
54+ ./Oxygene
55+```
4856
4957Note that all jedi-sdl code should be compiled in Delphi-compatible mode. Most jedi-sdl units include jedi-sdl.inc that already has the line {\$mode delphi} added, but some example programs don't include jedi-sdl.inc. So be sure to compiled them with -Sd command-line option (or add {\$mode delphi} directive).
5058
5159### SDL headers from FreePascal CVS (deprecated)
5260
5361Get them using CVS:
5462
55-`cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS login`
63+```text
64+cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS login
65+```
5666
5767(password is 'cvs')
5868
59-`cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS -z3 co projects/contrib/sdl`
69+```text
70+cvs -d :pserver:cvs@cvs.freepascal.org:/FPC/CVS -z3 co projects/contrib/sdl
71+```
6072
6173## Tips and tricks
6274
6375### SDL_mixer library
6476
6577When using SDL_mixer, the call to Mix_OpenAudio MUST happen before the call to SDL_SetVideoMode, otherwise you will get a ( sometimes load ) audible pop.
6678
6779### SMPEG library
6880
6981If you use SDL_mixer you'll notice that it's dependent on smpeg library. For modern Linux distros and FreeBSD this is not a problem (because smpeg is distributed with them), but it can be troublesome e.g. for Windows. You can get smpeg.dll for Windows from [SDL_sound for Visual C sources](http://icculus.org/SDL_sound/downloads/sdl_sound_visualc_srcs.zip).
7082
7183Alternatively, you can simply modify the source of SDL_mixer.pas: remove smpeg from it's uses clause and comment out one line in the sources mentioning mp3s (it's a case near the end). Remember that you will also need to have SDL_mixer dll/so that is *not* linked to smpeg -- otherwise SDL_mixer library will depend on smpeg anyway.
7284
7385## Mac OS X specific issues
7486
7587### SDL 架构 and SDL 库
7688
7789On Mac OS X, SDL uses Cocoa to setup the drawing window and to handle all events (such as keypresses). This is done using a small piece of code that is automatically called when the program starts up, and which subsequently calls a function with the name *SDLmain*. More information is available at <http://www.libsdl.org/faq.php?action=listentries&category=7#55>
7890
7991There are however two different ways to package/distribute SDL for Mac OS X, and depending on which version you use, the procedure to get this startup code into your program is slightly different.
8092
8193#### 架构版本
8294
8395This the version that you get when you download the Mac OS X version of SDL from [libsdl.org](http://libsdl.org). In this case, the startup code is only available in source form. It is located on the installation disk image, in the folder *devel-lite*. After copying the *SDL.framework* from the disk image to */Library/Frameworks* and copying the *devel-lite* folder anywhere on your hard drive (e.g., in your home directory), you can compile it into libSDLMain.a by opening a Terminal session, navigating to the copied *devel-lite* folder, and executing the following commands:
8496
8597 gcc -c -o SDLMain.o SDLMain.m -I /Library/Frameworks/SDL.framework/Headers
8698 ar r libSDLMain.a SDLMain.o
8799 ranlib libSDLMain.a
88100
89101You can then move the generated *libSDLMain.a* librray anywhere you want. To make sure the linker can find it when you compile SDL applications, pass the *-Fl/full/path/to/folder/containing/libSDLMain.a* command line parameter to the compiler.
90102
91103#### Unix 库版本
92104
93105There is also a "classic Unix" version of SDL for Mac OS X (no framework, just a bunch of separate libraries), which you get if you compile SDL from sources, or if you install SDL using Fink or MacPorts. In this case, libSDLmain.a is already included in a compiled form. You just have to use the compiler's -Fl parameter, as explained in the previous section, to make sure that the linker can find this library.
94106
95107### For FPC 2.2.2 and later
96108
97109The SDL unit included with FPC includes all necessary framework, library and main procedure name renaming statements, so you no longer have to do anything special. Just add the sdl unit to your program and everything will be taken care of. However, the remarks about libSDLMain in the above section still hold (libSDLMain.a is required by the SDL unit included with FPC).
98110
99111Note that if you use the original units as distributed by the JEDI team, you may still need to follow the instructions in the section below.
100112
101113### 关于 FPC 2.0.2 至 2.2.0
102114
103115fpc 2.0.2 至 2.2.0, and possibly also when using the original SDL units as distributed by the JEDI team, you have to use the `-XMSDL_main` command line option and tell the linker to include some frameworks:
104116
1051171\) install sdl, for example using fink.
106118
1071192\) Add the following to your program:
108120
109-` {$linklib gcc}`\
110-` {$linklib SDLmain}`\
111-` uses sdl;`
121+``` pascal
122+ {$linklib gcc}
123+ {$linklib SDLmain}
124+ uses sdl;
125+```
112126
1131273\) Then, this command line does it:
114128
115-` ``fpc -XMSDL_main -k-L/sw/lib -k-lSDL -k-framework -kOpenGL -k-framework -kCocoa -Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files> YourProgram.pas`
129+```text
130+ <tt>fpc -XMSDL_main -k-L/sw/lib -k-lSDL -k-framework -kOpenGL -k-framework -kCocoa -Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files> YourProgram.pas</tt>
131+```
116132
117133If you installed the SDL libraries using fink, also add `-k-L/sw/lib -k-lSDL` to your fpc command.
118134
119135If sdl.pas and jedi-sdl.inc are in the directory of your program, you can omit `-Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files>`.
120136
121137## 例程
122138
123139建立一个空的 SDL 窗口:
124140
125-`program sdltest;`\
126-` {$linklib gcc}`\
127-`{$linklib SDLmain}`\
128-` uses sdl;`\
129-` var scr: PSDL_Surface; // Our main screen`\
130-` begin`\
131-` SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem`\
132-` scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr`\
133-` SDL_Quit; // close the subsystems and SDL`\
134-`end.`
141+``` pascal
142+program sdltest;
143+{$linklib gcc}
144+{$linklib SDLmain}
145+uses sdl;
146+var scr: PSDL_Surface; // Our main screen
147+begin
148+ SDL_Init(SDL_INIT_VIDEO); // Initialize the video SDL subsystem
149+ scr:=SDL_SetVideoMode(640, 480, 8, SDL_SWSURFACE); // Create a software window of 640x480x8 and assign to scr
150+ SDL_Quit; // close the subsystems and SDL
151+end.
152+```
135153
136154You can then compile this code with
137155
138-` fpc -Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files> example.pas`
156+```text
157+ fpc -Fu<pathtosdl.pas files> -Fi<pathtosdl.inc files> example.pas
158+```
139159
140160如果你是使用 lazarus, 请将 "other unit files" 和 "include files" 设置正确.
141161
142162译者注:
143163
144-`  "other unit files" 和 "include files"两个设置项,在lazarus的Project菜单->Compiler Options (编译选项)`
164+``` pascal
165+ "other unit files" 和 "include files"两个设置项,在lazarus的Project菜单->Compiler Options (编译选项)
166+```
145167
146168## 译者注
147169
148-`  英文版的官方文档我看的很是迷糊,因为我是在Ubuntu上使用Lazarus。而Linux上只有OpenGL,除此之外我别无选择。`
170+```text
171+ 英文版的官方文档我看的很是迷糊,因为我是在Ubuntu上使用Lazarus。而Linux上只有OpenGL,除此之外我别无选择。
172+```
149173
150174### SDL 和 JEDI-SDL
151175
152176SDL 是 Simple DirectMedia Layer打头字母的简写。Simple DirectMedia Layer有简单的媒体指令层的意思。
153177
154178JEDI 是 "Joint Endeavor of Delphi Innovators"打头字母的简写。Delphi Innovators共同努力。
155179
156180### 为什么要使用SDL?
157181
158182现阶段或者在未来很长的一段时间,我们与显示卡沟的办法有两种,一种是DirectX,另一种是OpenGL。这两种办法是受到主流显示卡支持的,但是当我们远离WINDOWS操作系统的时候,我们只有一个选择就是OpenGL,我很难想像在Windows以外的操作系统上使用DirectX。正如,当我想在Ubuntu上使用OpenGL的时候,我选了一个中间部份,这个中间部分就是SDL。
159183
160184---
161185*From the Free Pascal wiki, page "FPC and SDL/zh CN", as it stood on 2010-04-18 after a change by Installxp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
162186Category: zh

Back to history