diff --git a/log.txt b/log.txt index 66d55ff..55982b4 100644 --- a/log.txt +++ b/log.txt @@ -1,4 +1,6 @@ -2007-03-18 18:37:49:515 # Loading sound: data/sounds/test.wav -2007-03-18 18:37:49:531 # Sound sources: quantity=0 -2007-03-18 18:37:49:531 # Stoping sound: source=0 -2007-03-18 18:37:49:531 # Playing sound: source=0 buffer=264767544 +2007-03-21 19:59:45:093 # Loading texture: data/units/tank.png +2007-03-21 19:59:46:203 # Loading texture: data/particle.bmp +2007-03-21 19:59:46:421 # Loading sound: data/sounds/test.wav +2007-03-21 19:59:46:484 # Sound sources: quantity=0 +2007-03-21 19:59:46:484 # Stoping sound: source=0 +2007-03-21 19:59:46:484 # Playing sound: source=0 buffer=261490744 diff --git a/raw/media/units/ei_tank.max b/raw/media/units/ei_tank.max index 07295f7..84233f9 100644 Binary files a/raw/media/units/ei_tank.max and b/raw/media/units/ei_tank.max differ diff --git a/src/data/particle.bmp b/src/data/particle.bmp new file mode 100644 index 0000000..ee02072 Binary files /dev/null and b/src/data/particle.bmp differ diff --git a/src/ei/engine/LWJGLGameWindow.java b/src/ei/engine/LWJGLGameWindow.java index e01e3ca..d463d23 100644 --- a/src/ei/engine/LWJGLGameWindow.java +++ b/src/ei/engine/LWJGLGameWindow.java @@ -61,18 +61,25 @@ public class LWJGLGameWindow { // Create the display window Display.create(); - // enable textures since we're going to use these for our sprites - GL11.glEnable(GL11.GL_TEXTURE_2D); - + //Select The Projection Matrix + GL11.glMatrixMode(GL11.GL_PROJECTION); + //Reset The Projection Matrix + GL11.glLoadIdentity(); + + GL11.glOrtho(0.0f, width, height, 0, -1, 1); + + // Select The Modelview Matrix (controls model orientation) + GL11.glMatrixMode(GL11.GL_MODELVIEW); + GL11.glLoadIdentity(); // disable the OpenGL depth test since we're rendering 2D graphics GL11.glDisable(GL11.GL_DEPTH_TEST); - GL11.glMatrixMode(GL11.GL_PROJECTION); - //Enable Smooth Shading - //GL11.glShadeModel(GL11.GL_SMOOTH); - //Really Nice Perspective Calculations - //GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST); - GL11.glLoadIdentity(); - GL11.glOrtho(0, width, height, 0, -1, 1); + // enable textures since we're going to use these for our sprites + GL11.glEnable(GL11.GL_TEXTURE_2D); + + //Type Of Blending To Perform + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + //Enable Blending + GL11.glEnable(GL11.GL_BLEND); // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work) Display.setVSyncEnabled(true); diff --git a/src/ei/engine/effects/CopyOfLesson19.java b/src/ei/engine/effects/CopyOfLesson19.java new file mode 100644 index 0000000..8f0ea27 --- /dev/null +++ b/src/ei/engine/effects/CopyOfLesson19.java @@ -0,0 +1,326 @@ +package ei.engine.effects; + +/* + * This Code Was Created By Jeff Molofee and GB Schmick 2000 + * A HUGE Thanks To Fredric Echols For Cleaning Up + * And Optimizing The Base Code, Making It More Flexible! + * If You've Found This Code Useful, Please Let Me Know. + * Visit Our Sites At www.tiptup.com and nehe.gamedev.net + */ + +import org.lwjgl.opengl.Display; +import org.lwjgl.opengl.DisplayMode; +import org.lwjgl.opengl.GL11; +import org.lwjgl.opengl.glu.GLU; +import org.lwjgl.input.Keyboard; + +import ei.engine.texture.Texture; +import ei.engine.texture.TextureLoader; +import ei.engine.util.MultiPrintStream; + +/** + * @author Mark Bernard + * date: 23-Jun-2004 + * + * Port of NeHe's Lesson 19 to LWJGL + * Title: Particle Engine Using Triangle Strips + * Uses version 0.9alpha of LWJGL http://www.lwjgl.org/ + * + * Be sure that the LWJGL libraries are in your classpath + * + * Ported directly from the C++ version + * + * 2004-10-08: Updated to version 0.92alpha of LWJGL. + * 2004-12-19: Updated to version 0.94alpha of LWJGL and to use + * DevIL for image loading. + */ +public class CopyOfLesson19 { + private boolean done = false; + private boolean fullscreen = false; + private final String windowTitle = "NeHe's OpenGL Lesson 19 for LWJGL (Particle Engine Using Triangle Strips)"; + private boolean f1 = false; + private DisplayMode displayMode; + + private final int MAX_PARTICLES = 1000; + private Particle particle[]; + boolean rainbow = true; // Rainbow Mode? + boolean sp; // Spacebar Pressed? + boolean rp; // Enter Key Pressed? + + float slowdown = 2.0f; // Slow Down Particles + float xspeed; // Base X Speed (To Allow Keyboard Direction Of Tail) + float yspeed; // Base Y Speed (To Allow Keyboard Direction Of Tail) + float zoom = -40.0f; // Used To Zoom Out + + int col; // Current Color Selection + int delay; // Rainbow Effect Delay + int texture; // Storage For Our Particle Texture + + private static float colors[][]= // Rainbow Of Colors + { + {1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f}, + {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f}, + {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f} + }; + + public static void main(String args[]) { + MultiPrintStream.makeInstance(new MultiPrintStream("log.txt")); + boolean fullscreen = false; + if(args.length>0) { + if(args[0].equalsIgnoreCase("fullscreen")) { + fullscreen = true; + } + } + + CopyOfLesson19 l19 = new CopyOfLesson19(); + l19.run(fullscreen); + } + public void run(boolean fullscreen) { + this.fullscreen = fullscreen; + try { + init(); + while (!done) { + mainloop(); + render(); + Display.update(); + } + cleanup(); + } + catch (Exception e) { + e.printStackTrace(); + System.exit(0); + } + } + private void mainloop() { + if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { // Exit if Escape is pressed + done = true; + } + if(Display.isCloseRequested()) { // Exit if window is closed + done = true; + } + if(Keyboard.isKeyDown(Keyboard.KEY_F1) && !f1) { // Is F1 Being Pressed? + f1 = true; // Tell Program F1 Is Being Held + switchMode(); // Toggle Fullscreen / Windowed Mode + } + if(!Keyboard.isKeyDown(Keyboard.KEY_F1)) { // Is F1 Being Released? + f1 = false; + } + if((Keyboard.isKeyDown(Keyboard.KEY_SPACE) && !sp) || (rainbow && (delay > 25))) { + if(Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { + rainbow = false; // If Spacebar Is Pressed Disable Rainbow Mode + } + sp = true; // Set Flag Telling Us Space Is Pressed + delay = 0; // Reset The Rainbow Color Cycling Delay + col++; // Change The Particle Color + if(col > 11) { + col = 0; // If Color Is Too High Reset It + } + } + if(!Keyboard.isKeyDown(Keyboard.KEY_SPACE)) { + sp = false; + } + if(Keyboard.isKeyDown(Keyboard.KEY_ADD) && (slowdown > 1.0f)) { + slowdown -= 0.01f; // Speed Up Particles + } + if(Keyboard.isKeyDown(Keyboard.KEY_SUBTRACT) && (slowdown < 4.0f)) { + slowdown += 0.01f; // Slow Down Particles + } + + if(Keyboard.isKeyDown(Keyboard.KEY_PRIOR)) { + zoom += 0.1f; // Zoom In + } + if(Keyboard.isKeyDown(Keyboard.KEY_NEXT)) { + zoom -= 0.1f; // Zoom Out + } + + if(Keyboard.isKeyDown(Keyboard.KEY_RETURN) && !rp) { // Return Key Pressed + rp = true; // Set Flag Telling Us It's Pressed + rainbow = !rainbow; // Toggle Rainbow Mode On / Off + } + if(!Keyboard.isKeyDown(Keyboard.KEY_RETURN)) { + rp = false; // If Return Is Released Clear Flag + } + + delay++; // Increase Rainbow Mode Color Cycling Delay Counter + } + + private void switchMode() { + fullscreen = !fullscreen; + try { + Display.setFullscreen(fullscreen); + } + catch(Exception e) { + e.printStackTrace(); + } + } + + private void createWindow() throws Exception { + Display.setFullscreen(fullscreen); + DisplayMode d[] = Display.getAvailableDisplayModes(); + for (int i = 0; i < d.length; i++) { + if (d[i].getWidth() == 640 + && d[i].getHeight() == 480 + && d[i].getBitsPerPixel() == 32) { + displayMode = d[i]; + break; + } + } + Display.setDisplayMode(displayMode); + Display.setTitle(windowTitle); + Display.create(); + } + private void init() throws Exception { + particle = new Particle[MAX_PARTICLES]; + + for(int i=0;i-1.5f)) { + particle[i].yg -= 0.01f; + } + + // If Number Pad 6 And X Gravity Is Less Than 1.5 Increase Pull Right + if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD6) && (particle[i].xg<1.5f)) { + particle[i].xg += 0.01f; + } + + // If Number Pad 4 And X Gravity Is Greater Than -1.5 Increase Pull Left + if (Keyboard.isKeyDown(Keyboard.KEY_NUMPAD4) && (particle[i].xg>-1.5f)) { + particle[i].xg -= 0.01f; + } + + if (Keyboard.isKeyDown(Keyboard.KEY_TAB)) { // Tab Key Causes A Burst + particle[i].x = 0.0f; // Center On X Axis + particle[i].y = 0.0f; // Center On Y Axis + particle[i].z = 0.0f; // Center On Z Axis + particle[i].xi = ((float)(Math.random() * 50.0) - 26.0f) * 10.0f; // Random Speed On X Axis + particle[i].yi = ((float)(Math.random() * 50.0) - 25.0f) * 10.0f; // Random Speed On Y Axis + particle[i].zi = ((float)(Math.random() * 50.0) - 25.0f) * 10.0f; // Random Speed On Z Axis + } + } + } + } + + private void cleanup() { + Display.destroy(); + } + + private int loadTexture(String path) { + Texture tex; + tex = TextureLoader.getTextureLoaderInstance().getTexture(path); + return tex.getGLTarget(); // Return Image Address In Memory + } +} +/* +class Particle { // Particles Structure + public boolean active; // Active (Yes/No) + public float life; // Particle Life + public float fade; // Fade Speed + public float r; // Red Value + public float g; // Green Value + public float b; // Blue Value + public float x; // X Position + public float y; // Y Position + public float z; // Z Position + public float xi; // X Direction + public float yi; // Y Direction + public float zi; // Z Direction + public float xg; // X Gravity + public float yg; // Y Gravity + public float zg; // Z Gravity +} +*/ diff --git a/src/ei/engine/effects/Particles.java b/src/ei/engine/effects/Particles.java new file mode 100644 index 0000000..30acbdb --- /dev/null +++ b/src/ei/engine/effects/Particles.java @@ -0,0 +1,194 @@ +package ei.engine.effects; + +/* + * This Code Was Created By Jeff Molofee and GB Schmick 2000 + * A HUGE Thanks To Fredric Echols For Cleaning Up + * And Optimizing The Base Code, Making It More Flexible! + * If You've Found This Code Useful, Please Let Me Know. + * Visit Our Sites At www.tiptup.com and nehe.gamedev.net + */ + +import org.lwjgl.opengl.GL11; + +import ei.engine.scene.Entity; +import ei.engine.texture.Texture; +import ei.engine.texture.TextureLoader; + +/** + * @author Mark Bernard + * date: 23-Jun-2004 + * @author Ziver Koc + * date: 19-Mar-2007 + * + * Port of NeHe's Lesson 19 to LWJGL + * Title: Particle Engine Using Triangle Strips + * Uses version 0.9alpha of LWJGL http://www.lwjgl.org/ + * + * Be sure that the LWJGL libraries are in your classpath + * + * Ported directly from the C++ version + * + */ +public class Particles extends Entity{ + private final int MAX_PARTICLES = 1000; + private Particle particle[]; + boolean rainbow = true; // Rainbow Mode? + + float slowdown = 1.0f; // Slow Down Particles + float xspeed = 00; // Base X Speed (To Allow Keyboard Direction Of Tail) + float yspeed = 000; // Base Y Speed (To Allow Keyboard Direction Of Tail) + float zoom = 0.0f; // Used To Zoom Out + + int col; // Current Color Selection + int delay; // Rainbow Effect Delay + Texture texture; // Storage For Our Particle Texture + + private static float colors[][]= // Rainbow Of Colors + { + {1.0f,0.5f,0.5f},{1.0f,0.75f,0.5f},{1.0f,1.0f,0.5f},{0.75f,1.0f,0.5f}, + {0.5f,1.0f,0.5f},{0.5f,1.0f,0.75f},{0.5f,1.0f,1.0f},{0.5f,0.75f,1.0f}, + {0.5f,0.5f,1.0f},{0.75f,0.5f,1.0f},{1.0f,0.5f,1.0f},{1.0f,0.5f,0.75f} + }; + + public Particles(String name){ + super(name); + this.texture = TextureLoader.getTextureLoaderInstance().getTexture("data/particle.bmp"); + reset(); + setExplotion(); + } + + /** + * Resets all the paricals + * + */ + public void reset(){ + particle = new Particle[MAX_PARTICLES]; + + for(int i=0;i 25)) { + delay = 0; // Reset The Rainbow Color Cycling Delay + col++; // Change The Particle Color + if(col > 11) { + col = 0; // If Color Is Too High Reset It + } + } + delay++; // Increase Rainbow Mode Color Cycling Delay Counter + } + + + private void setExplotion() { + for (int i=0;i