/** * Called back immediately after the OpenGL context is initialized. Can be used to perform * one-time initialization. Run only once. */ @Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context glu = new GLU(); // get GL Utilities gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color gl.glClearDepth(1.0f); // set clear depth value to farthest // Do not enable depth test // gl.glEnable(GL_DEPTH_TEST); // enables depth testing // gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting // Load the texture image try { // Use URL so that can read from JAR and disk file. BufferedImage image = ImageIO.read(this.getClass().getResource(textureFileName)); // Create a OpenGL Texture object texture = AWTTextureIO.newTexture(GLProfile.getDefault(), image, false); // Use linear filter if image is larger than the original texture gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); // Use linear filter if image is smaller than the original texture gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); } catch (GLException | IOException e) { e.printStackTrace(); } // Texture image flips vertically. Shall use TextureCoords class to retrieve // the top, bottom, left and right coordinates, instead of using 0.0f and 1.0f. TextureCoords textureCoords = texture.getImageTexCoords(); textureCoordTop = textureCoords.top(); textureCoordBottom = textureCoords.bottom(); textureCoordLeft = textureCoords.left(); textureCoordRight = textureCoords.right(); // Enable the texture texture.enable(gl); texture.bind(gl); // gl.glEnable(GL_TEXTURE_2D); // Enable blending gl.glEnable(GL_BLEND); gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Allocate the stars for (int i = 0; i < stars.length; i++) { stars[i] = new Star(); // Linearly distributed according to the star number stars[i].distance = ((float) i / numStars) * 5.0f; } }
public DrawByLevelFractal() { baseDir = "CS371/assignments/assignment02/ifs/"; ifsFiles = new ArrayList<String>(); ifsFiles.add("carpet.ifs"); ifsFiles.add("chaos.ifs"); ifsFiles.add("coral.ifs"); ifsFiles.add("curl.ifs"); ifsFiles.add("four.ifs"); ifsFiles.add("galaxy.ifs"); ifsFiles.add("dragon.ifs"); ifsFiles.add("leady.ifs"); ifsFiles.add("koch.ifs"); ifsFiles.add("mouse.ifs"); ifsFiles.add("leaf.ifs"); ifsFiles.add("seven.ifs"); ifsFiles.add("three.ifs"); ifsFiles.add("tri.ifs"); pointsToDraw = 80000; left = -7; right = 7; bottom = -7; top = 11; xOrigin = 0; yOrigin = 0; rotate_scale_xx = new double[maximumTransitions]; rotate_scale_xy = new double[maximumTransitions]; rotate_scale_yx = new double[maximumTransitions]; rotate_scale_yy = new double[maximumTransitions]; trans_x = new double[maximumTransitions]; trans_y = new double[maximumTransitions]; prob = new double[maximumTransitions]; caps = new GLCapabilities(GLProfile.getGL2GL3()); caps.setDoubleBuffered(true); // request double buffer display mode caps.setHardwareAccelerated(true); canvas = new GLJPanel(); // canvas.setOpaque(true); canvas.addGLEventListener(this); canvas.addKeyListener(this); animator = new FPSAnimator(canvas, 60); getContentPane().add(canvas); }
public AnimationPanel(GLEventListener renderer, AnimationTrigger trigger, Dimension dim) { super(new MigLayout("insets 0, nogrid, center, fill", "center", "center")); GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2)); _canvas = new GLCanvas(caps); _canvas.setName("glCanvas"); _canvas.setMinimumSize(new Dimension(5, 5)); setRenderer(renderer); if (trigger != null) { _defaultTrigger = null; _altTrigger = trigger; _altTrigger.setCanvas(_canvas); } else { _altTrigger = null; _defaultTrigger = new Animator(_canvas); _defaultTrigger.setPrintExceptions(true); } add(_canvas); setSize(dim); }