package Buchstaben; import java.awt.event.*; import javax.media.opengl.*; import javax.media.opengl.glu.*; import com.sun.opengl.util.Animator; import java.nio.*; public class JOGLEventListener implements GLEventListener, KeyListener { private final GLU glu = new GLU(); private Animator animator = null; private final int MAX_PARTICLES = 1000; private Particle particles[] = new Particle[MAX_PARTICLES]; private int[] textures = new int[1] ; private float a = 0.0f; private float b = 0.0f; private float j = 0.0f; private float o = 0.0f; private float g = 0.0f; private float l = 0.0f; /** * Called by the drawable immediately after the OpenGL context is * initialized for the first time. Can be used to perform one-time OpenGL * initialization such as setup of lights and display lists. * @param gLDrawable The GLDrawable object. */ public void init(GLAutoDrawable gld) { GL gl = gld.getGL(); gl.glEnable( GL.GL_BLEND ); gl.glEnable(GL.GL_TEXTURE_2D); gl.glGenTextures(1,textures, 0); gl.glBindTexture(GL.GL_TEXTURE_2D,textures[0]); gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); gl.glTexParameteri( GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR); ByteBuffer dest = null; byte[] data = getTextureData(); dest = ByteBuffer.allocateDirect(data.length); dest.order(ByteOrder.nativeOrder()); dest.put(data, 0, data.length); dest.rewind(); gl.glTexImage2D (GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, 256, 256, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, dest); gld.addKeyListener(this); } /** * Called by the drawable to initiate OpenGL rendering by the client. * After all GLEventListeners have been notified of a display event, the * drawable will swap its buffers if necessary. * @param gLDrawable The GLDrawable object. */ public void display(GLAutoDrawable gld) { GL gl = gld.getGL(); gl.glClear(GL.GL_COLOR_BUFFER_BIT|GL.GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer gl.glDisable(GL.GL_DEPTH_TEST); gl.glColor3f(1.0f,0.0f,0.0f); gl.glEnable(GL.GL_BLEND ); //Blendmodus ein - fuer Texturen gl.glLoadIdentity(); gl.glTranslatef( -0.1f, 0.8f, -2.0f); for(int i=0; i!! CURRENTLY UNIMPLEMENTED IN JOGL !! * @param gLDrawable The GLDrawable object. * @param modeChanged Indicates if the video mode has changed. * @param deviceChanged Indicates if the video device has changed. */ public void displayChanged(GLAutoDrawable gld, boolean modeChanged, boolean deviceChanged) { } /** * Invoked when a key has been pressed. * See the class description for {@link KeyEvent} for a definition of * a key pressed event. * @param e The KeyEvent. */ public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ESCAPE){ animator.stop(); System.exit(0); } } /** * Invoked when a key has been released. * See the class description for {@link KeyEvent} for a definition of * a key released event. * @param e The KeyEvent. */ public void keyReleased(KeyEvent e) {} /** * Invoked when a key has been typed. * See the class description for {@link KeyEvent} for a definition of * a key typed event. * @param e The KeyEvent. */ public void keyTyped(KeyEvent e) {} /** * Used to register an Animator Object, which can be controlled from inside * this class * @param animator The Animator */ public void registerAnimator(Animator animator) { this.animator = animator; } private Particle createParticle() { Particle p = new Particle(1.0f, 0.001f); p.setSpeed(Particle.SPEED_X, 0.001f-(float)Math.random()/500.0f); p.setSpeed(Particle.SPEED_Z, 0.001f-(float)Math.random()/500.0f); return p; } public byte[] getTextureData() { byte[] data = new byte[256*4*256]; for(int i=0; i<256*4*256; i+=4) { data[i] = (byte)150; data[i+1] = (byte)150; data[i+2] = (byte)255; } for(int y=0; y<256; y++) { for(int x=0; x<256; x++) { int dx = x-128; int dy = y-128; int w = 50 - (int)Math.sqrt((double)(dx*dx+dy*dy))*2; if (w < 0) w = 0; data[y*256*4+x*4+3] = (byte)w; } } return data; } }