Sign in to follow this  
Andrew6655

DirectX and Object oriented programming

Recommended Posts

Andrew6655    122
Hello, I am learning DirectX from a book which tells you not to use OO concepts as they will slow the program down. But I (and presume anyone else) would find it difficult to program a whole game in one class. Currently, I am creating my game as a Win32 app (as opposed to an MFC one) and #including the C++ header and source files which deal with the game logic. Should I use MFC or Win32? What is the best approach to gaining smooth performance? Hope someone can help. Andrew

Share this post


Link to post
Share on other sites
jff_f    372
Quote:
Original post by Andrew6655
I am learning DirectX from a book which tells you not to use OO concepts as
they will slow the program down.
But I (and presume anyone else) would find it difficult to program a whole
game in one class.


What book is that???... Unless this was only aimed at beginners (which never heard of object oriented before) that will never evolve I'd say that's wrong. Usually beginners evolve, learn things, improve themselves and their use of the libraries and language concepts only gets better.

According to my experience the code I wrote in an object oriented manner was more efficient. It's probably due to the fact that I have a hard time figuring how not to use objects since they were always around me.

I know that on some gaming consoles and older PCs, having too many virtual functions (big virtual table if you know what it is ;)) makes your code slower. But I never saw anything against the use of object oriented programming, use it wisely.

DirectX itself is using OO concepts, almost everything is just an interface and you call the API's function to create the objects (a lot like factories). So if there was a performance issue there it wouldn't have been used.

Quote:
Original post by Andrew6655
Currently, I am creating my game as a Win32 app (as opposed to an MFC one)
and #including the C++ header and source files which deal with the game
logic.
Should I use MFC or Win32? What is the best approach to gaining smooth
performance?


Depends on your knowledge of Win32 of MFC and what do you want to achieve. If you can work with both and only creating a window to render to, I'd suggest to stick to Win32. I think that MFC adds too much junk when all you need is create a window to render to. If you want buttons, list boxes, etc (like in the tools) use MFC (or other similar libraries).

I never tried rendering from a MFC window (or even profiled MFC code) so I can't comment on the performance. MFC only wraps Win32 anyway so the performance is probably close (just a small overhead for the wrapping functions).

JFF

Share this post


Link to post
Share on other sites
daviangel    604
Most people will wrap up their directx stuff in a class once they know what they are doing since all the directx stuff isn't object oriented anyways.
Most books start off showing how to use directx with win32 so you can see all the details of how it's done. But once you learn it there really is no reason to put yourself through all that grief.
You should avoid MFC if you can since it's looked upon as a plague among programmers.
Performance differences if you are using latest MS VC++ won't be noticable.

Share this post


Link to post
Share on other sites
beebs1    398
Just to clarify a few parts of this post.

Quote:
Original post by daviangel
all the directx stuff isn't object oriented anyways.


DirectX is object-oriented, with the exception of the D3DX library and XInput. However, it's still a good idea to wrap much of the functionality into your own classes/engine once you feel comfortable with it.

Quote:
Original post by daviangel
You should avoid MFC if you can since it's looked upon as a plague among programmers.


Straight Win32 is usually fine for most games, but if you really need classes for Windows then I believe Microsoft recommends using .NET instead of MFC.

Hope that was helpful - daviangel, if I got the wrong end of the stick with your post then apologies :)

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