Sign in to follow this  
javasirc

Concerned about learning game dev in c++

Recommended Posts

I currently program in C# with XNA. Ive been programming off and on for years. I recently completed a Minesweeper clone. Im thinking about switching to C++, and probably using DirectDraw. My main concerns are that C++ will be hard to get things working, such as creating a window, getting DirectDraw to work, drawing graphics, and espcially developing a loop for the game. In C#/XNA, i downloaded and installed them, and was given the entire base/framework for creating a game (it had Update, Draw, Initialize, Graphics/Content objects, and all that other stuff. All i had to do was learn the functions. With C++, all im given is the 'main()' function. I know i have to get DirectDraw and get that working, but i have no idea how. When i do start programming, i have to set up a window to draw in. No idea how. Then i have the game run at a cirtain framerate so it doesnt consume 100% CPU. No idea how. I was never challanged with any of the basics to game development, only the "content side" because C#/XNA was so mindless and easy. So can anyone explain to me how DirectDraw is set up (the theory of how a library works, not step-by-step directions), and how setting a framerate works? XNA was simply install and it works. Ive tried to use DirectX and C++ many years ago, but i gave up because i didnt know how it worked.

Share this post


Link to post
Share on other sites
I believe DirectDraw is deprecated.

Have you considered using something like SDL or SFML?

Most low level libraries don't have a concept that maps nicely to "setting the framerate". It is simple enough to add, you can call a blocking function that waits for vsync, this locks your framerate to the hardware (unless you draw too slowly). Adding in your own logic for limiting the framerate is pretty simple, and you might need such code anyway if you want to run a fixed time step for your game logic.

Share this post


Link to post
Share on other sites
The main reason i wanted to switch was because i dont feel like C#+XNA is the programming that ive dreamed of. When i think of game programming, i think of starting with a blank file and going from there (aside from using an API to access hardware). C#/XNA doesnt give me the professional feeling, and it feels like im holding Microsoft's hand. I have a lot of mystery behind the framework it starts me with when i make a new program, because i dont know what happens behind the Draw(), Update(), and Initialize() functions.

Take these for example, when i start a new Game project in XNA:
GraphicsDeviceManager graphics;
ContentManager content;

I have no idea what they do aside from letting me load images and draw them.
And theres GameTime gameTime which i dont know much about. All i know is it keeps track of the amount of time that passed, and gives me functions to retrieve that time. But id still rather program that type of thing myself and create my own libraries with those functions, so i know whats going on.

And another reason i want to do C++ is i hear people talking about it being more powerful because its a lower level language, and its the "industry standard language". I dont know whats more powerful about it, but it makes me more attracted to it. I dont want to make a game fast, i want to thoroughly learn a language that i can do a lot of things with, and feel confident with it.

I should have mentioned that i have used c++ before. I learned it in 10th grade but i wasnt the best at it. I watched a long video tutorial recently, and coded as i relearned, and i did fine. I know the syntax and such to c++ but i never used an API/library with it. I also have a stack of c++ books that ive accumulated since i started programming.

I guess the main reason i want to do c++ is because it seems like a more professional language and i do all the programming. And not knowing exactly what the .NET framework and XNA does leaves me with a lot of mysteries, which kind of pushes me away and makes me lose interest in it.

Share this post


Link to post
Share on other sites
C# and XNA is definetly not going away, especially with Microsofts recent announcement that it will be used to make games on PC, xbox and the new windows phon 7. I saw a video clip of someone at microsoft giving a presentation playing the same game on a PC, xbox, and windows phone 7 because it used xna across the board.

As far as C++, there are lots of different API's you could use to program a game not just directX. I have experience with Allegro and SDL. While these are i guess "not as mature or professional" as directX, picking one of them would be a good start to get your feet wet with game programming in C++. Then the transition to the more complex DirectX would be easier.

Hope that helps a little bit

Share this post


Link to post
Share on other sites
Have you considered using SlimDX? That would give you a similar interface that DirectX has while still being able to use C#.

Share this post


Link to post
Share on other sites
You should definitely learn C++ game techniques/APIs.

You'll learn the pros and cons a lot better that way, and make up your own mind about which is better *for you*, *for any given task*. You can also put it on your resume which can't hurt.

For programmers, more knowledge is almost always a good thing! DO IT!

Share this post


Link to post
Share on other sites
Quote:
Original post by Nypyren
For programmers, more knowledge is almost always a good thing! DO IT!


The OP will gain more useful knowledge actually making games in XNA than fighting C++.

Quote:

You can also put it on your resume which can't hurt.


If you haven't done it professionally, it doesn't count. I'm exaggerating of course, but not much. If you can't back it up with professional references or a slick, easy to access demo it's not going to mean anything on a resume to most places.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
Quote:
Original post by Nypyren
For programmers, more knowledge is almost always a good thing! DO IT!


The OP will gain more useful knowledge actually making games in XNA than fighting C++.


If he fights C++ he will more clearly understand why the C# alternative is there and how they differ.

Quote:
Quote:

You can also put it on your resume which can't hurt.


