org.newdawn.slick.opengl.InternalTextureLoader Java Examples
The following examples show how to use
org.newdawn.slick.opengl.InternalTextureLoader.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Image.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Create an image based on a file at the specified location * * @param ref The location of the image file to load * @param flipped True if the image should be flipped on the y-axis on load * @param f The filtering method to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; this.transparent = transparent; this.flipped = flipped; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #2
Source File: Image.java From opsu-dance with GNU General Public License v3.0 | 6 votes |
/** * Load the image * * @param in The input stream to read the image from * @param ref The name that should be assigned to the image * @param flipped True if the image should be flipped on the y-axis on load * @param f The filter to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #3
Source File: PBufferUniqueGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the PBuffer that will be used to render to * * @throws SlickException */ private void init() throws SlickException { try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), null, null); // Initialise state of the pbuffer context. pbuffer.makeCurrent(); initGL(); image.draw(0,0); GL11.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID()); GL11.glCopyTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGBA, 0, 0, tex.getTextureWidth(), tex.getTextureHeight(), 0); image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
Example #4
Source File: Image.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Create an image based on a file at the specified location * * @param ref The location of the image file to load * @param flipped True if the image should be flipped on the y-axis on load * @param f The filtering method to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; this.transparent = transparent; this.flipped = flipped; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #5
Source File: PBufferGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Initialise the PBuffer that will be used to render to * * @throws SlickException */ private void init() throws SlickException { try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); final RenderTexture rt = new RenderTexture(false, true, false, false, RenderTexture.RENDER_TEXTURE_2D, 0); pbuffer = new Pbuffer(screenWidth, screenHeight, new PixelFormat(8, 0, 0), rt, null); // Initialise state of the pbuffer context. pbuffer.makeCurrent(); initGL(); GL.glBindTexture(GL11.GL_TEXTURE_2D, tex.getTextureID()); pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER); image.draw(0,0); image.setTexture(tex); Display.makeCurrent(); } catch (Exception e) { Log.error(e); throw new SlickException("Failed to create PBuffer for dynamic image. OpenGL driver failure?"); } }
Example #6
Source File: Image.java From opsu with GNU General Public License v3.0 | 6 votes |
/** * Load the image * * @param in The input stream to read the image from * @param ref The name that should be assigned to the image * @param flipped True if the image should be flipped on the y-axis on load * @param f The filter to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #7
Source File: Image.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Load the image * * @param in The input stream to read the image from * @param ref The name that should be assigned to the image * @param flipped True if the image should be flipped on the y-axis on load * @param f The filter to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ private void load(InputStream in, String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(in, ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #8
Source File: Image.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Create an image based on a file at the specified location * * @param ref The location of the image file to load * @param flipped True if the image should be flipped on the y-axis on load * @param f The filtering method to use when scaling this image * @param transparent The color to treat as transparent * @throws SlickException Indicates a failure to load the image */ public Image(String ref, boolean flipped, int f, Color transparent) throws SlickException { this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; this.transparent = transparent; this.flipped = flipped; try { this.ref = ref; int[] trans = null; if (transparent != null) { trans = new int[3]; trans[0] = (int) (transparent.r * 255); trans[1] = (int) (transparent.g * 255); trans[2] = (int) (transparent.b * 255); } texture = InternalTextureLoader.get().getTexture(ref, flipped, filter, trans); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to load image from: "+ref, e); } }
Example #9
Source File: Image.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * Create an empty image * * @param width The width of the image * @param height The height of the image * @param f The filter to apply to scaling the new image * @throws SlickException Indicates a failure to create the underlying resource */ public Image(int width, int height, int f) throws SlickException { ref = super.toString(); this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { texture = InternalTextureLoader.get().createTexture(width, height, this.filter); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to create empty image "+width+"x"+height); } init(); }
Example #10
Source File: LoadingList.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Indicate if we're going to use deferred loading. (Also clears the current list) * * @param loading True if we should use deferred loading */ public static void setDeferredLoading(boolean loading) { single = new LoadingList(); InternalTextureLoader.get().setDeferredLoading(loading); SoundStore.get().setDeferredLoading(loading); }
Example #11
Source File: FBOGraphics.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initialise the FBO that will be used to render to * * @throws SlickException */ private void init() throws SlickException { IntBuffer buffer = BufferUtils.createIntBuffer(1); EXTFramebufferObject.glGenFramebuffersEXT(buffer); FBO = buffer.get(); // for some reason FBOs won't work on textures unless you've absolutely just // created them. try { Texture tex = InternalTextureLoader.get().createTexture(image.getWidth(), image.getHeight(), image.getFilter()); EXTFramebufferObject.glBindFramebufferEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, FBO); EXTFramebufferObject.glFramebufferTexture2DEXT(EXTFramebufferObject.GL_FRAMEBUFFER_EXT, EXTFramebufferObject.GL_COLOR_ATTACHMENT0_EXT, GL11.GL_TEXTURE_2D, tex.getTextureID(), 0); completeCheck(); unbind(); // Clear our destination area before using it clear(); flush(); // keep hold of the original content drawImage(image, 0, 0); image.setTexture(tex); } catch (Exception e) { throw new SlickException("Failed to create new texture for FBO"); } }
Example #12
Source File: Image.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * 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); } }
Example #13
Source File: Image.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create an empty image * * @param width The width of the image * @param height The height of the image * @param f The filter to apply to scaling the new image * @throws SlickException Indicates a failure to create the underlying resource */ public Image(int width, int height, int f) throws SlickException { ref = super.toString(); this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { texture = InternalTextureLoader.get().createTexture(width, height, this.filter); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to create empty image "+width+"x"+height); } init(); }
Example #14
Source File: AppGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * @see org.newdawn.slick.GameContainer#reinit() */ public void reinit() throws SlickException { InternalTextureLoader.get().clear(); SoundStore.get().clear(); initSystem(); enterOrtho(); try { game.init(this); } catch (SlickException e) { Log.error(e); running = false; } }
Example #15
Source File: AppletGameContainer.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initialise GL state */ protected void initGL() { try { InternalTextureLoader.get().clear(); SoundStore.get().clear(); container.initApplet(); } catch (Exception e) { Log.error(e); container.stopApplet(); } }
Example #16
Source File: Container.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Actions to perform before destroying the game container. */ private void close_sub() { // save user options Options.saveOptions(); // reset cursor UI.getCursor().reset(); // destroy images InternalTextureLoader.get().clear(); // reset image references GameImage.clearReferences(); GameData.Grade.clearReferences(); Beatmap.clearBackgroundImageCache(); // prevent loading tracks from re-initializing OpenAL MusicController.reset(); // stop any playing track SoundController.stopTrack(); // reset BeatmapSetList data BeatmapGroup.set(BeatmapGroup.ALL); BeatmapSortOrder.set(BeatmapSortOrder.TITLE); if (BeatmapSetList.get() != null) BeatmapSetList.get().reset(); // delete OpenGL objects involved in the Curve rendering CurveRenderState.shutdown(); LegacyCurveRenderState.shutdown(); // destroy watch service if (!Options.isWatchServiceEnabled()) BeatmapWatchService.destroy(); BeatmapWatchService.removeListeners(); // delete temporary directory Utils.deleteDirectory(Options.TEMP_DIR); }
Example #17
Source File: Image.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * 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); } }
Example #18
Source File: Image.java From opsu with GNU General Public License v3.0 | 5 votes |
/** * Create an empty image * * @param width The width of the image * @param height The height of the image * @param f The filter to apply to scaling the new image * @throws SlickException Indicates a failure to create the underlying resource */ public Image(int width, int height, int f) throws SlickException { ref = super.toString(); this.filter = f == FILTER_LINEAR ? SGL.GL_LINEAR : SGL.GL_NEAREST; try { texture = InternalTextureLoader.get().createTexture(width, height, this.filter); } catch (IOException e) { Log.error(e); throw new SlickException("Failed to create empty image "+width+"x"+height); } init(); }
Example #19
Source File: DisplayContainer.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
public void destroyImages() { InternalTextureLoader.get().clear(); GameImage.destroyImages(); GameData.Grade.destroyImages(); Beatmap.destroyBackgroundImageCache(); FrameBufferCache.shutdown(); }
Example #20
Source File: Image.java From opsu-dance with GNU General Public License v3.0 | 5 votes |
/** * 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); } }
Example #21
Source File: BufferedImageUtil.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Load a texture into OpenGL from a BufferedImage * * @param resourceName * The location of the resource to load * @param resourceimage * The BufferedImage we are converting * @param target * The GL target to load the texture against * @param dstPixelFormat * The pixel format of the screen * @param minFilter * The minimising filter * @param magFilter * The magnification filter * @return The loaded texture * @throws IOException * Indicates a failure to access the resource */ public static Texture getTexture(String resourceName, BufferedImage resourceimage, int target, int dstPixelFormat, int minFilter, int magFilter) throws IOException { ImageIOImageData data = new ImageIOImageData();int srcPixelFormat = 0; // create the texture ID for this texture int textureID = InternalTextureLoader.createTextureID(); TextureImpl texture = new TextureImpl(resourceName, target, textureID); // Enable texturing Renderer.get().glEnable(SGL.GL_TEXTURE_2D); // bind this texture Renderer.get().glBindTexture(target, textureID); BufferedImage bufferedImage = resourceimage; texture.setWidth(bufferedImage.getWidth()); texture.setHeight(bufferedImage.getHeight()); if (bufferedImage.getColorModel().hasAlpha()) { srcPixelFormat = SGL.GL_RGBA; } else { srcPixelFormat = SGL.GL_RGB; } // convert that image into a byte buffer of texture data ByteBuffer textureBuffer = data.imageToByteBuffer(bufferedImage, false, false, null); texture.setTextureHeight(data.getTexHeight()); texture.setTextureWidth(data.getTexWidth()); texture.setAlpha(data.getDepth() == 32); if (target == SGL.GL_TEXTURE_2D) { Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MIN_FILTER, minFilter); Renderer.get().glTexParameteri(target, SGL.GL_TEXTURE_MAG_FILTER, magFilter); if (Renderer.get().canTextureMirrorClamp()) { Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT); Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_MIRROR_CLAMP_TO_EDGE_EXT); } else { Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_S, SGL.GL_CLAMP); Renderer.get().glTexParameteri(SGL.GL_TEXTURE_2D, SGL.GL_TEXTURE_WRAP_T, SGL.GL_CLAMP); } } Renderer.get().glTexImage2D(target, 0, dstPixelFormat, texture.getTextureWidth(), texture.getTextureHeight(), 0, srcPixelFormat, SGL.GL_UNSIGNED_BYTE, textureBuffer); return texture; }
Example #22
Source File: LoadingList.java From slick2d-maven with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Check if we're using deferred loading * * @return True if we're using deferred loading */ public static boolean isDeferredLoading() { return InternalTextureLoader.get().isDeferredLoading(); }