Hacker News new | ask | show | jobs
by astrodust 4661 days ago
How else do you get pixels to the screen at reasonable frame rates? You load it into a texture and place it on a 3D polygon that just happens to be sized the same as the screen, making it in effect a 2D canvas with 1:1 texel to pixel mappings. Doing old-school "bitblitting" isn't going to cut it today, the overhead is too huge. GPU texture manipulation and layering is orders of magnitude faster than what you can do in the CPU space.

Windows uses Direct3D for the native UI, and OS X uses OpenGL for the same thing.

1 comments

Your definition of "reasonable" really needs a qualifier here.

If you're doing AAA games in 2D, yeah you will use the GPU. But an indie game? You probably don't need it. Especially if you're writing the game without Unity (i.e. straight C++). The costs of setting up and working with 2D in OpenGL is high. I've done it. It's not fun, it's not pretty. It's a bitch, plain and simple. Texture atlases, font rendering, UV coords, texture uploading, vertex buffers, shaders. That's a ton of crap you have to worry with. Just to render simple 2D sprites to a screen. Many people can and do skip it and go straight to SDL or somesuch. It works, and modern CPUs are more than adequate.

Most of the popular 2D engines use OpenGL or Direct3D in the back-end, it allows them to do compositing much more easily, and at near zero cost. You don't have to worry about a thing if you're using the right library, it's no harder than the usual canvas calls.

This isn't just about performance. On a phone it's about not burning the battery down by loading down the CPU with expensive tasks that the GPU can do more easily.

Don't forget you can do your font rendering in the classic environment, then ship that texture image over for placement. It's not all that difficult with the right tools, many of which get packaged up for you transparently. You're not stuck in OpenGL by any means.

Most "2D" games are just 3D games rendered in isometric mode, top-down, with the depth information being used for layering.

> This isn't just about performance.

Yes, but let's not forget you made it about performance.

There are plenty of reasons to choose to use OpenGL. Lots of freebies come with it. But you can still do 2D games without the GPU. That's the point. You can't just keep moving the goal posts however you want.