From: Luke H. <lh...@us...> - 2002-11-26 07:05:24
|
Update of /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson08 In directory sc8-pr-cvs1:/tmp/cvs-serv29914/lesson08 Modified Files: Lesson8.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: Lesson8.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson08/Lesson8.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson08/Lesson8.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Lesson8.java 25 Nov 2002 06:53:08 -0000 1.1 +++ Lesson8.java 26 Nov 2002 07:05:22 -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 lesson08; + import java.nio.*; import java.io.*; import java.awt.image.BufferedImage; @@ -39,6 +41,9 @@ import org.lwjgl.opengl.*; import org.lwjgl.input.*; +import lesson06.Texture; +import lesson07.Lesson7; + /** * $Id$ * @@ -49,13 +54,7 @@ * @author Luke Holden * @version $Revision$ */ -public class Lesson8 { - private GL gl; - private GLU glu; - - private boolean done = false; - private boolean fullscreen = true; - +public class Lesson8 extends Lesson7 { /* Lighting ON / OFF */ private boolean light; /* Blending OFF/ON? ( NEW ) */ @@ -84,33 +83,9 @@ } - /* 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]; @@ -171,50 +146,10 @@ } - 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 */ - 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); - - /* Setup The Ambient Light */ - gl.lightfv(GL.LIGHT1, GL.AMBIENT, Sys.getDirectBufferAddress(lightAmbient)); - /* Setup The Diffuse Light */ - gl.lightfv(GL.LIGHT1, GL.DIFFUSE, Sys.getDirectBufferAddress(lightDiffuse)); - /* Position The Light */ - gl.lightfv(GL.LIGHT1, GL.POSITION, Sys.getDirectBufferAddress(lightPosition)); - gl.enable(GL.LIGHT1); + super.initGL(); /* Full Brightness, 50% Alpha ( NEW ) */ gl.color4f(1.0f,1.0f,1.0f,0.5f); @@ -227,7 +162,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); @@ -317,75 +252,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 */ @@ -395,20 +289,7 @@ if (Keyboard.key == Keyboard.KEY_ESCAPE && Keyboard.state) { done = true; } -// /* F1 switch between fullscreen/windowed is buggy... -// * So for now, we are leaving this ability disabled */ -// if (Keyboard.key == Keyboard.KEY_F1 && Keyboard.state) { -// try { -// killGLWindow(); -// fullscreen=!fullscreen; -// createGLWindow(640, 480, 16, fullscreen); -// } -// catch (Exception e) { -// /* We dont want to put exceptions into our loop... so */ -// e.printStackTrace(); -// System.exit(1); -// } -// } + if (Keyboard.key == Keyboard.KEY_L && Keyboard.state) { light=!light; if (!light) { @@ -443,25 +324,11 @@ } } - private IntBuffer createIntBuffer(int size) { - ByteBuffer temp = ByteBuffer.allocateDirect(4 * size); - temp.order(ByteOrder.nativeOrder()); - - return temp.asIntBuffer(); - } - - private FloatBuffer createFloatBuffer(int size) { - ByteBuffer temp = ByteBuffer.allocateDirect(4 * size); - temp.order(ByteOrder.nativeOrder()); - - return temp.asFloatBuffer(); - } - public static void main(String[] arguments) { int err = 0; Lesson8 lesson = new Lesson8(); 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/lesson08/Texture.java |