Update of /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson04
In directory sc8-pr-cvs1:/tmp/cvs-serv7149
Modified Files:
Lesson4.java
Log Message:
Extends Lesson1
Index: Lesson4.java
CVS Browser:
http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson04/Lesson4.java
===================================================================
RCS file: /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson04/Lesson4.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- Lesson4.java 25 Nov 2002 06:24:09 -0000 1.1
+++ Lesson4.java 26 Nov 2002 05:56:01 -0000 1.2
@@ -29,10 +29,14 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+package lesson04;
+
import org.lwjgl.*;
import org.lwjgl.opengl.*;
import org.lwjgl.input.*;
+import lesson01.Lesson1;
+
/**
* $Id$
*
@@ -43,13 +47,7 @@
* @author Luke Holden
* @version $Revision$
*/
-public class Lesson4 {
- private GL gl;
- private GLU glu;
-
- private boolean done = false;
- private boolean fullscreen = true;
-
+public class Lesson4 extends Lesson1 {
/* Angle For The Triangle */
float rtri; // (new)
/* Angle For The Quad */
@@ -60,45 +58,8 @@
}
- private void resizeGLScene(int width, int height) {
- /* Reset The Current Viewport */
- gl.viewport(0, 0, width, height);
- /* Select The Projection Matrix */
-
- gl.matrixMode(GL.PROJECTION);
- /* Reset The Projection Matrix */
- gl.loadIdentity();
-
- /* Calculate The Aspect Ratio Of The Window */
- glu.perspective(45.0f, ((float) Display.getWidth()) / ((float) Display.getHeight()), 0.1f, 100.0f);
-
- /* Select The Modelview Matrix */
- gl.matrixMode(GL.MODELVIEW);
- /* Reset The Modelview Matrix */
- gl.loadIdentity();
- }
- private boolean initGL() {
-
- /* Enables Smooth Shading */
- gl.shadeModel(GL.SMOOTH);
-
- /* Black Background */
- gl.clearColor(0.0f, 0.0f, 0.0f, 0.0f);
-
- /* Depth Buffer Setup */
- gl.clearDepth(1.0f);
- /* Enables Depth Testing */
- gl.enable(GL.DEPTH_TEST);
- /* The Type Of Depth Test To Do */
- gl.depthFunc(GL.LEQUAL);
-
- /* Really Nice Perspective Calculations */
- gl.hint(GL.PERSPECTIVE_CORRECTION_HINT, GL.NICEST);
- return true;
- }
-
- private boolean drawGLScene() {
+ protected boolean drawGLScene(float frameTime) {
/* Clear The Screen And The Depth Buffer */
gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
@@ -140,65 +101,13 @@
gl.vertex3f(-1.0f,-1.0f, 0.0f);
gl.end();
- /* Increase The Rotation Variable For The Triangle */
- rtri+=0.2f; // (new)
- /* Decrease The Rotation Variable For The Quad */
- rquad-=0.15f; // (new)
+
+ /* Rotate triangle 20 pps ( NEW ) */
+ rtri += frameTime * 20f;
+ /* Rotate Quad 15 pps ( NEW ) */
+ rquad -= frameTime * 15f;
return true;
- }
-
- public void killGLWindow() {
- Keyboard.destroy();
- gl.destroy();
- Display.destroy();
- }
-
- public void createGLWindow(int width, int height, int bits, boolean fullscreenflag) throws Exception {
- fullscreen = fullscreenflag;
- try {
- Display.create(new DisplayMode(width, height, bits, 60), fullscreenflag);
- gl = new GL(bits, 0, bits, 8);
- gl.create();
- glu = new GLU(gl);
- Keyboard.create();
- Keyboard.enableBuffer();
-
- resizeGLScene(Display.getWidth(), Display.getHeight());
-
- initGL();
- }
- catch (Exception e) {
- throw new Exception("Problem initialising Lesson", e);
- }
- }
-
- public void start() throws Exception {
- try {
- createGLWindow(640, 480, 16, fullscreen);
-
- while (!done) {
- loop();
- }
- killGLWindow();
- }
- catch (Exception e) {
- throw new Exception("Problem starting loop", e);
- }
- }
-
- private void loop() {
- drawGLScene();
- gl.swapBuffers();
-
- /* Keys that have a toggle effect */
- Keyboard.read();
- for (int i = 0; i < Keyboard.getNumKeyboardEvents(); i++) {
- Keyboard.next();
- if (Keyboard.key == Keyboard.KEY_ESCAPE && Keyboard.state) {
- done = true;
- }
- }
}
public static void main(String[] arguments) {
|