From: Luke H. <lh...@us...> - 2002-11-26 07:05:24
|
Update of /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson07 In directory sc8-pr-cvs1:/tmp/cvs-serv29914/lesson07 Modified Files: Lesson7.java Removed Files: Texture.java Log Message: now using timers, packages... most packages extend lesson1 or 6-7. lessons 10-17 will be broken for the rest of the night. going to bed... They will be done tomarrow =) Index: Lesson7.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson07/Lesson7.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson07/Lesson7.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Lesson7.java 25 Nov 2002 06:53:08 -0000 1.1 +++ Lesson7.java 26 Nov 2002 07:05:21 -0000 1.2 @@ -29,6 +29,8 @@ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +package lesson07; + import java.nio.*; import java.io.*; import java.awt.image.BufferedImage; @@ -39,6 +41,8 @@ import org.lwjgl.opengl.*; import org.lwjgl.input.*; +import lesson06.*; + /** * $Id$ * @@ -49,13 +53,8 @@ * @author Luke Holden * @version $Revision$ */ -public class Lesson7 { - private GL gl; - private GLU glu; - - private boolean done = false; - private boolean fullscreen = true; - +public class Lesson7 extends Lesson6 { + protected boolean fullscreen = false; /* Lighting ON / OFF */ private boolean light; @@ -81,34 +80,9 @@ public Lesson7() { } - - /* A javafied version of AUX_RGBImageRec *LoadBMP(char*); */ - private Texture loadImage(String filename) throws Exception { - Texture texture = null; - BufferedImage tmpImg = null; - /* normally I would use StringUtils.isValid(String) from the - jakarta commons lib, but thats beyond the scope of this lesson */ - if ((filename != null) && (filename.trim() != "")) { - try { - InputStream is = getClass().getResourceAsStream(filename); - tmpImg = (BufferedImage) ImageIO.read(is); - if (tmpImg == null) { - throw new Exception("Error: Got null from ImageIO.read()"); - } - texture = new Texture(tmpImg); - } - catch ( Exception e ) { - throw new Exception("Problem loading bitmap", e); - } - } else { - throw new Exception("Error: file name is not valid!"); - } - return texture; - } - /* Load Bitmaps And Convert To Textures */ - private void loadGLTextures() throws Exception { + protected void loadGLTextures() throws Exception { /* Create Storage Space For The Texture */ Texture[] textureImage = new Texture[1]; @@ -168,43 +142,12 @@ } } + - 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{ + protected void initGL() throws Exception{ /* Jump To Texture Loading Routine */ try { - loadGLTextures(); - /* Enable Texture Mapping ( NEW ) */ - gl.enable(GL.TEXTURE_2D); - /* Enables Smooth Shading */ - gl.shadeModel(GL.SMOOTH); - /* Black Background */ - gl.clearColor(0.0f, 0.0f, 0.0f, 0.5f); - /* 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); + super.initGL(); /* Setup The Ambient Light */ gl.lightfv(GL.LIGHT1, GL.AMBIENT, Sys.getDirectBufferAddress(lightAmbient)); @@ -221,7 +164,7 @@ } } - 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); @@ -311,75 +254,34 @@ gl.end(); /* X Axis Rotation */ - xrot+=xspeed; + xrot+=frameTime * xspeed; /* Y Axis Rotation */ - yrot+=yspeed; + yrot+=frameTime * yspeed; 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(); - + protected void input(float frameTime) { /* Keys that have a constant effect */ Keyboard.poll(); if (Keyboard.isKeyDown(Keyboard.KEY_PRIOR)) { - z-=0.02f; + z-=frameTime * 10f; } if (Keyboard.isKeyDown(Keyboard.KEY_NEXT)) { - z+=0.02f; + z+=frameTime * 10f; } if (Keyboard.isKeyDown(Keyboard.KEY_UP)) { - xspeed-=0.01f; + xspeed-=frameTime * 20f; } if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { - xspeed+=0.01f; + xspeed+=frameTime * 20f; } if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) { - yspeed+=0.01f; + yspeed+=frameTime * 20f; } if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) { - yspeed-=0.01f; + yspeed-=frameTime * 20f; } /* Keys that have a toggle effect */ @@ -403,7 +305,8 @@ // System.exit(1); // } // } - if (Keyboard.key == Keyboard.KEY_L && Keyboard.state) { + + if (Keyboard.key == Keyboard.KEY_L && !Keyboard.state) { light=!light; if (!light) { gl.disable(GL.LIGHTING); @@ -421,14 +324,7 @@ } } - private IntBuffer createIntBuffer(int size) { - ByteBuffer temp = ByteBuffer.allocateDirect(4 * size); - temp.order(ByteOrder.nativeOrder()); - - return temp.asIntBuffer(); - } - - private FloatBuffer createFloatBuffer(int size) { + public FloatBuffer createFloatBuffer(int size) { ByteBuffer temp = ByteBuffer.allocateDirect(4 * size); temp.order(ByteOrder.nativeOrder()); @@ -439,7 +335,7 @@ int err = 0; Lesson7 lesson = new Lesson7(); try { - lesson.start(); + lesson.start(640, 480, 16, false); } catch (Exception e) { err = 1; --- Texture.java DELETED --- CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson07/Texture.java |