@Override public void init(GameContainer container) throws SlickException { // Set up the rendering system texture = PixelData.createTexture(container.getWidth(), container.getHeight(), ImageData.Format.RGB, Image.FILTER_NEAREST); image = new Image(texture); pixels = new PixelData(container.getWidth(), container.getHeight()); pixels.clear(0x00); // Creates the Set if(fractalType == MANDELBROT_SET) { set = new Mandelbrot(); } else if(fractalType == JULIA_SET) { set = new Julia(constantReal, constantImaginary); } // Calculates the first frame pixels = set.updateSet(container, pixels, zoom, maxIterations, xOffset, yOffset, colorFactor); // Updates the texture pixels.apply(texture); }
/** * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.opengl.ImageData, int, int) */ public void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException { try { Cursor cursor = CursorLoader.get().getCursor(data, hotSpotX, hotSpotY); Mouse.setNativeCursor(cursor); } catch (Throwable e) { Log.error("Failed to load and apply cursor.", e); throw new SlickException("Failed to set mouse cursor", e); } }
/** * Create an image from a image data source. Note that this method uses * * @param data The pixelData to use to create the image * @param f The filter to use when scaling this image */ public Image(ImageData data, int f) { try { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; texture = InternalTextureLoader.get().getTexture(data, this.filter); ref = texture.toString(); } catch (IOException e) { Log.error(e); } }
/** * @see org.newdawn.slick.GameContainer#setMouseCursor(org.newdawn.slick.opengl.ImageData, int, int) */ public void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException { try { Cursor cursor = CursorLoader.get().getCursor(data, hotSpotX, hotSpotY); Mouse.setNativeCursor(cursor); } catch (Exception e) { Log.error("Failed to load and apply cursor.", e); } }
/** * Set the mouse cursor to be displayed - this is a hardware cursor and hence shouldn't have any impact of FPS. * * @param data The cursor to be used * @param hotSpotX The x offset of the cursor * @param hotSpotY The y offset of the cursor */ public static void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY){ if(appgc == null){ return; } try{ appgc.setMouseCursor(data, hotSpotX, hotSpotY); }catch(SlickException e){ Logger.getLogger(Game.class.getName()).log(Level.WARNING, "Could Not Set Mouse Cursor " + data.toString(), e); } }
/** * Create an image from a image data source. Note that this method uses * * @param data The pixelData to use to create the image * @param f The filter to use when scaling this image */ private Image(@Nonnull ImageData data, int f) { try { this.filter = f; texture = InternalTextureLoader.get().getTexture(data, this.filter); ref = texture.toString(); } catch (IOException e) { Log.error(e); } }
/** * Convenience method to create a texture with a given internal format. * @param width the width of the empty texture * @param height the height of the empty texture * @param filter the filter to use * @param format the internal format * @return a generated texture */ public static Texture createTexture(int width, int height, ImageData.Format format, int filter) throws SlickException { EmptyImageData data = new EmptyImageData(width, height); ByteBuffer dataBuffer = data.getImageBufferData(); String ref = "pixelhandler:"+width+"x"+height+":"+format.toString(); try { return InternalTextureLoader.get().createTexture(data, dataBuffer, ref, GL11.GL_TEXTURE_2D, filter, filter, false, format); } catch (IOException e) { throw new SlickException("Error generating texture", e); } }
/** * Creates a PixelData buffer with the specified size and format. * * Note that Slick currently loads textures with an internal RGBA format; * this means that even if we upload, say, 2-component (e.g. GRAYALPHA) * texture data, it will eventually be stored in OpenGL video memory * using RGBA. For better performance and memory management, * create textures with the same internal format as the format given to PixelData. * The static 'createTexture' utility method is intended for this purpose. * * Also note that most drivers will expand formats to RGBA internally, so this optimization may * not be necessary. * * @param width the width in pixels of our data * @param height the height in pixels of our data * @param format the desired format to use during uploading (RGB, RGBA, GRAY, GRAYALPHA, ALPHA) */ public PixelData(int width, int height, ImageData.Format format) { this.format = format; this.width = width; this.height = height; this.pixels = BufferUtils.createByteBuffer(width * height * format.getColorComponents()); }
/** * Set the mouse cursor to be displayed - this is a hardware cursor and hence * shouldn't have any impact on FPS. * * @param data The image data from which the cursor can be construted * @param hotSpotX The x coordinate of the hotspot within the cursor image * @param hotSpotY The y coordinate of the hotspot within the cursor image * @throws SlickException Indicates a failure to load the cursor image or create the hardware cursor */ public abstract void setMouseCursor(ImageData data, int hotSpotX, int hotSpotY) throws SlickException;
/** * Create an image from a pixelData of pixels * * @param buffer The pixelData to use to create the image * @param filter The filter to use when scaling this image */ Image(ImageBuffer buffer, int filter) { this((ImageData) buffer, filter); TextureImpl.bindNone(); }
/** * Create an image from a image data source * * @param data The pixelData to use to create the image */ public Image(ImageData data) { this(data, FILTER_LINEAR); }