If you haven't done it professionally, it doesn't count. I'm exaggerating of course, but not much. If you can't back it up with professional references or a slick, easy to access demo it's not going to mean anything on a resume to most places.


Not everyone's applying to huge companies that would ignore non-professional experience. It seemed to work fine on my resume. I didn't have any professional C++ experience before my first game development job, yet I'd been using it for years on top of my college degree. Of course I could also back it up strongly during the interview as well.

Share this post


Link to post
Share on other sites
Thanks for the replies. Im probably going stick with C# for now and try switching to SlimDX, which mumbo brought up. I dont plan on being a professional programmer, so i guess its not that important for me to do c++.

Share this post


Link to post
Share on other sites
Quote:
Original post by javasirc
Thanks for the replies. Im probably going stick with C# for now and try switching to SlimDX, which mumbo brought up. I dont plan on being a professional programmer, so i guess its not that important for me to do c++.

Only reason to really bother with C++ (or learning any programming language that isn't garbage collected for that matter)is if you plan on programming for the iPhone to ease the pain. Just like with C++ you'll have to learn to clean up after yourself since there is no garbage collector to clean up after you on the iPhone either :(
Technically, Objective-C 2.0 ,which is the latest version of the native programming language used for iPhone programming now supports garbage collection but only on Mac OS X 10.5 and later and not on the iPhone!



[Edited by - daviangel on March 10, 2010 7:22:31 PM]

Share this post


Link to post
Share on other sites
Quote:
Original post by mumbo
Have you considered using SlimDX? That would give you a similar interface that DirectX has while still being able to use C#.


I second this. You can do all the "lower level" stuff that is hidden away from you with XNA without having to "battle" with learning C++ at the same time.

Once you've got all that understood conceptually you can always give it a go in C++. It'll be much easier if you understand what you're trying to do and don't know the language, rather than not know what you're trying to do AND not knowing the language.

Share this post


Link to post
Share on other sites
Quote:
Original post by daviangel
Quote:
Original post by javasirc
Thanks for the replies. Im probably going stick with C# for now and try switching to SlimDX, which mumbo brought up. I dont plan on being a professional programmer, so i guess its not that important for me to do c++.

Only reason to really bother with C++ is if you plan on programming for the iPhone. Just like with C++ you'll have to learn to clean up after yourself since there is no garbage collector to clean up after you on the iPhone either :(


But most of the time you don't (have to) clean up things explicity in C++, whereas in C# you are forced to every time you use a disposable object. (sidenote: no, in using(var x = new Foo()), it is still explicit).

E.g., in a pet-project of mine (which claims roughly 30,000 LoC right now), there are only one or two deletes in total, in very specific places where I needed to squeeze out some more free bytes and performance. The rest (e.g. syntax-trees and optimizers, scene-graphs, etc.) is handled by smart pointers or not using reference types at all, and thus by the concept of RAII.

So, to add some other problem domains where C++ might be relevant: Systems programming, Non-GPU Graphics programming in general, Non-GPU Number crunching in general, Programming where you must exploit available resources.

Share this post


Link to post
Share on other sites
Quote:
Original post by daviangel
Only reason to really bother with C++ is if you plan on programming for the iPhone. Just like with C++ you'll have to learn to clean up after yourself since there is no garbage collector to clean up after you on the iPhone either :(


Dev for the iPhone is done with Objective-C, not C++.

Share this post


Link to post
Share on other sites
I'd switch to C++. The problem is C# is an interpreted language a similar way that Java is. So you won't have the inherent speed you would normally get from an optimized, compiled executable.

If your goal is to make a real simple game, then C# is fine. But if you can't leave well enough alone and want to keep adding cool features that rely on the cpu (collision detection, AI, shadow volume creation, etc), then you're going to run out of FPS soon.

But if you are going to make a simple game, then I would switch to Java and OpenGL. Then at least your game could be run on Windows, Mac and Linux.

Share this post


Link to post
Share on other sites
Quote:
Original post by howie_007
I'd switch to C++. The problem is C# is an interpreted language a similar way that Java is. So you won't have the inherent speed you would normally get from an optimized, compiled executable.

If your goal is to make a real simple game, then C# is fine. But if you can't leave well enough alone and want to keep adding cool features that rely on the cpu (collision detection, AI, shadow volume creation, etc), then you're going to run out of FPS soon.

But if you are going to make a simple game, then I would switch to Java and OpenGL. Then at least your game could be run on Windows, Mac and Linux.

I think you haven't a clue about what you are talking about. Only the last line of your post is true, C# will limit your portability more than Java.

You can make reasonably complex games in C# or Java. While you might not be able to make a modern AAA game with them, that point is moot because you won't be doing that in C++ either, unless you have access to a large team of developers and/or license expensive middleware.

In any case, if the OP is still at the stage of making minesweeper, he won't be making games that will challenge modern hardware for quite some time. You don't even need to challenge the hardware to make a fun game.

Share this post


Link to post
Share on other sites
Quote:
Original post by howie_007
I'd switch to C++. The problem is C# is an interpreted language a similar way that Java is. So you won't have the inherent speed you would normally get from an optimized, compiled executable.
You didn't even bother to qualify this statement. I recommend you be ignored. I am rating you down accordingly.

Share this post


Link to post
Share on other sites
Quote:
Original post by nobodynews
You didn't even bother to qualify this statement. I recommend you be ignored. I am rating you down accordingly.
I figured this was common knowledge.[oh] Below is your verification.

What's the point of C#?
Here is the relevant text from the above link.[imwithstupid]

C#, as part of the .NET framework, is compiled to Microsoft Intermediate Language (MSIL), which is a language similar to Java's bytecode. MSIL allows C# to be platform independent and runs using just in time compiling.

Share this post


Link to post
Share on other sites
Quote:
Original post by howie_007
If your goal is to make a real simple game, then C# is fine. But if you can't leave well enough alone and want to keep adding cool features that rely on the cpu (collision detection, AI, shadow volume creation, etc), then you're going to run out of FPS soon.


This game was written entirely in C#. It's not the best game in the world but contains all the features you claim will make C# "run out of FPS"

http://pc.ign.com/objects/692/692397.html
http://en.wikipedia.org/wiki/Arena_Wars

[EDIT: redacted lame attack]

Game developers primarily use C/C++ for several reasons:
1) all of their legacy code is C/C++ and starting from scratch is rarely an option
2) game consoles have historically only provided C/C++ compilers. The 360, however, now has support for C# through the XNA framework and a huge portion of the XBLA games are now made with that language.
3) most engineers know C/C++ and many engineers are lazy fools who refuse to learn new languages

