Sign in to follow this  
harminal

Question about c,c++,direct x and game development

Recommended Posts

In the creation of a game i see most developers use c++. I just have a few questions that need answering 1)I see WoW uses the C Language and direct x graphics. I thought direct X couldnt be used in C so how would they go about doing this? 2) In directX programming is there a tutorial/way to use normal C++ with the Win32 part of the programming?

Share this post


Link to post
Share on other sites
I think you have a few confusions about what Direct X and Win32 is exactly.

DirectX is basically just some libraries that serve as an intermediary between your code, and the hardware. Back in the day the games had to have special code for all different types of hardware, there was no abstraction so if the game didn't directly support some kind of hardware, you were SOL. DirectX came, and provided one interface to access any different kind of hardware, and if the hardware didn't support something then it could tell you, and possibly try and emulate the functionality with software.

Win32 is another library, and it allows your application to interact with the windows operating system. This entails things like making windows, receiving messages, etc...

Now for your questions:

1) I'm wager that WoW uses C++. Any large project nowadays is going to be using object oriented programming, it's just too essential to creating manageable software. DirectX is built on COM, which requires C++, so you could not use it with C, I believe. Keep in mind though, that C++ is pretty backwards compatible with C, so you could write and compile C code with a C++ compiler, and use C++ libraries with your C code.

2) Win32 and DirectX are "normal C++". They are just libraries, they can be accessed by any language. Visual Basic, Delphi, Python, Etc... can all use Win32 and DirectX. Not sure exactly what you're asking here.

Share this post


Link to post
Share on other sites
Quote:
Original post by cclyde
DirectX is built on COM, which requires C++, so you could not use it with C, I believe.


No, COM can be used with C. That's why the header files are built with all those mental macros. You basically end up calling free functions and passing the equivalent of this as a normal parameter.

It's awkward but it can be done.

Share this post


Link to post
Share on other sites
Quote:
Original post by cclyde
Win32 and DirectX are "normal C++". They are just libraries, they can be accessed by any language. Visual Basic, Delphi, Python, Etc... can all use Win32 and DirectX. Not sure exactly what you're asking here.


Actually, it is extremely difficult to get DirectX to work with older Borland Win32 compilers. I'm not entirely sure why this is but this was what made me migrate from Borland to Visual C++.

And yes, you can mix C and C++ code very easily. You might have to typecast certain data and at worst wrap some code in "extern C" but they are very compatible. In fact, I mostly use standard C with C++ only being used for the class portion.

Share this post


Link to post
Share on other sites
Quote:
Original post by harminal
In the creation of a game i see most developers use c++. I just have a few questions that need answering

1)I see WoW uses the C Language and direct x graphics. I thought direct X couldnt be used in C so how would they go about doing this?

2) In directX programming is there a tutorial/way to use normal C++ with the Win32 part of the programming?


World of Warcraft is written in C++, not C.

Share this post


Link to post
Share on other sites
Quote:
Original post by Flimflam
Quote:
Original post by harminal
In the creation of a game i see most developers use c++. I just have a few questions that need answering

1)I see WoW uses the C Language and direct x graphics. I thought direct X couldnt be used in C so how would they go about doing this?

2) In directX programming is there a tutorial/way to use normal C++ with the Win32 part of the programming?


World of Warcraft is written in C++, not C.


C++ is just a superset of C. I wouldn't read to much into semantics. I know of no commercial compilers this day and age that are exclusively C or exclusively C++. Every modern compiler I've seen has supported both and often support ASM too.

Share this post


Link to post
Share on other sites
Its not semantics because they are two different languages (which is why I cringe when someone says C/C++) and really should be treated as such.

C is C, C++ is C++. Compilers might well deal with both however that doesn't make them the same thing and it disappoints me that people working in a field which requires precision and correctness ignore this simple fact.

If anything, this mixing of C and C++ is probably partly to blame for so much bad C++ existing because people treat C++ as 'C with classes' and end up writing bad code and missing out on the many features of C++ which would allow them to write better programs; both in code quality and execution speed.

