diff options
author | Peter Wu <lekensteyn@gmail.com> | 2014-01-09 15:23:43 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2014-01-09 15:23:43 +0100 |
commit | 6a88bc222d2805257093fc25ee8a46203ac0218a (patch) | |
tree | 0658bef9265dad6c04c9c1bd5af6ef53fcccdd48 | |
parent | 9c173b3c4c458a180779002012bb3033b868ce1b (diff) | |
download | 2iv60-robots-6a88bc222d2805257093fc25ee8a46203ac0218a.tar.gz |
Allow textures to be disabled
Minor other change for consistency, even though 180 + 180 is a full
rotation, use 180 - 180 to emphasize "revert".
-rw-r--r-- | src/RaceTrack.java | 8 | ||||
-rw-r--r-- | src/Robot.java | 12 | ||||
-rw-r--r-- | src/RobotRace.java | 39 |
3 files changed, 49 insertions, 10 deletions
diff --git a/src/RaceTrack.java b/src/RaceTrack.java index 3865b3d..01a28c2 100644 --- a/src/RaceTrack.java +++ b/src/RaceTrack.java @@ -148,7 +148,9 @@ class RaceTrack extends BetterBase { Vector norm_up = Vector.Z; // Set brick texture - race.getBrickTexture().bind(gl); + if (race.enableTextures) { + race.getBrickTexture().bind(gl); + } // Draw track walls gl.glBegin(GL_QUADS); @@ -181,7 +183,9 @@ class RaceTrack extends BetterBase { glVertex(point_B); gl.glEnd(); - race.getTrackTexture().bind(gl); + if (race.enableTextures) { + race.getTrackTexture().bind(gl); + } // Draw track itself gl.glBegin(GL_QUADS); diff --git a/src/Robot.java b/src/Robot.java index d050b6f..778b2e5 100644 --- a/src/Robot.java +++ b/src/Robot.java @@ -103,16 +103,20 @@ class Robot extends BetterBase { // Draw the robot, everything is relative to the center of torso. // Static parts (that do not animate): - race.getTorsoTexture().bind(gl); + if (race.enableTextures) { + race.getTorsoTexture().bind(gl); + } drawTorso(); // Rotate the head so it looks forward (for texturing) gl.glRotatef(180, 0, 0, 1); - race.getHeadTexture().bind(gl); + if (race.enableTextures) { + race.getHeadTexture().bind(gl); + } drawHead(); // Rotate back so the other robot parts are facing the right direction - gl.glRotatef(180, 0, 0, 1); + gl.glRotatef(-180, 0, 0, 1); unbindTextures(); @@ -191,7 +195,7 @@ class Robot extends BetterBase { // Depending on if it needs to be textured, use our own method // or the glut solid cube. - if (isTextured) { + if (isTextured && race.enableTextures) { drawCube(); } else { glut.glutSolidCube(1); diff --git a/src/RobotRace.java b/src/RobotRace.java index cc48694..ee1fc86 100644 --- a/src/RobotRace.java +++ b/src/RobotRace.java @@ -142,6 +142,11 @@ public class RobotRace extends Base { private final Random random = new Random(); /** + * Whether textures are enabled for surfaces. + */ + boolean enableTextures; + + /** * Constructs this robot race by initializing robots, camera, track, and * terrain. */ @@ -194,6 +199,9 @@ public class RobotRace extends Base { // Initialize global OpenGL context. BetterBase.setGL(gl); + // enable textures if supported + toggleTextures(); + // Enable blending. gl.glEnable(GL_BLEND); gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -530,19 +538,23 @@ public class RobotRace extends Base { } public Texture getTorsoTexture() { - return this.torso; + assert torso != null; + return torso; } public Texture getHeadTexture() { - return this.head; + assert head != null; + return head; } public Texture getBrickTexture() { - return this.brick; + assert brick != null; + return brick; } public Texture getTrackTexture() { - return this.track; + assert track != null; + return track; } /** @@ -583,10 +595,29 @@ public class RobotRace extends Base { case KeyEvent.VK_I: /* print Info */ System.err.println("GlobalState: " + robotRace.gs); return true; + case KeyEvent.VK_T: /* toggle Textures */ + boolean state = robotRace.toggleTextures(); + System.err.println("Textures are " + + (state ? "enabled" : "disabled")); + return true; default: return false; } } }); } + + /** + * Disable textures if enabled, enable textures iff disabled AND supported. + * @return The new enabled state. + */ + boolean toggleTextures() { + if (track == null || brick == null || head == null || torso == null) { + System.err.println("Some textures are missing"); + enableTextures = false; + } else { + enableTextures = !enableTextures; + } + return enableTextures; + } } |