2

OpenGL vs. DirectX: Which Should You Use for Game Development?

 2 years ago
source link: https://www.makeuseof.com/opengl-vs-directx-game-development-best/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

OpenGL vs. DirectX: Which Should You Use for Game Development?

Published 5 hours ago

How do you decide which graphics API to use? It may come down to the platforms you’re targeting or simply whichever has the best raw performance.

graphics card with code

Graphics APIs, like OpenGL and DirectX, act as a bridge between the software and graphics hardware used to play games. These APIs provide standardized methods to display 2D and 3D graphics on-screen. They have become fundamental to game development over the last couple of decades.

Engines like Unity offer a choice between the graphics APIs they use, but how are you supposed to pick the right option for your game? Join us as we compare OpenGL with DirectX to give you an idea of which of these tools is best for you.

DirectX vs. OpenGL: Main Feature Overview

nvidia rtx 1080 graphics card

At their core, both DirectX and OpenGL share the same graphics pipeline, and they have for many years. Both APIs use points called vertices to build complex graphics primitives. Each vertex stores its own coordinates and other important information. But the way that each library uses vertices is different.

They may perform similar functions, but you’ll notice the difference between OpenGL and DirectX if you work with them.

DirectX vs. OpenGL: API Scope

Before going much further, it is important to note that, while they are both graphics APIs, OpenGL and DirectX have different scopes. OpenGL is a purebred graphics API, and this means that it doesn’t deal with anything other than 2D and 3D graphics. DirectX, on the other hand, is a collection of graphics, audio, networking, and other hardware APIs that all work together.

In some cases, OpenGL will use DirectX to perform functions that it can’t do on its own. The rest of this article will be ignoring this difference between the two APIs, focusing on the graphics elements of each tool.

OpenGL vs. DirectX: Platforms

OpenGL is a free API managed by a non-profit company called Khronos Group, while DirectX is made by Microsoft. DirectX works on Windows and Xbox primarily, with other platforms, like Linux, slowly getting support. OpenGL is cross-platform, making it usable for game development across a range of operating systems and game consoles.

DirectX vs. OpenGL: Hardware Resources

DirectX leaves hardware management to the developer, giving you the ability to allocate resources efficiently, as you need them. OpenGL handles hardware management, but this can come with its own benefits, as you don’t have to worry about managing resources yourself.

DirectX vs. OpenGL: Documentation

Access to detailed documentation can make game development much easier when working with APIs. DirectX and OpenGL offer regularly updated documentation and helpful developer communities. Both of these APIs receive large yearly updates to ensure that they offer the best features available.

Using OpenGL vs. DirectX for Game Development

Programming on a large curved monitor

Developers have made many beautiful and well-optimized games on the modern market using both OpenGL and DirectX. There are several things you should consider when choosing a 2D/3D graphics API. Some developers will simply rely on the tool they are most comfortable with.

OpenGL or DirectX: Platforms

We’ve already touched on platforms, but this is a crucial consideration for developers. If you want to make games for the Nintendo Switch, Playstation 4, or Linux, you will need to work with OpenGL or another API with support for them. DirectX is made for Windows and Xbox and has limited compatibility with other systems.

OpenGL or DirectX: Engine Compatibility

Most game developers use engines like Unity and Unreal to create their games, nowadays. Both of these engines support OpenGL and DirectX, as do other cross-platform game development engines.

OpenGL or DirectX: Ease of Use

Some would argue that OpenGL is easier to work with than DirectX. Alongside hardware resources, OpenGL only handles graphics, making it simpler by nature. The fact that it works across more platforms also makes it easier to release games with this requirement.

Graphics API ease of use isn’t as important as it used to be for game developers. With engines like Unity interfacing with graphics APIs behind the scenes, it only takes a click of a button to swap the API you are using. Unless you are creating a game from scratch, it’s unlikely that you will notice a difference in the ease of use of each API.

OpenGL or DirectX: Graphics Features

Unless you are a fringe case, it is unlikely that you will see a huge difference in the features you have available between these APIs. They both support your graphic card’s capabilities, and this is only going to change if GPUs see dramatic changes in the future.

OpenGL or DirectX: Game Performance

a man sitting playing games

There is much debate between developers regarding the performance of these APIs. It is hard to imagine that OpenGL or DirectX have significant performance differences, though the claim that OpenGL is smoother and more efficient is common online.

The only way to find out which of these APIs performs the best is through testing. Thanks to Unity’s compatibility with both APIs, we can create a project and test a sample game with both APIs to create a performance benchmark.

These tests have been performed with both 2D and 3D graphics to ensure that their differing pipelines aren’t a considerable factor. Each test runs for 120 seconds of regular gameplay and frames per second are being measured to determine performance. All testing has been conducted on the same PC.

3D Performance Test: Unity Carting Microgame

cart game made in unity

The Unity Carting Microgame is a free template that contains everything you need to build a simple racing game. It comes with tutorials, but we are more interested in the game itself. We built the Carting Microgame with both OpenGL and DirectX to compare their performance and the results were as follows:

Lowest Highest Average
DirectX 331 848 365.05
OpenGL 247 819 283.7

DirectX outperformed OpenGL in our 3D benchmark, achieving impressive frame rates throughout. OpenGL's results are still more than playable.

2D Performance Test: Unity Platformer Microgame

2D game with player and enemy

Much like the Carting Microgame, the Unity Platformer Microgame is free and packed with great learning tools. As expected, the 2D game in our tests performs better than the 3D one, but you can assess the results for yourself.

Lowest Highest Average
DirectX 599 850 767.367
OpenGL 302 604 515.417

As you can see from the results above, DirectX achieved a much higher average frame rate in our testing. While the difference may look dramatic, both of the results are very much playable.

OpenGL or DirectX 11: Performance Conclusion

While many people say that OpenGL performs better than DirectX, the latter API achieved better results in both of our benchmarks. This is far from conclusive, with many factors playing a role in dictating a game's performance, especially as they get more complex.

DirectX or OpenGL: Which Should You Use for Game Development?

Choosing the right graphics API depends on several factors. DirectX is the most widely used graphics API. Many game developers create their games for Windows and Xbox before porting them to OpenGL for other platforms. If you’re publishing a game exclusively outside of Windows and Xbox, you might benefit from using OpenGL from the beginning.

Performance is also a factor to consider, though our testing shows that this is fairly negligible when using engine tools like Unity. In essence, the differences between these two graphics APIs only matter to those looking for specific niche features.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK