From: Luke H. <lh...@us...> - 2002-11-26 05:49:29
|
Update of /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson02 In directory sc8-pr-cvs1:/tmp/cvs-serv4280 Modified Files: Lesson2.java Log Message: now extends lesson01.Lesson1 Index: Lesson2.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson02/Lesson2.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson02/Lesson2.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Lesson2.java 25 Nov 2002 06:24:09 -0000 1.1 +++ Lesson2.java 26 Nov 2002 05:49:25 -0000 1.2 @@ -29,11 +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 lesson02; import org.lwjgl.*; import org.lwjgl.opengl.*; import org.lwjgl.input.*; +import lesson01.Lesson1; + /** * $Id$ * @@ -44,57 +47,13 @@ * @author Luke Holden * @version $Revision$ */ -public class Lesson2 { - private GL gl; - private GLU glu; - - private boolean done = false; - private boolean fullscreen = true; - +public class Lesson2 extends Lesson1 { /** Creates a new instance of Lesson */ public Lesson2(){ } - 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); /* Reset The Current Modelview Matrix */ @@ -130,60 +89,7 @@ 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; Lesson2 lesson = new Lesson2(); |