各种 DirectX 绘图方法的成本/收益?

发布于 2024-12-20 15:20:59 字数 264 浏览 1 评论 0原文

我正在使用 C++ 和 DirectX9 开发 2D 游戏,并且已经完成了相当多的工作。截至目前,我对所有内容都使用 sprite.draw :玩家、背景(用 for 循环平铺)、墙壁、HUD 等。然后我开始质疑我是如何绘制的游戏是最好的方式。使用精灵和使用纹理基元之间有主要区别吗?有没有一种方法可以从我自己的函数中单独设置每个像素,这实用吗?如果我以后可以添加照明和 Alpha 混合,那就太好了,如果它不会使程序速度减慢太多,我会自己编写代码。我只想立即把事情搞清楚,确保没有遗漏任何东西。

I'm working on a 2D game using C++ and DirectX9 and I've got a decent amount of it working. As of now I have it using sprite.draw for everything: the player, the backgrounds (tiled with for loops), the walls, the HUD, etc. Then I started questioning if how I was drawing the game was the best way to go. Are there major differences between using sprites and using textured primitives? Is there a way to just set each pixel individually from my own functions, and would that be practical? It'd be nice if I could later add lighting and alpha blending, and I'd be up for coding that myself if it doesn't slow the program down too much. I just want to get things straight right away and make sure there's nothing I'm missing.

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

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

发布评论

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

评论(1

初相遇 2024-12-27 15:20:59

精灵绘制很好,它的优点是它可以为您处理所有纹理坐标,并且可能也是硬件加速的。

有没有一种方法可以从我自己的函数中单独设置每个像素,这是否实用

这是可能的,但不实用。 CPU 无法在每一帧处理如此多的像素,而且其总线也不够宽,无法在每一帧发送所有像素。这就是显卡的用途,它的像素处理速度要快得多,并且到显示器的总线要宽得多。

如果我以后可以添加照明和 Alpha 混合,那就太好了,如果它不会使程序速度减慢太多,我会自己编写代码

是可能的,有用于灯光和 alpha 混合的内置函数,您甚至可以自己编写代码(称为着色器)。

Sprite drawing is fine, the advantage of it is that it handles all the texture coordinates for you and probably is also hardware accelerated.

Is there a way to just set each pixel individually from my own functions, and would that be practical

It is possible, but not practical. The cpu cannot process so much pixels at each frame, and neither its buses are wide enough to send all of them every frame. Thats what the graphic card is for, it is much faster with pixel processing and has much wider buses to the display.

It'd be nice if I could later add lighting and alpha blending, and I'd be up for coding that myself if it doesn't slow the program down too much

It is possible, with built in functions for lights and alpha blending, and you can even code it yourself (its called a shader).

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