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