Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How to make a 3D game in C++?

  1. Jan 24, 2012 #1
    I dont want to use any game engine.

    I want to use only C++ to make a 3D Game. How can I do so?

    I have made many 2D games, like chess, connect 4, mario, snake, etc.

    But how do i do 3D and make things like DOOM?

    I use the OLD Turbo C++ Compiler, not Dev C++
    Last edited: Jan 24, 2012
  2. jcsd
  3. Jan 24, 2012 #2
    AFAIK, Turbo C++ doesn't support any 3d Graphics library. Other than that, TurboC++ is a 16-bit compiler & it produces 16 bit binaries. 16 bit stuff doesn't run well on Win7-64 bit edition - you will need to use an emulator.

    Download Visual C++ (I think non-commercial edition is free) or g++ (this is fully free) Then you can use OpenGL or DirectX for programming 3D Graphics.

    If you want to learn more about Computer Graphics - pick up the book by Hearn & Baker.
  4. Jan 24, 2012 #3
    Well, i will have to make a great deal of syntax change to transfer into another compiler.

    Although, then what is the best possible game makeable in TC?
  5. Jan 24, 2012 #4
    Depends. All the standard C++ stuff remains the same. But any compiler specific functions you have used would need to be rewritten. Another thing to remember is that TC is a 20 year old compiler. C++ has changed radically since those times. Most standard code written in TC++ would still work in a modern C++ compiler, but current C++ is far more powerful & offers you really powerful features (templates etc) which will make programming easier for you.

    However, since you say that you have only written 2d games till now, wouldn't you have to scratch from scratch anyway to make 3d games?

    You can do 3D - but you would have to write you own 3d library which would be non trivial exercise. If you are serious about programming, take the plunge and move to a modern compiler & library.

    By the way, I am not a game programmer.
  6. Jan 24, 2012 #5
    First off, you probably do want to use a game engine. Here's a list of game engines suitable for a hobbyist, some free...

    Second off, I recommend using Dev-C++ or Microsoft Visual Studio Express.

    Third off if you just want to start drawing 3D and do not want to rely on a library, the best thing to do is start learning OpenGL or DirectX. What I like to do is use SDL to create an OpenGL window and draw OpenGL inside of that. I use this approach because it means my code is very portable and can run on all operating systems. (If you are careful to write "OpenGL 3.0" or "OpenGL ES", you can even port to mobile phones easily.) There are many OpenGL tutorials on the internet.

    Here is some OpenGL sample code I put on the internet but I am not sure it will help you much if you are a beginner... http://msm.runhello.com/?p=385

    If you really, REAAALLLY just want something that looks like "doom", and you have working 2D drawing already, the original "doom" was done using "ray casting" and rendering in CPU. You can easily do the math for ray-casting yourself and then just splat that to screen with your existing 2D drawing tools. I find a tutorial on raycasting here. However this is not what you want, you want to be using a modern 3D API with GPU acceleration. 3D in CPU will be very slow and not look very good.

    If you have actually written code which will break if you change C++ compilers, then it is bad code and you want to replace it anyway.
  7. Jan 25, 2012 #6


    User Avatar
    Science Advisor

    Hey Algren and welcome to the forums.

    As other posters have pointed out, using a game engine to make games is a good idea. I say its vital because it will take you a very very long time to get things done.

    You should note that DOOM is actually a raycaster. It's not a true 3D rendering application like you see in your modern games. Quake was the one that filled this gap. You can get source code for both binaries from the iD website if you want to learn about this.

    Also as other people have mentioned you will need to switch compilers. There are a few to choose from: Visual Studio is good for its interface. You could use Dev-C++ but I don't like its interface as much as VS.

    Making 3D games is a lot of work. As other posters have pointed out, there are a lot of open-source hobbyist engines out there that allow you to get something up and running fairly quickly, and allow you to integrate game specific code fairly easily.

    The biggest headache is learning the internals and how to get the stage of adding content (art assets or code) to where you can get what you want up and running straight away.

    It takes a little while before you become able to get stuff up and running the way you want it with an existing engine, but its worth it. I wouldn't code your own from scratch unless you really, really want that learning experience. I did this to a large extent and it was a great learning experience for me, but it took years of my life to do this.
  8. Jan 25, 2012 #7
    Really you might be happiest just downloading Unity 3D and using C#. If you already know some C++ it is not a big jump.
  9. Jan 25, 2012 #8


    Staff: Mentor

    there was no mention of IDEs but both Eclipse and NetBeans supports C++ development and provides the same kind of experience as Turbo C++ does complete with code completion and code debugging. Learning these IDEs are crucial for modern programming development.
  10. Jan 25, 2012 #9


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    I'll give the cheeky answer.

    It's impossible: C++ simply doesn't offer you the features to do so. Of course, the same is true of most programming languages.

    However, C++ (and most languages) is flexible enough that third parties can provide you libraries that let you do graphics and other stuff.

    For example, absolutely nothing in conio.h is part of C or C++. Instead, that was a bonus feature a lot of old MS-DOS vendors decided to bundle with their product.
  11. Jan 25, 2012 #10


    User Avatar
    Science Advisor

    Lol, you're a bastard Hurkyl :)
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook