是否有同时具有像素完美绘图和 2D 硬件加速的 2D 图形 API? [英] Is there a 2D graphics API with both pixel perfect drawing and 2D hardware acceleration?

查看:29
本文介绍了是否有同时具有像素完美绘图和 2D 硬件加速的 2D 图形 API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我们正处于制作 2D 游戏的第一阶段,该游戏将专注于可破坏的环境和物体.

We are in the first stages of making a 2D game at the moment, which will focus on destructible environments and objects.

然而,我们在选择正确的图形 API 方面已经遇到了严重的问题

However, we have already encountered serious problems with the choice of the right graphics API

目前,我们使用 SDL - 但我们看到它的问题是它的性能不高,并且没有硬件加速的表面缩放和旋转!- 这也使得动画相机变焦几乎不可能

At the moment, we use SDL - but the problem we see with it is that it isn't really performant, and has no hardware-accelerated surface scaling and rotating! - This also makes animated camera zooms practically impossible

我们也考虑过使用 OpenGL,但是我们看到它的问题是我们需要的直接像素访问.您认为这是正确的选择吗?

We have thought about using OpenGL as well, however the problem we see with it is the direct pixel access that we need. Do you think it would be the right choice?

我们正在寻找的是一个图形 API,它是硬件加速的,提供直接像素访问和修改以及表面的快速块传输、旋转和缩放

What we are searching for is a graphics API that is hardware accelerated, offers direct pixel access and modifying as well as fast blitting, rotating and scaling of surfaces

推荐答案

OpenGL 可以为您提供直接的像素访问,但有时很难理解为什么它没有某些功能...

OpenGL can give you direct pixel access, but its sometimes difficult to understand why it doesn't with some functionality...

glDrawPixels可能是最简单和最可靠的方法 - 您可以将一块像素从常规"内存复制到帧缓冲区 - 这不是特别快,但是它很旧(MSDN 记录了它很旧),跨平台得到很好的支持(和硬件)并为您提供像素渲染的完全控制和准确性 - 您甚至可以对所有渲染逻辑进行编程以在 CPU 上运行,并将其用于绘制像素.但是,尝试利用使用硬件的性能优势可能是明智的...

glDrawPixels is probably the simplest and most reliable way - you can copy a block of pixels from "regular" memory on to the framebuffer - this isn't especially fast, but its old (its documented by MSDN its so old), well supported across platforms (and hardware) and gives you total control and accuracy for pixel rendering - you can even program all of your rendering logic to run on the CPU and just use it for drawing pixels. However, it is probably sensible to try and leverage the performance benefits of using the hardware...

使用硬件很好,但即使是最简单的操作也不能保证像素完美的精度 - 通常驱动程序会做一些与你期望的有点不同的事情 - GL_LINES、GL_LINE_LOOP 等通常表现得最好 -很难以像素精度使用它们,据我所知,如果你想要更粗的线条,就没有办法让它们一致地呈现——不同的驱动程序会做不同的事情.虽然它可能只是一个像素差异,但我知道这通常足以引起问题.

Using the hardware is fine, but having pixel-perfect precision is not guaranteed for even the simplest of operations - often the driver will do something a little different to what you are expecting - GL_LINES, GL_LINE_LOOP etc. usually show this best - its difficult to use them with pixel accuracy and as far as I know there is no way to have them render consistently if you want thicker lines - different drivers will do different things. Although it might only be a single pixel difference I know that can often be enough to cause a problem.

然而,有些操作很可能是像素完美的,例如,在屏幕大小的四边形上采样纹理.这对于延迟渲染和需要以某种方式合成全屏缓冲区的类似技术至关重要 - 只要您避免舍入错误的常见问题,您通常可以以像素完美的精度定位三角形/四边形 - 只是不要围绕通过累积浮点值来筛选屏幕 - 通过使用每个像素具有整数值的变换使其尽可能简单,这可以通过 glOrtho 函数.事实上,根据经验,三角形渲染方法最受关注,并且需要最一致,因为最流行的图形软件(游戏)完全依赖于它们.

Some operations however are very likely to be pixel-perfect, for instance, sampling a texture across a screen-sized quad. This is vital for deferred rendering and similar techniques where full-screen buffers need to be composited somehow - so long as you avoid the common problems with rounding errors you can normally position triangles/quads with pixel perfect precision - just don't iterate around the screen by accumulating floating point values - make it as simple as possible by using a transform which has integer values for each pixel, this can be achieved with the glOrtho function. In fact as a rule of thumb the triangle rendering methods get the most attention and need to be the most consistent simply because the most popular graphics software (games) are totally dependent on them.

如果您正在努力寻找执行特定操作的方法,那么也可以考虑研究着色器 - 它们几乎总是足以满足您的任何需要(尽管使其性能提高可能具有挑战性)并为您提供额外的水平高质量 2d 渲染器可能需要的控制.

If you are struggling to find ways to do particular operations then consider looking into shaders as well - they are almost always sufficient for whatever you want to do (although it might be challenging to make it performant) and give you that extra level of control that you are likely to need for a high quality 2d renderer.

这篇关于是否有同时具有像素完美绘图和 2D 硬件加速的 2D 图形 API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