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 Project: opsu-dance   Author: yugecin   File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 Project: opsu-dance   Author: yugecin   File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 Project: opsu   Author: itdelatrisu   File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #4
Source Project: opsu   Author: itdelatrisu   File: Image.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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 #5
Source Project: slick2d-maven   Author: nguillaumin   File: Image.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #6
Source Project: slick2d-maven   Author: nguillaumin   File: Image.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 Project: slick2d-maven   Author: nguillaumin   File: PBufferGraphics.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #8
Source Project: slick2d-maven   Author: nguillaumin   File: PBufferUniqueGraphics.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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 #9
Source Project: opsu-dance   Author: yugecin   File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 Project: opsu-dance   Author: yugecin   File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #11
Source Project: opsu-dance   Author: yugecin   File: DisplayContainer.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void destroyImages() {
	InternalTextureLoader.get().clear();
	GameImage.destroyImages();
	GameData.Grade.destroyImages();
	Beatmap.destroyBackgroundImageCache();
	FrameBufferCache.shutdown();
}
 
Example #12
Source Project: opsu   Author: itdelatrisu   File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #13
Source Project: opsu   Author: itdelatrisu   File: Image.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #14
Source Project: opsu   Author: itdelatrisu   File: Container.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 #15
Source Project: slick2d-maven   Author: nguillaumin   File: AppletGameContainer.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 Project: slick2d-maven   Author: nguillaumin   File: AppGameContainer.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * @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 #17
Source Project: slick2d-maven   Author: nguillaumin   File: Image.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #18
Source Project: slick2d-maven   Author: nguillaumin   File: Image.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #19
Source Project: slick2d-maven   Author: nguillaumin   File: FBOGraphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #20
Source Project: slick2d-maven   Author: nguillaumin   File: LoadingList.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 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 #21
Source Project: slick2d-maven   Author: nguillaumin   File: BufferedImageUtil.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * 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 Project: slick2d-maven   Author: nguillaumin   File: LoadingList.java    License: BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Check if we're using deferred loading 
 * 
 * @return True if we're using deferred loading
 */
public static boolean isDeferredLoading() {
	return InternalTextureLoader.get().isDeferredLoading();
}