From: Luke H. <lh...@us...> - 2002-11-26 07:05:24
|
Update of /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson09 In directory sc8-pr-cvs1:/tmp/cvs-serv29914/lesson09 Modified Files: Lesson9.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: Lesson9.java CVS Browser: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/java-game-lib/LWJGL/examples/nehe/lesson09/Lesson9.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/examples/nehe/lesson09/Lesson9.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- Lesson9.java 25 Nov 2002 06:53:08 -0000 1.1 +++ Lesson9.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 lesson09; + import java.nio.*; import java.io.*; import java.awt.image.BufferedImage; @@ -40,6 +42,8 @@ import org.lwjgl.opengl.*; import org.lwjgl.input.*; +import lesson06.*; + /** * $Id$ * @@ -50,17 +54,12 @@ * @author Luke Holden * @version $Revision$ */ -public class Lesson9 { +public class Lesson9 extends Lesson6 { /* Number Of Stars To Draw */ public static int NUM = 50; - private GL gl; - private GLU glu; private Random rand = new Random(); - - private boolean done = false; - private boolean fullscreen = true; - + /* Twinkling Stars */ private boolean twinkle = false; @@ -92,33 +91,8 @@ } - /* 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]; @@ -152,42 +126,16 @@ } } - 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 { 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); - /* Really Nice Perspective Calculations */ - gl.hint(GL.PERSPECTIVE_CORRECTION_HINT, GL.NICEST); + super.initGL(); + /* Blending Function For Translucency Based On Source Alpha Value */ gl.blendFunc(GL.SRC_ALPHA, GL.ONE); /* Enable Blending */ gl.enable(GL.BLEND); - + /* Create A Loop That Goes Through All The Stars */ for (curStar = 0; curStar < NUM; curStar++) { star[curStar] = new Stars(); @@ -205,7 +153,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); /* Select our Texture */ @@ -262,11 +210,11 @@ gl.end(); /* Used To Spin The Stars */ - spin+=0.01f; + spin+=frameTime * 2f; /* Changes The Angle Of A Star */ - star[curStar].angle += ((float)curStar)/NUM; + star[curStar].angle += frameTime * ((float)curStar)/NUM * 300 ; /* Changes The Distance Of A Star */ - star[curStar].dist -= 0.01f; + star[curStar].dist -= frameTime * 0.4f; /* Is The Star In The Middle Yet */ if (star[curStar].dist < 0.0f) { @@ -281,62 +229,21 @@ 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_UP)) { - tilt -= 0.5f; + tilt -= frameTime * 20f; } if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) { - tilt += 0.5f; + tilt += frameTime * 20f; } if (Keyboard.isKeyDown(Keyboard.KEY_PRIOR)) { - zoom -= 0.2f; + zoom -= frameTime * 10f; } if (Keyboard.isKeyDown(Keyboard.KEY_NEXT)) { - zoom += 0.2f; + zoom += frameTime * 10f; } @@ -353,18 +260,11 @@ } } - private IntBuffer createIntBuffer(int size) { - ByteBuffer temp = ByteBuffer.allocateDirect(4 * size); - temp.order(ByteOrder.nativeOrder()); - - return temp.asIntBuffer(); - } - public static void main(String[] arguments) { int err = 0; Lesson9 lesson = new Lesson9(); 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/lesson09/Texture.java |