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 create game that renders 3D objects fast?

  1. Mar 11, 2015 #1
    I was interested in making a game that renders 3d objects in the way they would look like in viewing them in real life. Rendering 3d objects takes lots of memory and processing power, and it may lag easily. So, I was wondering, what should I do to maximize efficiency in rendering 3d objects? What should I NOT do (things that aren't efficient or may cause lag) when trying to make the source code for the render?
  2. jcsd
  3. Mar 11, 2015 #2
    This is a pretty big topic. What tools are you using or have experience in? Have you read up on any 3D engines?
  4. Mar 11, 2015 #3
    I am using java jdk 8 and I am using the IDE: eclipse 4.4 standard.
  5. Mar 12, 2015 #4
    Most dont do it in Java. 3d games work off GPUs, which are massively parallel clusters of little processors. People code for them in C/C++ and write little kernels for each little processor. At a higher level, people use Gaming Engines, which abstract all this. I know if you Google you can find an open source gaming engines, and some might have Java wrappers. But dont try to roll your own in Java its just too slow.
  6. Mar 12, 2015 #5

    Filip Larsen

    User Avatar
    Gold Member

    If you are not restricted to use Java (that is, if you are not trying to add 3D to an existing application or something) I would second Foolality's comment and recommend you look into other tools. For instance, you may want to check out Unity [1] which comes in a Personal Edition that is free to use. I haven't used it myself, but a coworker who is a part time game developer recommends it highly.

    [1] http://unity3d.com/5
  7. Mar 12, 2015 #6
    Only use unity if your not willing to think, if you want to go in depth into game design I advise a proper engine, like direct x if you know c++ or xna /monogame if you know c#. since you know java you could go with lwjgl. That way you have alot more control, if your having lag issue you can come up with your own solution to solve it, and you get the satisfaction of building a game from scratch and getting to know how everything works.
  8. Mar 13, 2015 #7
    Have you done any reading about graphics theory? Understanding the math and how points get transformed through the pipeline will help you know what to optimize and how to best do it, programming languages aside. There are a lot of books on the subject as well and there's lots of techniques for speedup on the software side.

    As for what language to use, it's really up to you. Most languages will support OpenGL or DirectX, so you'll end up using their prebaked functions to manipulate things although newer versions allow you get control of the shaders to make some really cool effects. The shaders are written in their own C-like language (either GLSL or HLSL) but they're usually passed to the rendering program as a string, so it's kind of language-independent. I've seen a few games and things written in Java, so you can do that if Java's your preference, but I hear the Java game programming community's a pretty small group.

    As for using prebuilt tools, there's also a pretty big divide in the game programming community when it comes to actually writing games. Everyone's in basically in one of 2 camps: the people interested in the algorithms that games use, or the people interested in actually writing a game. The former group like to implement their own algorithms for everything and tinker around with things like optimization or speed. The fun for them is the exploration and learning about the methods and the game itself (playability, art, etc.) becomes a secondary objective. The latter group is interested in actually producing a game for the public (or a small private group). They love the challenge of making something function and playable and don't necessarily care about using pre-built tools like rendering or physics engines. These groups aren't necessarily exclusive groups and they're not usually at odds with one another. In fact, the former group usually ends up creating the tools for the latter to use. It's just mainly a question of focus.
  9. Mar 15, 2015 #8
    To be honest, I am still learning to apply 3D rendering. So would C++ be better for faster 3D rendering than Java?
  10. Mar 15, 2015 #9
    Yes, C++ is faster than Java in practically any application.
    Also, I think that creating 3D objects and coloring them is done by the GPU. I don't know how deep you want to go into this. But you can either take advantage of the functions of an GPU or you make a program that also does the work of the GPU so you can maybe monitor the efficiency of your renderer? I am not too sure about your options here.
    Last edited: Mar 15, 2015
  11. Mar 16, 2015 #10
    If you are looking to create fast 3D games I would recommend using Unity 3D big time, not only is it easy but some really popular high quality games have come out of it :)
  12. Mar 16, 2015 #11
    Sadly, Martin's correct. It's cheaper for game developing companies to use third-party generic game engines (like Unity, ugh) rather than developing their own. This eventually leads to unfixable bugs.

    You can get rich by spamming Unity 3D crap games onto PC game distribution networks, like Steam. Most people who try to do it the low-level way quit when they realize it's actually quite hard.
  13. Mar 17, 2015 #12
    Indeed. Obviously most people would prefer to develop their own engine etc... However, especially for you icecubeceast it's just not practical. Though Unity 3D may seem crap it does have its positive sides, at least it's best for what you want!
  14. Mar 17, 2015 #13

    Filip Larsen

    User Avatar
    Gold Member

    Developing a (good) game engine is definitely not a trivial task and it is very rarely feasible to develop an engine "just" to support your own game. Regarding bugs I would say it is a fair claim that you need access to a very experienced development team in order to expect them to make fewer bugs in a newly created engine compared to the same team having to just manage getting around the few well-known bugs and short-comings that some of the popular engines have. This is pretty much a standard trade-off in the whole software business and the reason so many good libraries, engines and frameworks exists.

    Anyone wishing to develop a game engine because the think they can do better ought to at least have an idea about what they are up against. Anyone developing a game engine because they think it would be fun to do so should probably also be inspired by how other engines are structured. And anyone wanting to do both (have fun and make a competitive engine) should probably try work on some of the open source engines [1] or apply for a job position somewhere.

    [1] http://en.wikipedia.org/wiki/List_of_game_engines
  15. Mar 18, 2015 #14


    User Avatar
    Science Advisor

    Hey icecubebeast.

    I used to do game developing for what its worth.

    The best advice I can give you is to learn about scene classification and computational geometry.

    Graphics cards are designed to process triangles extremely fast. They have vertex and fragment engines that are hugely parallelized and this is what all graphics cards render to the screen if they use the accelerated capabilities of the GPU.

    What you need to do is to figure out a way of organizing your scene so that the optimal amount of triangles are processed. The scene organization techniques are varied but if you can classify the space easily so that you can filter out the triangles that don't have to be drawn then this is what will save a lot of time.

    In addition to this I would also point out that GPU memory (on board memory) is getting bigger and bigger so uploading vertex and fragment data to the GPU can be done which also adds rendering benefits since accessing that memory rather than simply uploading it every frame will save you a lot of time.

    You will need to learn how to classify spaces which involves linear algebra, vector algebra, and all kinds of geometry.

    The easiest way to classify a space is to divide into a half-space which involves a plane. Learn about planes first and then learn about scene classification and computational geometry and take it from there.
  16. Mar 18, 2015 #15
    Would it be easier to use java libraries to make code for 3D rendering?
    @Filip Larsen Are you referring to developing game engines from scratch or using existing/downloaded java libraries?
  17. Mar 18, 2015 #16


    User Avatar
    Science Advisor

    I wouldn't use Java libraries unless they have been compiled in something like C++ and optimized with direct calls to graphics interfaces (like OpenGL).

    If you have all the optimized code done properly then Java may be OK. If you don't then you will be looking at a really bad slide-show as opposed to a smooth rendering of your virtual environment.

    I would suggest you learn C++ and get one of the many engines available and use/modify that particular engine and scripts that they use.

    Developing engines from scratch take years and its often better to find a well developed one that is easy to modify for your purposes and go that route.
  18. Mar 18, 2015 #17
    There are some pretty good 3D engines out there which are very efficient, which means there is need to do all the work from scratch.
    However I realize that promoting a particular one could get me in trouble, so I'll just mention that one of the best ones is actually free if you are not a commercial organisaton.
    The free version has limitations of course, but almost everything you need to get started and a long way beyond that are there
    A bit of googling will probably get you to what I am referring to.
  19. Mar 19, 2015 #18

    Filip Larsen

    User Avatar
    Gold Member

    Yes, using a suitable library will be the easiest way to draw a 3D scene in any language, including Java. Likewise, using a game engine will be the easiest way to make a game (with a game engine being more of a framework and typically contain much more support for games than just the 3D rendering libraries).

    I was commenting on the notion seemly made by several posters here, that using an engine or a library is a "bad thing". Yes, using a particular engine or library may easily have some negative issues associated (not necessarily all of a technical kind) which anyone using them would be wise to be aware of, but you still get a lot more than if you have to develop this yourself from scratch. And even more so if the engine or library is free or open source.

    I would recommend that you find a library or engine that supports what you want to do or learn about, without forcing you to handle issues you do not want to learn about. For instance, if you are comfortable with Java and just want to learn how to render a 3D scene in Java then by all means choose a Java library like Java3D [1,2]. It won't get you an industry-strength game engine but if you are just trying to learn about 3D then it may not matter much since virtually any library have to map to a standard like OpenGL [3] or Direct3D [4] anyway. If language is not important to you then, as been said a few times already, you will probably have more libraries and engines to choose from if you go with C++ (for engines, see the list [5] I mentioned earlier).

    And, of course, feel free to combine this with a good textbook on 3D game graphics if you want to dig into some of the algorithms. I remember 3D Game Engine Design [6] as a good algorithm book even if the title is somewhat miss-leading.

    [1] https://en.wikipedia.org/wiki/Java_3D
    [2] https://java3d.java.net/
    [3] https://en.wikipedia.org/wiki/OpenGL
    [4] https://en.wikipedia.org/wiki/Direct3D
    [5] http://en.wikipedia.org/wiki/List_of_game_engines
    [6] 3D Game Engine Design, Dave Eberly, Taylor & Francis, 2007
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook