您的位置:首页 > 编程语言 > C语言/C++

C++ SDL教程翻译 Lesson 01 Hello SDL

2017-06-19 20:24 363 查看
好吧,这就是SDL翻译系列的第一篇,我会在每一篇翻译末尾适当添加些内容,方便你的理解。

警告:转载此翻译文请注明来自CSDN博客,CSDN博客是此翻译唯一出处。

注:我才14,初二,可能翻译的并不好,纯手工加翻书,勿喷,有建议可回复或联系QQ540809998。

中文版:

课程1 你好SDL

在本教程中,我们将设置SDL库并创建我们的第一个窗口。

所以你学了C++的基础知识,但是你厌倦了做一些基于文本的程序。

为了使用图像、声音、键盘、操纵杆等东西,你需要一个API(应用程序程序员的接口),它可以将所有的硬件功能转化为C++可以交互的东西。

这就是SDL的作用。

它采用windows/linux/mac/android/ios/等工具,并以某种方式将它们封装在SDL中,并将其编译为它说支持的平台。

为了使用它,你需要安装它。

SDL作为一个动态链接的库。

一个动态链接的库有3个部分:

——头文件(Library.h)

——库文件(为windows或lib库提空自由的Library.lib,一个为了*nix)

——二进制文件(用于windows或lib库的dll,Library.dll。所以为了*nix)

你的编译器能在编译时找到头文件,这样它就知道SDL_Init和其他SDL函数的功能和结构是什么了。

你可以配置您的编译器,以在一个附加的目录中搜索SDL头文件,或者将头文件与编译器附带的其他头文件放在一起。

如果编译器抱怨它找不到SDL.h,这意味着头文件不再编译器寻找头文件的地方。

在编译器编译所有源文件之后,它必须将它们链接在一起。

为了使程序正确地链接,它需要知道所有函数的地址,包括SDL的地址。

对于动态链接的库,它们地址位于库文件中。

该库文件具有导入地址表,以便您的程序可以在运行时导入这些函数。

与头文件一样,您可以配置编译器来在SDL库文件所在的附加目录中搜索,或者将库文件与编译器附带的其他库文件放在一起。

您还必须告诉链接器链接到链接器中的库文件。

如果链接器抱怨它找不到-lSDL或SDL2.lib,这意味着库文件不在链接器查找库文件的地方。

如果链接器抱怨一个未定义的引用,这很可能意味着它从未被告知要链接这个库。

在您的程序被编译并链接之后,您要能够在运行它时链接到库。

为了运行一个动态链接的应用程序,您需要能够在运行时导入库二进制文件。

当您运行程序时,您的操作系统需要能够找到库二进制文件。

您可以将库二进制文件放在与可执行文件相同的目录中,或者您的操作系统保存库二进制文件的目录。

在设置SDL之后,我们将讨论如何创建SDL2窗口。

中英对照版:

Lesson 01 Hello SDL

课程1 你好SDL

In this tutorial we will be setting up the SDL library and creating our first window.

在本教程中,我们将设置SDL库并创建我们的第一个窗口。

So you learned the basics of C++, but you’re sick of making little text based programs.

所以你学了C++的基础知识,但是你厌倦了做一些基于文本的程序。

In order to use things like graphics, sound, keyboards, joysticks, etc you need an API (Application Programmer’s Interface) that takes all those hardware features and turns it into something C++ can interact with.

为了使用图像、声音、键盘、操纵杆等东西,你需要一个API(应用程序程序员的接口),它可以将所有的硬件功能转化为C++可以交互的东西。

That’s what SDL does.

这就是SDL的作用。

It takes the Windows/Linux/Mac/Android/iOS/etc tools and wraps them in a way that you can code something in SDL and compile it to what ever platform it supports.

它采用windows/linux/mac/android/ios/等工具,并以某种方式将它们封装在SDL中,并将其编译为它说支持的平台。

In order to use it, you need to install it.

为了使用它,你需要安装它。

