What language and programming environment should we use for 3d programming?
If you are a beginner to programming, see here.
What are the options? If we just want to display a 2d representation of the points it would be relatively easy to program in any reasonably efficient language such as either C++ or Java. If we want to display 3D graphics in real-time, for instance in a game or 3D simulation, then we need a language and environment that runs fast and we also need efficient 3D libraries.
- Use C++. There is quite a steep learning curve, because, not only do we have to learn C++ (the easy part!) we also have to understand the OpenGL library (GLUT) or Direct3d and any other libraries you may need.
- Use Java and Java3D - Much easier to learn, this is what I use, JBuilder6 is for Java, however the downside of this is that Java can run slower and it is more difficult to distribute Java applications to other people. There is a standard extension to Java which supports 3D display, this is Java3D.
- .Net languages such as C# or Visual Basic which (2003 versions/ net1.1) now support directX 9.
- Write the program as a script to drive VRML or the 3D program that you are using.
Graphics standards and class library's
- OpenGL tends to be used by both graphics and CAD programs and games.
- GLUT is a library for using OpenGL from C++.
- Direct3d is less accurate, and tends to be used by games.
- OpenGL is supported on Windows, Macintosh, UNIX workstations, PCs, X-Box, linux, etc.
- Direct3D is supported only on Microsoft windows platforms and X-box.
- I think the other games platforms tend to use their own graphics interfaces.
For more information about this please see this open forum discussion
Commercial graphics and/or physics engines
Another option to consider, if if you have plenty of money to spend on the
project is buying in a commercial graphics and/or physics engines, there would
be royalties to pay.
To build a commercial game from scratch. This would allow you to put more of your time into the creative side, also these engines would come with interfaces for the different games platforms.
One possibility is the use of Quake III Arena (TM), which is a game engine for shoot-em type games, which uses OpenGL.
The 3D gamemaker - Allows simple 'shoot-em-up' type games to be built without any programming from the elements provided. You can use your own characters in the game, provided you can find a way to build them in Microsoft .X file format.
- Other commercial game generation software for home use
- Darkbasic is a good choice, see comments from Giles
Java is supported on many platforms such as Windows, UNIX, Linux, etc. The source code is compiled onto code which runs on a Java virtual machine (JVM). Sun provides virtual machines for the platforms supported.
The syntax of the language is derived from C.
This is much the most productive programming environment that I have used. The language and the class libraries are all integrated together, so everything feels integrated and works well together. Also features such as garbage collection and lack of pointers means that memory leaks and null pointer type problem are less likely.
At the moment Java does not have any built in support for displaying 3D. In order to use a 3D library such as OpenGL we need a java 'wrapper' which has some native code to call OpenGL. There are a number of possibilities:
- Java3D - This is an 'extension' to Java, which mean that it is not distributed with java and requires a separate download. Java3D is both a OpenGL or Direct3D wrapper and a scenegraph model. Sun have stopped developing this and its future is in doubt, there is a possibility it may become open source?
- JOGL - This is just an OpenGL wrapper, so it is a much smaller download than Java3D. There is a possibility that in future that it may be distributed with Java.
At the moment there are some downsides to the use of Java for 3D.
- Performance - The JVM is an interpreter, and this slows down performance, Just In Time (JIT) compilation instead of interpreting may help if each part of the code is run many times. For large 3D models, there may also be issues with the memory size required, this has to be setup at runtime. Also the vector and matrix library may not make use of the SIMD instructions built into most computers machine code.
- Distribution - Use of Java3d requires a Java2 virtual machine, most PCs don't have this, current browsers still use an older JVM. Therefore to download from the web and then run a java application on most PCs would require: download the program, and download Java 2 and download Java3d. The average user would not be prepared to do this.
Therefore Java is relatively easy for the developer, but not very practical for the end user.
external links: http://www.javagaming.org/
JBuilder - There is also a free version of Jbuilder at borland website . However its licence conditions are quite restrictive so you may prefer another java IDE.
This is a Microsoft specific framework. Like Java it compiles to intermediate code. The advantage of .NET is that it allows you choose between C++, C#, Visual Basic and other languages, and even to mix these languages. There are some Linux versions such as mono, I don't know how complete or reliable they are or if they will catch on, however the choice of platforms is less than Java.
Programs written for this framework will be distributed as intermediate code (CLI = Common Language Infrastructure). This is interpreted (or more accuately just-in-time compiled) when run.
The original 2002 versions of these programs do not have a library which supports activeX or OpenGL, so the only way to use these versions is to use anOpenGL .NET wrapper which can be included in your .NET program as an axHost component.
The 2003 versions of these programs (.net version 1.1) now support directX 9 without the need for any 3rd party plugins.
The 2005 versions of these programs now use .net version 2.0. This means that the code built using the 2005 versions will only run on PCs with .net 2.0 installed.
C#Visual C# .NET for Microsoft Platforms only.
This is a Microsoft language that uses the ideas from Java. For instance it uses a virtual machine and a garbage collector. The main difference is that the intermediate code (CLI = Common Language Infrastructure) is not so closely tied to C#, so the virtual machine can be used by other languages.
There are different ways to write code using C# such as:
- Use the open source Mono development environment on Linux.
- Use Microsoft Express 2005 edition, this is free for a year (at the time of writing). However it is a very large download and reqires .net 2.0 on any machines which run the code.
C++Visual C++ .NET for Microsoft Platforms only.
C++ tends to be the language of choice for games programmers.
C++ and C tends to be complied directly to the machine language of the platform being used. Also C and C++ allows you to write in a way that is quite close to most machine code (incrementing pointers, etc.). Because of these things the code produced can be very efficient and run very fast. However is is very easy to create bugs, such as not releasing resources leading to memory leaks, or not setting pointers properly, etc.
There is a very steep learning curve for the programmer, who has to learn the language itself, the libraries, whatever 3D library is used, also any libraries for interface components. These libraries don't always 'join up' and so it takes a long time to learn where everything is, and in some cases the libraries may not do what you want and you may have to resort to understanding the APIs used and calling them directly. However there is not much you cant do in C++ if you can master the complexity.
So there are a lot of choices to be made about what platform and what class framework to use. These choices include:
- Microsoft Visual C++ with MFC - MFC is a set of class libraries to support widows, buttons, text boxes, controls etc. If you are writing a game MFC would not be needed if you want the screen to consist of a 3D window only. Superseded by .NET unless you need features not yet supported by .NET such as OpenGL or direct3D.
- Microsoft Visual C++ with ATL - Active Template Library is a lightweight alternative to MFC designed to be included in Web pages, put together to compete with Java applets without the security, now superseded by .NET.
- Microsoft Visual C++ with OpenGL and GLUT (cant yet be used directly with .NET).
- Microsoft Visual C++ with direct3D.
- Microsoft Visual C++ NET - This restricts you to a subset of C++ (no multiple inheritance for example). Also it does not support OpenGL. However I have written a wrapper to allow provide a OpenGL control in a .NET program.
- Linux + Gnome + Glade is a free user interface builder for GTK+ and GNOME.
- Linux + KDE + KDevelop - C/C++ IDE (information about C++ programming with KDevelop here)
- Linux + OpenGL
Because most PCs already have have the code for the 3D libraries installed, programs compiled from C++ to the native platform can be much easier for the user to install than Java programs. The user only has to download the code itself from the web in the form of an .EXE file and and run it. Provided they trust the site where the code came from!
If you want really fast and efficient code then, you might be able to code it yourself using an assembler to produce faster code than a compiler would produce.
It would only be worth doing this for time critical parts of the program that are run frequently.
One example, where writing machine code by hand might help is to make use of the machine code extensions intended for 3D. These are SIMD Single Instruction Multiple Data instructions such as MMX and 3Dnow, which can do multiple integer or floating point operations at a time.
Visual BasicVisual Basic .NET for Microsoft Platforms only.
|Dark Basic Professional Edition - It is better to get this professional edition|
Visual Basic is easier to learn than some other languages but it may not be as well structured, and may not scale up so well as the program gets bigger. It may be either interpreted or compiled, but it will not produce such efficient code as C++. 3D libraries such as Direct3D can be called by the use of ActiveX components.
Microsoft Express 2005 edition, is free for a year (at the time of writing). However it is a very large download and reqires .net 2.0 on any machines which run the code.