What 3D graphics framework should I use for a real world game engine? [closed]
Asked Answered
C

5

15

I'm a C++ programmer with very extensive server programming experience. I'm however fairly bored at the moment and I decided to tackle a new area: 3D game programming, for learning purposes. Additionally I think this learning project may turn out to be good resume material in the future should I decide to work in this area.

Instead of creating a 3D engine from scratch I decided to emulate as exactly as I'm able an existing one: World of Warcraft's. If you are curious as to why (feel free to skip this):

  • It's a real world successful game
  • All the map textures, models and what not are already done (I'm not interested in learning how to actually draw a texture with photoshop or whatever)
  • Their file formats have been more or less completely reverse engineered
  • There is already an identical open source project (wowmapview) that I can look at if I'm in trouble.

ok, that was a long preface.. Now, my main question is the following: Should I use DirectX, OpenGL, wrapper libraries such as sdl, or what?

What's the most used one in the real world?

And, something else that perplexes me: World of Warcraft appears to be using both! In fact, normally it uses DirectX, but you can use opengl by starting it with the "-opengl" switch via command line.

Is this something common in games? Why did they do it? I imagine it's a lot of work and from my understanding nobody uses OpenGL anyway (very very few people know about the secret switch at all).

If it's something usually done, do programmers usually create their own 3d engine "wrapper", something like SDL made in house, and based on switches / #defines / whatnot decide which API function to ultimately call (DirectX or OpenGL)? Or is this functionality already built in in sdl (you can switch between DirectX and OpenGL at will)?

And, finally, do you have any books to suggest?

Thanks!

Cyma answered 7/11, 2009 at 1:11 Comment(5)
"Why did they do it?" Because Mac OsX doesn't have DirectX support?Neurasthenic
SDL is merely a platform abstraction layer, it substitutes neither OpenGL nor DirectX. When SDL is used though, it is more commonly used with OpenGL, since both cross platform libraries. Also worth noting is that SDL doesn't provide a widget toolkit, so if that's a requirement (not very common in fullscreen 3D games), something like Qt might be a better choice for a cross platform application.Pentane
@gf: good point. Makes me wonder now why they don't support linux natively since they went through all the trouble to make OpenGL work for mac.. should only need relatively trivial changes. oh well, guess I'll never find out.Cyma
Blizzard do, or at least did at some point, have an internal, unsupported build for Linux, but it's never been released. I'm pretty sure they're using SDL too, since Slouken, WoW's lead interface programmer, is also the author of SDL...Sirup
take a look at this as well gamedev.stackexchange.com/questions/90/… this is my favorite post when I think I am boring and decide to do some game for fun especially WOW like . ^_^Barefoot
N
31

I realize you already accepted an answer, but I think this deserves some more comments. Sorry to quote you out of order, I'm answering by what I think is important.

Instead of creating a 3D engine from scratch I decided to emulate as exactly as I'm able an existing one: World of Warcraft's.

However I wanted to focus on the actual 3d and rendering engine, not the interface, so I don't think I will be using it [lua] for this project.

From these two snippets, I can tell you that you are not trying to emulate the game engine. Just the 3D rendering backend. It's not the same thing, and the rendering backend part is very small part compared to the full game engine.

This, by the way, can help answer one of your questions:

World of Warcraft appears to be using both! In fact, normally it uses DirectX, but you can use opengl by starting it with the "-opengl" switch via command line.

Yep, they implemented both. The amount of work to do that is non-negligeable, but the rendering back-end, in my experience, is at most 10% of the total code, usually less. So it's not that outraging to implement multiple ones.

More to the point, the programming part of a game engine today is not the biggest chunk. It's the asset production that is the bulk (and that includes most game programming. Most lua scripts are considered on that side of things, e.g.)

For WoW, OSX support meant OpenGL. So they did it. They wanted to support older hardware too... So they support DX8-level hardware. That's already 3 backends. I'm not privy to how many they actually implement, but it all boils down to what customer base they wanted to reach.

Multiple back-ends in a game engine is something that is more or less required to scale to all graphics cards/OSs/platforms. I have not seen a single real game engine that did not support multiple backends (even first party titles tend to support an alternate back-end for debugging purposes).

ok, that was a long preface.. Now, my main question is the following: Should I use DirectX, OpenGL, wrapper libraries such as sdl, or what?

Well, this depends strongly on what you want to get out of it. I might add that your option list is not quite complete:

  • DirectX9
  • DirectX10
  • DirectX11
  • OpenGL < 3.1 (before deprecated API is removed)
  • OpenGL >= 3.1
  • OpenGL ES 1.1 (only if you need to. It's not programmable)
  • OpenGL ES 2.0

Yep, those APIs are different enough that you need to decide which ones you want to handle.

If you want to learn the very basics of 3D rendering, any of those can work. OpenGL < 3.1 tends to hide a lot of things that ultimately has to happen in user code for the other ones (e.g. Matrix manipulation, see this plug).

The DX SDKs do come with a lot of samples that help understand the basic concepts, but they also tend to use the latest and greatest features of DX when it's not necessarily required when starting (e.g. using Geometry shader to render sprites...)

On the other hand, most GL tutorials tend to use features that are essentially non-performant on modern hardware (e.g. glBegin/glEnd, selection/picking, ... see the list of things that got removed from GL 3.1 or this other plug) and tend to seed the wrong concepts for a lot of things.

What's the most used one in the real world?

For games, DirectX9 is the standard today in PC world. By a far margin.

However, I'm expecting DirectX11 to grab more market share as it allows for some more multithreaded work. It's unfortunately significantly more complicated than DX9.

nobody uses OpenGL anyway (very very few people know about the secret switch at all).

Ask the Mac owners what they think.

Side question, do you really think hardware vendors would spend any energy in OpenGL drivers if this was really the case (I realize I generalize your comment, sorry)? there are real world usages of it. Not much in games though. And Apple makes OpenGL more relevant through the iphone (well OpenGL ES, really).

If it's something usually done, do programmers usually create their own 3d engine "wrapper",

It's usually a full part of the engine design. Mind you, it's not abstracting the API at the same level, it's usually more at a "draw this with all its bells and whistles over there". Which rendering algorithm to apply on that draw tends to be back-end specific.

This, however, is very game engine dependent. If you want to understand better, you could look at UE3, it just got released free (beer) for non-commercial use (I have not looked at it yet, so I don't know if they exposed the backends, but it's worth a look). To get back to my comment that game engine does not just mean 3D, look at this.

Naarah answered 7/11, 2009 at 10:7 Comment(4)
+1 for a very thorough and thoughtful answer!Gubernatorial
Great answer, marked this one as accepted. Thanks !Cyma
wow, I did not even know you could change the accepted answer after the fact.Naarah
+1 for noting that the renderer and game logic require orders of magnitude less effort than assets. Renderers and engines can be made in a few days, but proper assets can take months to design.Lamellar
C
3

I think the primary benefit of using OpenGL over DirectX is the portability. DirectX only runs on windows. However, this is often not a problem (many games only run on Windows).

DirectX also provides other libraries which are useful for games which are unrelated to graphics such as sound and input. I believe there are equivalents which are often used with OpenGL but I don't think they're actually part of OpenGL itself.

If you're going to be locking into windows with DirectX and you are willing to/interested in learning C# and managed code, I have found XNA to be and extremely easy platform to learn. It allows you to learn most of the concepts without dealing with a lot of the really tricky details of DirectX (or OpenGL). You can still use shader code and have the full power of DirectX but in a much friendlier environment. It would be my recomendation but again, you'd have to switch to C# (mind you, you can also put that on you're resume).

Cornute answered 7/11, 2009 at 1:18 Comment(3)
DirectX no longer supports C#: social.msdn.microsoft.com/Forums/en-US/…. The last version I used with support was 9.0cDamnify
Huge +1 for XNA given the askers background and future applicability of the technologyAphorism
True, you cannot program DirectX directly with C# however, XNA is a C# library, which uses DirectX underneath. It is not the same as DirectX and is very much in use today, version 3.0 just came out recently.Cornute
T
1

You might want to look at some projects that encapsulate the low level 3d api in a higher level interface that is api independent such as Ogre3D. As you are doing this to learn I assume you probably will be more interesting in implementing the low level detail yourself, but you could probably learn a lot from such a project.

Threadgill answered 8/11, 2009 at 9:28 Comment(1)
Or irrlicht, or openscenegraphColchicum
R
0

I'm doing some OpenGL work right now (on both Windows and Mac).

Compared to my midnight game programming using the Unity3D engine, usingOpenGL is a bit like having to chop down your own trees to make a house versus buying the materials.

Unity3D runs on everything (Mac, PC and iPhone, Web player, etc) and lets you concentrate on the what makes a game, a game. To top it off, it's faster than anything I could write. You code for it in C#, Java (EDIT: make that JavaScript) or Boo. (EDIT: Boo support has been dropped)

I just used Unity to mock up a demo for a client who wants something made in OpenGL so it has it's real world uses also.

-Chris

PS: The Unity Indie version recently became free.

Ragout answered 9/11, 2009 at 1:30 Comment(2)
A little correction: You can program in Javascript, not Java! :-)Franchot
Thanks Thiago. I've fixed it 7 years later...Ragout
M
0

if you are really only interested in the rendering part, i can suggest ogre3d. it is clean, c++, tested and cross-platform. i used it in two projects and compared to other experiences (torque3d for example), i liked the good support (tutorials/wiki/forum) and the not so steep learning curve. i think someone can also learn a lot by looking at the sourcecode and the concepts they have used in the design. there is a accompanying book as well, which is a bit outdated, but it is good for the start

the problem with this is, you will be thinking inside this engine and soon you will need gameplay-like (timers, events) elements for simulating and testing your effects or whatever you want to do. so you will end up working around ogre3ds shortcomings (it is not a game engine) and implement in on your own or use another middleware.

so if you really want to touch 3d rendering first, i would take some computer graphics books (gpu gems, shaderx) and see some tutorials and demos on the web and start building my own basic framework. this is for the experience and i think you will learn the most from this approach. at least i did ...

Moreira answered 24/11, 2009 at 15:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.