SDL as a dynamically linked library.

SDL作为一个动态链接的库。

A dynamically linked library has 3 parts:

一个动态链接的库有3个部分:

——The header files (Library.h)

——头文件(Library.h)

——The library files (Library.lib for windows or libLibrary.a for *nix)

——库文件(为windows或lib库提空自由的Library.lib,一个为了*nix)

——The binary files (Library.dll for windows or Library.so for *nix)

——二进制文件(用于windows或lib库的dll,Library.dll。所以为了*nix)

Your compiler needs to be able to find the header files when compiling so it knows what SDL_Init() and the other SDL functions and structures are.

你的编译器能在编译时找到头文件,这样它就知道SDL_Init和其他SDL函数的功能和结构是什么了。

You can either configure your compiler to search in an additional directory where the SDL header files are located, or put the header files in with the rest of header files that your compiler comes with.

你可以配置您的编译器,以在一个附加的目录中搜索SDL头文件,或者将头文件与编译器附带的其他头文件放在一起。

If the compiler complains that it can’t find SDL.h, it means the header files aren’t in a place that the compiler looks for header files.

如果编译器抱怨它找不到SDL.h,这意味着头文件不再编译器寻找头文件的地方。

After your compiler compiles all your source files it has to link them together.

在编译器编译所有源文件之后,它必须将它们链接在一起。

In order to program to link properly, it needs to know the addresses of all your functions including the ones for SDL.

为了使程序正确地链接,它需要知道所有函数的地址,包括SDL的地址。

For a dynamically linked library, these addresses are in the library file.

对于动态链接的库,它们地址位于库文件中。

The library file has the Import Address Table so your program can import the functions at runtime.

该库文件具有导入地址表,以便您的程序可以在运行时导入这些函数。

Like with header files, You can either configure your compiler to search in an additional directory where the SDL library files are located, or put the library files in with the rest of library files that your compiler comes with.

与头文件一样,您可以配置编译器来在SDL库文件所在的附加目录中搜索,或者将库文件与编译器附带的其他库文件放在一起。

You also have to tell the linker to link against the library file in the linker.

您还必须告诉链接器链接到链接器中的库文件。

If the linker complains that it can’t find -lSDL or SDL2.lib, it means the library files aren’t in a place that the linker looks for library files.

如果链接器抱怨它找不到-lSDL或SDL2.lib,这意味着库文件不在链接器查找库文件的地方。

If the linker complains about an undefined reference, it probably means it was never told to link the library.

如果链接器抱怨一个未定义的引用,这很可能意味着它从未被告知要链接这个库。

After your program is compiled and linked, you need to be able to link against the library when you run it.

在您的程序被编译并链接之后,您要能够在运行它时链接到库。

In order to run a dynamically linked application, you need to be able to import the library binaries at runtime.

为了运行一个动态链接的应用程序,您需要能够在运行时导入库二进制文件。

Your operating system needs to be able to find the library binary when you run your program.

当您运行程序时,您的操作系统需要能够找到库二进制文件。

You can either put the library binaries in the same directory as your executable, or a directory that your operating system keeps library binary files.

您可以将库二进制文件放在与可执行文件相同的目录中,或者您的操作系统保存库二进制文件的目录。

After you set up SDL, we’ll cover how to create an SDL 2 window.

在设置SDL之后,我们将讨论如何创建SDL2窗口。

Lesson 01是教你如何配置SDL的,但是外国的这个教程可能说的并不清楚,大家可以参照SDL学习之路1st(当然是我写的)配置就可以了,这里是地址:

【哇咔咔,超强的传送门】

所以说白了,Lesson 01的价值并不大,但是可以让你很好的理解SDL。

说实话,每一课(Lesson)都太长了,光Lesson 01我就翻译了一晚上,还是在我作业在学校写完的情况下(初二),所以Lesson 02的更新可能会等久一点,不过也快暑假了哦~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sdl c语言 c++ sdl2 sdl教程