From: Luke H. <lh...@us...> - 2002-11-25 06:42:48
|
Update of /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson01 In directory sc8-pr-cvs1:/tmp/cvs-serv12937 Added Files: Lesson1.java Log Message: up we go --- NEW FILE: Lesson1.java --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson01/Lesson1.java /* * Copyright (c) 2002 Light Weight Java Game Library Project * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * * Neither the name of 'Light Weight Java Game Library' nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ import org.lwjgl.*; import org.lwjgl.opengl.*; import org.lwjgl.input.*; /** * $Id: Lesson1.java,v 1.1 2002/11/25 06:42:45 lholden Exp $ * * Setting Up An OpenGL Window * * Credit goes to Jeff Molofee (NeHe) whos tutorial this is based on * * @author Luke Holden * @version $Revision: 1.1 $ */ public class Lesson1 { private GL gl; private GLU glu; private boolean done = false; private boolean fullscreen = true; /** Creates a new instance of Lesson */ public Lesson1() { } 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 void initGL() throws Exception { try { /* 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); } catch (Exception e) { throw new Exception("Problem initialising GL", e); } } private boolean drawGLScene() { /* Clear The Screen And The Depth Buffer */ gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT); /* Reset The Current Modelview Matrix */ gl.loadIdentity(); 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) { int err = 0; Lesson1 lesson = new Lesson1(); try { lesson.start(); } catch (Exception e) { err = 1; e.printStackTrace(); } System.exit(err); } } |