01 package tutorial;
02 import javax.media.opengl.GL;
03 import javax.media.opengl.GLDrawable;
04
05 import de.rico.engine.game.AbstractBaseGame;
06 import de.rico.engine.geometry.Terrain;
07
08 /**
09 * A class that shows how to add a heightmap terrain to
10 * the 3d environment.
11 * @author Frank Bruns
12 *
13 */
14 public class AddHeightmapTerrain extends AbstractBaseGame
15 {
16 private Terrain terrain = null;
17
18 /**
19 * Constructor for the new game.
20 * @param title title for the window bar
21 * @param maxFps maximum possible framerate
22 */
23 public AddHeightmapTerrain(String title, int maxFps)
24 {
25 super(title, maxFps);
26 }
27
28 /* (non-Javadoc)
29 * @see de.rico.engine.game.AbstractBaseGame#initResources(javax.media.opengl.GLDrawable, javax.media.opengl.GL, int, int)
30 */
31 @Override
32 public void initResources(GLDrawable gld, GL gl, int width, int height)
33 {
34 // create terrain object --> resolution = 1, smooth = true
35 this.terrain = new Terrain("./images/misc/heightmap.jpg","./images/misc/heightmap_tex.jpg",1,true);
36 }
37
38 /* (non-Javadoc)
39 * @see de.rico.engine.game.AbstractBaseGame#update(long)
40 */
41 @Override
42 public void update(long elapsedTime)
43 {
44 // update the terrain every frame
45 this.terrain.update(elapsedTime);
46 }
47
48 /* (non-Javadoc)
49 * @see de.rico.engine.game.AbstractBaseGame#draw(javax.media.opengl.GL)
50 */
51 @Override
52 public void draw(GL gl)
53 {
54 // draw the terrain every frame
55 this.terrain.draw(gl);
56 }
57
58 /**
59 * The usual main method. It's the entry point to the application.
60 * @param args argument string
61 */
62 public static void main(String args[])
63 {
64 // create a new game
65 AddHeightmapTerrain game = new AddHeightmapTerrain("Test Game", 100);
66
67 // initialise the camera --> needs to be done!
68 game.initCamera(0f, 10f, 20f, 0f, 0f, 0.1f, 200f);
69
70 // show framerate --> this is optional
71 game.setDisplayFPS(true);
72
73 // finally start the game
74 game.start(game);
75 }
76 }
|