C语言 有没有关于 C 编程的 SDL2.0 的好教程?(不是 C++)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31615012/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 12:03:25  来源:igfitidea点击:

Are there good tutorials for SDL2.0 for C programming? (not C++)

csdl-2

提问by MrChwepsy

I'm a student learning C programming (at the moment).

我是一名学习 C 编程的学生(目前)。

In the subject I was given, I have to create some kind of Wolfenstein3d clone (hence the name of the project, "wolf3d"). To do this project, I'm allowed to use either the graphic library created by my school, or the SDL. I chose the SDL, because it is more complex to use and therefore more interesting.

在我得到的主题中,我必须创建某种 Wolfenstein3d 克隆(因此项目名称为“wolf3d”)。为了完成这个项目,我可以使用学校创建的图形库或 SDL。我选择了 SDL,因为它使用起来更复杂,因此也更有趣。

Unfortunately, I was not able to find any tutorial for SDL2 in C. Even the SDL wiki links were all oriented C++.

不幸的是,我找不到任何关于 C 语言的 SDL2 教程。甚至 SDL wiki 链接都是面向 C++ 的。

I'd be grateful if you could help me finding good tutorials for the SDL2 in C (even though I know the policy of the website is "use a search engine, which I did, but as I said, I did not find any so far).

如果您能帮我找到 C 语言中 SDL2 的好教程,我将不胜感激(尽管我知道该网站的政策是“使用搜索引擎,我做到了,但正如我所说,我没有找到任何远的)。

I think I might need to explain a few things about my school, in order to not give you the impression I'm asking you for help in order to cheat:

我想我可能需要解释一些关于我的学校的事情,以免给你留下我在向你求助以作弊的印象:

Why don't you look in your class notes?

Because I'm not given any. I'm given projects to do and sometimes few hints as how I should do them. I'm supposed to use Google or any means as long as I understand what I did.

你为什么不看看你的课堂笔记?

因为我没有得到任何。我有项目要做,有时我应该如何做这些提示很少。我应该使用谷歌或任何方式,只要我明白我做了什么。

And that's pretty much it. I'm also not looking for a tutorial on "how to create a wolfenstein3d clone using SDL2.0", but only a tutorial on how to use the SDL2 itself, from creating a window to drawing points.

仅此而已。我也不是在寻找关于“如何使用 SDL2.0 创建 wolfenstein3d 克隆”的教程,而只是关于如何使用 SDL2 本身的教程,从创建窗口到绘制点。

回答by Kin3TiX

If I were you I would use the tutorials available on SDL's page here:

如果我是你,我会使用 SDL 页面上提供的教程:

http://wiki.libsdl.org/Tutorials

http://wiki.libsdl.org/Tutorials

In conjunction with the API documentation here:

结合此处的 API 文档:

http://wiki.libsdl.org/APIByCategory

http://wiki.libsdl.org/APIByCategory

The API is written in C so despite the fact that the tutorials may be in C++ you should be able to follow the tutorial by referencing the API docs and understanding the functional structure of the example programs.

API 是用 C 编写的,所以尽管教程可能是用 C++ 编写的,但您应该能够通过参考 API 文档并理解示例程序的功能结构来遵循教程。

As an aspiring developer you should be able to understand enough of the C++ syntax to understand the conceptual way you need to develop an analogous application in C. The API calls will be need to made in the same way.

作为一个有抱负的开发人员,您应该能够理解足够的 C++ 语法,从而理解用 C 开发类似应用程序所需的概念方式。 API 调用需要以相同的方式进行。

Consider this page from one of the linked tutorials (which is stated as being for C++):

考虑来自链接教程之一的这个页面(它被声明为用于 C++):

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php

http://lazyfoo.net/tutorials/SDL/01_hello_SDL/index2.php

Are any of those code blocks really foreign to you? They shouldn't be, they're written in C. If you come across some expressions you are unfamiliar with as you go through the tutorial, reference the API. If you're still stumped, then maybe it would be time to post on StackOverflow. That particular tutorial may be written completely in C, I'm not sure I only went through the first few pages.

这些代码块中的任何一个对您来说真的很陌生吗?它们不应该是,它们是用 C 编写的。如果您在学习本教程时遇到一些不熟悉的表达式,请参考 API。如果您仍然感到困惑,那么也许是时候在 StackOverflow 上发帖了。那个特定的教程可能完全是用 C 编写的,我不确定我只看过前几页。

Also note that the function documentation in the SDL API docs gives C and C++ example code:

另请注意,SDL API 文档中的函数文档提供了 C 和 C++ 示例代码:

http://wiki.libsdl.org/SDL_Init

http://wiki.libsdl.org/SDL_Init

Here you can cross reference two identical programs in C and C++ and begin to learn how the same operations are performed in the two languages. From there you can start to interpret C++ tutorials for high level functional operations and translate that to C as opposed to just copying code samples. You will learn much more going through this process.

在这里,您可以交叉引用 C 和 C++ 中的两个相同程序,并开始学习如何在这两种语言中执行相同的操作。从那里你可以开始解释高级函数操作的 C++ 教程,并将其转换为 C,而不是仅仅复制代码示例。通过这个过程,你会学到更多。

To your own admission you decided to go the complex route. You should be prepared to invest some effort in the process!

你自己承认你决定走复杂的路线。您应该准备在此过程中投入一些精力!