This is a short tutorial on how to start programming amazing 3d graphics in Java language using Irrlicht IDE. First of all, you have to:
Download necessary packages
Eclipse IDE (http://www.eclipse.org/downloads/) about ~100Mbs.
Jirr (https://sourceforge.net/projects/jirr/) about ~10Mbs.
Download jirr_bin and jirr packages. jirr_3rd_party is used to combine Swing and Irrlicht and you may need it later.
Setup Eclipse IDE
All you have to do is to unzip the archive you have downloaded to any folder. Unzip jirr_bin to any folder. Start Eclipse IDE Go to the folder you have unzipped the Eclipse package to and click 'eclipse.exe' file. If you experience any problems starting Eclipse, check out the eclipse web-site, read FAQs, ask people etc. Eclipse is very very popular and you will not spend much time looking for an answer.
Create the project
Create the folder anywhere you like, name it for example: JirrTest Make a few subfolders:
src
classes
media
lib
Copy:
all DLL files from JIRR distribution package's bin folder to JirrTest root folder;
all files from JIRR distribution package's lib folder to JirrTest/lib folder;
all files from JIRR's media folder to JirrTest/media folder;
Now your new JirrTest folder should look like the one on the picture:
Setup the project in Eclipse IDE
In Eclipse go to File->New->Project->Java Project
Click Next
Click OK and the Finish
Create Demo class
Go to File->New->Class:
Copy and paste the following code (comes with the sources of Jirr in the examples folder):
Code: Select all
package com.leadercode;
import net.sf.jirr.*;
public class Demo {
static {
System.loadLibrary("irrlicht_wrap");
}
public static void main(String argv[]) {
IrrlichtDevice device = Jirr.createDeviceJava(E_DRIVER_TYPE.EDT_OPENGL,
640, 480, 16, false, false, false, null);
System.out.println("idevice = " + device);
String windowCaption = "Java@Hello World! - Irrlicht Engine Demo";
device.setWindowCaption(windowCaption);
IVideoDriver driver = device.getVideoDriver();
ISceneManager smgr = device.getSceneManager();
IGUIEnvironment guienv = device.getGUIEnvironment();
String text = "Hello World! This is the Irrlicht Software engine for Java!";
recti rect = new recti(10, 10, 280, 30);
IGUIStaticText staticText = guienv.addStaticText(text, rect, true,
true, null, -1);
IAnimatedMesh mesh = smgr.getMesh("media/sydney.md2");
IAnimatedMeshSceneNode node = smgr.addAnimatedMeshSceneNode(mesh, null,
-1, new vector3df(0, 0, 0), new vector3df(0, 0, 0),
new vector3df(1, 1, 1));
if (node != null) {
node.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
node.setFrameLoop(0, 99999);
node
.setMaterialTexture(0, driver
.getTexture("media/sydney.bmp"));
}
smgr.addCameraSceneNode(null, new vector3df(0, 10, -60), new vector3df(
0, 0, 0), -1);
final int step = 100;
int counter = 0;
double diff = 0;
long timer1 = System.currentTimeMillis();
long timer2 = 0;
while (device.run()) {
int a = 0;
int r = 100;
int g = 100;
int b = 100;
driver.beginScene(true, true, new SColor(a, r, g, b));
smgr.drawAll();
guienv.drawAll();
driver.endScene();
try {
// Thread.sleep(5);
} catch (Exception e) {
}
counter++;
if (counter >= step) {
timer2 = System.currentTimeMillis();
diff = 1000.0 / ((timer2 - timer1) / (double) step);
counter = 0;
timer1 = System.currentTimeMillis();
text = "This is the Irrlicht Software engine for Java! FPS: "
+ diff;
staticText.setText(text);
}
}
device.closeDevice();
}
}
Voila! Irrlicht is up and running! That's all folks.[/code]