So, yes, the semantics are important.

(also, while there might well be support for C89, C99 is alot less widespread. Afaik VC++ doesn't support it even in VS 2010)

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Its not semantics because they are two different languages (which is why I cringe when someone says C/C++) and really should be treated as such.

C is C, C++ is C++. Compilers might well deal with both however that doesn't make them the same thing and it disappoints me that people working in a field which requires precision and correctness ignore this simple fact.

If anything, this mixing of C and C++ is probably partly to blame for so much bad C++ existing because people treat C++ as 'C with classes' and end up writing bad code and missing out on the many features of C++ which would allow them to write better programs; both in code quality and execution speed.

So, yes, the semantics are important.

(also, while there might well be support for C89, C99 is alot less widespread. Afaik VC++ doesn't support it even in VS 2010)

Well I know VS2008 had poor to nonexistent C99 support from the little bit I tried to use.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
If anything, this mixing of C and C++ is probably partly to blame for so much bad C++ existing because people treat C++ as 'C with classes' and end up writing bad code and missing out on the many features of C++ which would allow them to write better programs; both in code quality and execution speed.


Do you have any data to back this up or is this just your opinion?

To say "better programs" implies that C++ is an inherently better language than C which is ridiculous. It's ultimately about the coder's level of knowledge, not the language. I've seen very ugly "pure C++" code.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
Its not semantics because they are two different languages (which is why I cringe when someone says C/C++) and really should be treated as such.


Very well then...phantom advocates not using the "for" statement because it was a C statement.

Share this post


Link to post
Share on other sites
Quote:
Original post by lakmir0
Do you have any data to back this up or is this just your opinion?
If it's "only" opinion, I'd say it's at least a fairly common opinion.
Quote:
Original post by lakmir0
To say "better programs" implies that C++ is an inherently better language than C which is ridiculous.
That's not quite true. The comparison is more like a native speaker of English vs. someone who speaks English with a heavy accent. It's not that English is "inherently" better than any other language or that a native English speaker is inherently better at communication, but a native English speaker will be able to communicate better in English than someone who speaks English with a heavy accent.
Quote:
Original post by lakmir0
Very well then...phantom advocates not using the "for" statement because it was a C statement.
Yeah, and you shouldn't use "if" since that's COBOL... yuck!

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
Quote:
Original post by lakmir0
Do you have any data to back this up or is this just your opinion?
If it's "only" opinion, I'd say it's at least a fairly common opinion.
Quote:
Original post by lakmir0
To say "better programs" implies that C++ is an inherently better language than C which is ridiculous.
That's not quite true. The comparison is more like a native speaker of English vs. someone who speaks English with a heavy accent. It's not that English is "inherently" better than any other language or that a native English speaker is inherently better at communication, but a native English speaker will be able to communicate better in English than someone who speaks English with a heavy accent.
Quote:
Original post by lakmir0
Very well then...phantom advocates not using the "for" statement because it was a C statement.
Yeah, and you shouldn't use "if" since that's COBOL... yuck!


You must be one of those C++ fanboys. Yeah, no point talking any further then.

Share this post


Link to post
Share on other sites
Quote:
Original post by lakmir0
You must be one of those C++ fanboys. Yeah, no point talking any further then.
I thought my response was quite reasoned... but, whatever.

Share this post


Link to post
Share on other sites
Quote:
Original post by Codeka
Quote:
Original post by lakmir0
You must be one of those C++ fanboys. Yeah, no point talking any further then.
I thought my response was quite reasoned... but, whatever.


It's not reasoned to say C++ is easier to "communicate" with...it's blooming absurd. C is a very flexible language and it integrates well with many other languages as well.

C++ is good for what it does. I like a certain amount of OOP but I also know how to code without.having.to.make.everything.class.oriented.

I once heard a joke about OOP that is true in a lot of circles..."OOP is like sex...everyone talks about doing it but few are actually doing it."

Don't bother arguing over this...we both obviously have our opinions fixed.

Share this post


Link to post
Share on other sites
Quote:
Original post by lakmir0
It's not reasoned to say C++ is easier to "communicate" with...
Right, but that's not what I said. I said it's easier to "communicate" if you use C++ correctly (as opposed to using C++ incorrectly, not as opposed to communicating in C or some other language).
Quote:
Original post by lakmir0
I once heard a joke about OOP that is true in a lot of circles..."OOP is like sex...everyone talks about doing it but few are actually doing it."
I actually think we agree. The discussion is not about which language is "better", but whether you're using the language you've chosen the way it's supposed to be used. If you're using C++ as "C with classes" then you're not using C++ the way it's supposed to be used.

Share this post


Link to post
Share on other sites
Quote:
Original post by lakmir0
To say "better programs" implies that C++ is an inherently better language than C which is ridiculous. It's ultimately about the coder's level of knowledge, not the language. I've seen very ugly "pure C++" code.


No, I was talking purely in the context of writing C++ code.

And yes, it is ultimately about the user's level of knowledge, however with C++ often that level of knowledge reaches a point where they can use it and they don't bother looking any further, at which point many people hit the 'C with classes level'.

Take for example the for loop; there is nothing wrong with the for loop as it is clearly part of the language. However, there is a very good chance that using something like std::foreach when going over a container (or memory block) will be faster because the compiler can (and most certainly does) fold more code together thus producing better performing code.

Now, you might say 'this is ugly' but I would argue that the reason it seems ugly is simply because you aren't used to it because so many people DONT write C++ "properly".

If anything I find C++ written like this to be better to read because I can make assumptions quickly about the code and things like the loop body is isolated away from the loop meaning that, with a well named class/functor, on initial look at the code I don't have to worry about what the code is doing.

Maybe in the cold realities of the commerical world good C++ practise goes by the way side, but that is no reason NOT to learn it in the first place. If you know it then you can, at the very start of the project at least, enforce it and use it which then gives you a solid start for the rest of the project. If you don't know it then you'll never use it and you'll never know what you are missing out on.

It also saves you coming across situations I did where I was working with someone who had been in the games industry for 5 years and had NEVER written a virtual function. His method of doing thing was to copy and paste code about when he needed the same functionality in related classes. This lead to code bloat, harder to maintain code and bugs which got fixed in one place and not in another. When we were working on a menu screen system for a game at work I could see a natural solution involving a small inheritance chain and a couple of virtuals; it was my area of code but I was going on holiday for a couple of days, so I outlined it to two guys (one being new to the company, the other the no-virtual guy) using standard C++ phrasing, asked if they were ok with it, which they apprently were, and went off for a long weekend.

I returned to find my design hadn't been implimented, instead a clugged involving C-style callbacks, copy and pasted code and far far more lines than required had been done and worked into the game which lead to me spending the next couple of days detangling the mess and fixing it up so that it was better and leaner code which did more.

So, yes, knowing how to use your language of choice is important and should be done properly.

Share this post


Link to post
Share on other sites
Quote:
Original post by phantom
I returned to find my design hadn't been implimented, instead a clugged involving C-style callbacks, copy and pasted code and far far more lines than required had been done and worked into the game which lead to me spending the next couple of days detangling the mess and fixing it up so that it was better and leaner code which did more.


I really don't think C was a problem here, more so the person who implemented it. C may not have all the nice object oriented features that C++ has but it's far from being hard to manage. Instead of writing spaghetti code he could have thrown the repeated code into a function. Even if your co-worker knew the C++ standard to the T, he'd probably still screw it up.

Share this post


Link to post
Share on other sites
I never said C was the problem, I never even mentioned C in the post. I have nothing against C and I'm at a loss to explain why people are getting the idea that I do. Hell, I doubt his solution was even good C either.

I specifically was talking about how his lack of knowledge about the language was a problem. If he understood C++, even slightly better, then sure he might not have come up with the best design but it would have been better C++ (and would have cost me little to no time to refactor it later if needs be).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this