为什么 SDL 和 OpenGL 相关?

发布于 2024-11-03 15:16:53 字数 189 浏览 3 评论 0原文

我正在摆弄 SDL,发现无法使用 SDL 旋转图像。到处问这个问题,人们都说用OpenGL来做旋转。我一直认为SDL与OpenGL完全分开,我的想法错了吗?我什至找到了在 SDL 中使用 OpenGL 的教程,这让我更加困惑。 SDL和OpenGL到底是什么关系?如果 OpenGL 更强大并且允许您做更多事情,为什么不直接使用 OpenGL(这是我读到的内容)?

I was messing around with SDL and found out that you cannot rotate images with SDL. Everywhere the question was asked, people said to use OpenGL to do rotation. I always thought that SDL was completely separate from OpenGL, am I wrong in thinking this? I even found tutorials for using OpenGL within SDL, which confused me even further. What exactly is the relationship between SDL and OpenGL? Why not just use OpenGL if its more powerful and allows you to do more (this is from what I've read)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

别把无礼当个性 2024-11-10 15:16:54

关于旋转图形的示例:使用 OpenGL(即硬件加速)比使用 SDL 本身(即在 CPU 上)更好,因为它通常是计算密集型的(特别是如果您有很多位图需要旋转每一帧并且你希望效果平滑)。

但是,没有什么(除了原因)阻止您使用 SDL_gfx 包,该包的模块 SDL_rotozoom 负责旋转和缩放位图。

About your example about rotating graphics: it is better to do it with OpenGL (i.e. hardware accelerated) than with SDL itself (i.e. on the CPU) because it is generally computionally intensive (especially if you have a lot of bitmaps to rotate every frame and you want the effect to be smooth).

However, nothing (besides reason) keeps you from using the SDL_gfx package which has the module SDL_rotozoom responsible for rotating and scaling bitmaps.

还不是爱你 2024-11-10 15:16:54

SDL 处理输入、窗口创建、图像加载和 OpenGL 不处理的其他几个功能。

SDL handles input, window creation, image loading and several other functionality that OpenGL doesn't handle.

時窥 2024-11-10 15:16:54

正如许多人所说,SDL 不仅仅处理渲染。除了处理音频、输入和其他好东西之外,它还使您可以访问许多原本需要自己实现的功能,从而使图形的使用更加简单。

所以是的,SDL 是 OpenGL 之上的抽象层。但是,您仍然可以在应用程序中访问 OpenGL,从而充分利用其功能。

一个简单的补充,因为您似乎对这种 API 很陌生:如果您想要一个类似于 SDL(用于 2D 图形)的 API,我建议您查看 SFML。它基于 C++ 而不是 C,并且具有旋转等功能。它也是基于 OpenGL 的。 :)

As many people have stated, SDL handles more than just rendering. Besides handling audio, input, and other nice stuff, it makes the use of graphics simpler by giving you access to many functions which you would otherwise need to implement yourself.

So yes, SDL is an abstraction layer above OpenGL. However, you are still able to access OpenGL in your application and therefore use its full power.

A simple addition, since you seem to be new to this kind of API: If you want an API which is similar to SDL (for 2D graphics), I recommend having a look at SFML. It's based on C++ instead of C and has functions for things like rotation. It's also based on OpenGL. :)

下壹個目標 2024-11-10 15:16:53

SDL是OpenGL之上的一层;事实上,它在 Windows 上默认使用 GDI,并且还具有 DirectX 后端。人们可能会说,您可以使用 OpenGL 来绕过默认使用 OpenGL 的平台上的 SDL 限制(咳咳,Linux),因为更高级别的抽象不会公开该功能。但是,您的代码“不太”可移植到 Windows(或至少使用 GDI 后端的 Windows)。

此外,除了图形之外,SDL 还可以完成许多 OpenGL 所不具备的其他功能 - 音频、输入等。

SDL is a layer above OpenGL; in fact it uses GDI on Windows by default and also has a DirectX backend. People are probably saying you can use OpenGL to get around limitations of SDL on platforms that by default use OpenGL (ahem, Linux) because the higher level abstraction doesn't expose that functionality. However, then your code is "less" portable to Windows (or at least Windows using the GDI backend).

Also, SDL does a lot of other things besides graphics - audio, input, etc. that OpenGL doesn't do.

十年九夏 2024-11-10 15:16:53

SDL 是一个跨平台多媒体库,旨在提供对音频、键盘、鼠标、操纵杆等。它还通过 OpenGL 支持 3D 硬件。

OpenGL 是一个标准规范,定义了跨语言、跨平台的 API,用于编写生成 2D 和 3D 计算机图形的应用程序。该界面由 250 多个不同的函数调用组成,可用于从简单的图元绘制复杂的三维场景。 OpenGL由Silicon Graphics Inc. (SGI)于1992年开发[4],广泛应用于CAD、虚拟现实、科学可视化、信息可视化和飞行模拟等领域。它还用于视频游戏,与 Microsoft Windows 平台上的 Direct3D 竞争(请参阅 OpenGL 与 Direct3D)。

SDL is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, etc. It also supports 3D hardware via OpenGL.

OpenGL is a standard specification defining a cross-language, cross-platform API for writing applications that produce 2D and 3D computer graphics. The interface consists of over 250 different function calls which can be used to draw complex three-dimensional scenes from simple primitives. OpenGL was developed by Silicon Graphics Inc. (SGI) in 1992[4] and is widely used in CAD, virtual reality, scientific visualization, information visualization, and flight simulation. It is also used in video games, where it competes with Direct3D on Microsoft Windows platforms (see OpenGL vs. Direct3D).

孤独患者 2024-11-10 15:16:53

SDL 使用 OpenGL 作为硬件渲染器,用于在某些平台上需要硬件渲染的内容。如果您有这样的平台,那么 OpenGL 就是底层 API,SDL 是其抽象。

SDL uses OpenGL as a hardware renderer for content that wants hardware rendering on some platforms. If you have such a platform, then OpenGL is the underlying API over which SDL is an abstraction.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文