为什么 SDL 和 OpenGL 相关?
我正在摆弄 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
关于旋转图形的示例:使用 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.
SDL 处理输入、窗口创建、图像加载和 OpenGL 不处理的其他几个功能。
SDL handles input, window creation, image loading and several other functionality that OpenGL doesn't handle.
正如许多人所说,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. :)
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.
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.