JIT compiling removes a lot of the penalties of bytecode. On an absolute scale, sure, there are things in C# that will be slower. In the practical case it rarely makes a difference. Usually it's the GPU that slows down games, not the CPU and C# versus C++ makes exactly zero difference on the GPU.

A random example of how CPU speed of a language doesn't matter all that much: Unreal has a scripting language called UnrealScript it's at least an order of magnitude (10x) slower than writing in native code. However, a vast chunk of game logic is run even with that pathetic excuse for a language. Would it be more performant to scrap it and use native code? Absolutely! Why don't they do it? It rarely makes difference in framerate since the Unreal games are typically GPU bound. The productivity gains of UnrealScript because it doesn't need to be compiled outstrip the performance concerns. Obviously not totally relevant but just a pointer that raw performance is not always the correct metric.

The purpose of a language is to make software. Sometimes a low level language is the right choice, sometimes it isn't. Much like you don't limit yourself to just a hammer at home, you shouldn't limit yourself to one language in programming.

-me

Share this post


Link to post
Share on other sites
Quote:
Original post by howie_007
C#, as part of the .NET framework, is compiled to Microsoft Intermediate Language (MSIL), which is a language similar to Java's bytecode. MSIL allows C# to be platform independent and runs using just in time compiling.
Alright, C# is similar to Java's bytecode. So let's look at Java performance then.
Quote:
from the link
The average performance of Java programs has increased a lot over time, and Java's speed might now be comparable with C or C++. In some cases Java is significantly slower, in others, significantly faster
Hence the need to qualify your statements. There are few absolutes in computing.

I was probably a bit too harsh with my response and I am rating you back up!

Share this post


Link to post
Share on other sites
I did find learning the low level parts of windows, message dispatch and the game loop to be inspiring. You can at least be able to appreciate the wrapping C# does to these concepts. In addition, in C/C++, you know exactly what's running around in the target PC. Again, this might not be necessary if you're making just another game, but if you make games because of the technical challenge, there is indeed a lot to learn.
If you're not interested, well, you've made the right choice then sticking to what you know for now.

Share this post


Link to post
Share on other sites
Quote:
Original post by Telastyn
Quote:
Original post by Nypyren
For programmers, more knowledge is almost always a good thing! DO IT!


The OP will gain more useful knowledge actually making games in XNA than fighting C++.

Quote:

You can also put it on your resume which can't hurt.


If you haven't done it professionally, it doesn't count. I'm exaggerating of course, but not much. If you can't back it up with professional references or a slick, easy to access demo it's not going to mean anything on a resume to most places.


One or two demos no, but having familiarity with it would. However, I agree with you that the OP should stick with C# unless there's a really good reason to start from scratch. Like to start from a blank file as supposed to using base code from a framework isn't any less of programming, it's much more productive. Frameworks are built to make our lives easier and so that we can focus on the important parts of a project. Not the tedious stuff.

Share this post


Link to post
Share on other sites
Quote:
Original post by nobodynews
The average performance of Java programs has increased a lot over time, and Java's speed might now be comparable with C or C++. In some cases Java is significantly slower, in others, significantly faster
This is true. You now have to ask the question why is this? How did it get faster? Did the Java people somehow figure out the error of their ways? It's the same answer for C#. The reason is if you're making library calls in Java or in the case of C# .NET framework, you're executing compiled native binaries. Back during the early days of Java and C#, the native binaries were few and far in between. Games are very unique and the more code you have to write specific to your game, the slower your game gets.
Quote:
Original post by nobodynews
I was probably a bit too harsh with my response and I am rating you back up!
I appreciate that.[smile]

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