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

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

问题描述

我们目前正在制作一款2D游戏的第一阶段,它将专注于可破坏的环境和对象。



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



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



我们也考虑过使用 OpenGL ,但是我们看到的问题是直接我们需要的像素访问。你认为这是正确的选择吗?我们正在寻找的是一个图形API,它是硬件加速的,提供直接的像素访问和修改,以及快速blitting ,旋转和缩放表面

解决方案

OpenGL可以给你直接的像素访问,但它有时很难理解它为什么不能具有一些功能......



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

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



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



如果您正在努力寻找特定操作的方法,那么请考虑查看着色器 - 它们对于您想要执行的任何操作而言几乎总是足够的(尽管可能会使其具有高性能)并为您提供额外的级别您可能需要高质量的2D渲染器。


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

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

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

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?

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 can give you direct pixel access, but its sometimes difficult to understand why it doesn't with some functionality...

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...

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.

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.

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图形API同时具有像素完美绘图和2D硬件加速?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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