org.newdawn.slick.opengl.TextureImpl Java Examples

The following examples show how to use org.newdawn.slick.opengl.TextureImpl. 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: slick2d-maven   Author: nguillaumin   File: PBufferGraphics.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.Graphics#enable()
 */
protected void enable() {
	SlickCallable.enterSafeBlock();
	
	try {
		if (pbuffer.isBufferLost()) {
			pbuffer.destroy();
			init();
		}

		pbuffer.makeCurrent();
	} catch (Exception e) {
		Log.error("Failed to recreate the PBuffer");
		throw new RuntimeException(e);
	}
	
	// Put the renderer contents to the texture
	GL.glBindTexture(GL11.GL_TEXTURE_2D, image.getTexture().getTextureID());
	pbuffer.releaseTexImage(Pbuffer.FRONT_LEFT_BUFFER);
	TextureImpl.unbind();
	initGL();
}
 
Example #2
Source Project: slick2d-maven   Author: nguillaumin   File: PBufferUniqueGraphics.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * @see org.newdawn.slick.Graphics#enable()
 */
protected void enable() {
	SlickCallable.enterSafeBlock();
	
	try {
		if (pbuffer.isBufferLost()) {
			pbuffer.destroy();
			init();
		}

		pbuffer.makeCurrent();
	} catch (Exception e) {
		Log.error("Failed to recreate the PBuffer");
		Log.error(e);
		throw new RuntimeException(e);
	}
	
	// Put the renderer contents to the texture
	TextureImpl.unbind();
	initGL();
}
 
Example #3
Source Project: slick2d-maven   Author: nguillaumin   File: ShapeRenderer.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Draw the outline of the given shape.  Only the vertices are set.  
 * The colour has to be set independently of this method.
 * 
 * @param shape The shape to draw.
 */
public static final void draw(Shape shape) {
    Texture t = TextureImpl.getLastBind();
    TextureImpl.bindNone();
    
    float points[] = shape.getPoints();
    
    LSR.start();
    for(int i=0;i<points.length;i+=2) {
    	LSR.vertex(points[i], points[i + 1]);
    }
    
    if (shape.closed()) {
    	LSR.vertex(points[0], points[1]);
    }
    
    LSR.end();
    
    if (t == null) {
    	TextureImpl.bindNone();
    } else {
    	t.bind();
    }
}
 
Example #4
Source Project: slick2d-maven   Author: nguillaumin   File: SimpleDiagramRenderer.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Render the diagram to the given graphics context
 * 
 * @param g The graphics context to which we should render the diagram
 */
public void render(Graphics g) {
	// last list generation
	if (list == -1) {
		list = GL.glGenLists(1);
		GL.glNewList(list, SGL.GL_COMPILE);
			render(g, diagram);
		GL.glEndList();
	}
	
	GL.glCallList(list);
	
	TextureImpl.bindNone();
}
 
Example #5
Source Project: slick2d-maven   Author: nguillaumin   File: Particle.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Render this particle
 */
public void render() {
	if ((engine.usePoints() && (usePoints == INHERIT_POINTS))
			|| (usePoints == USE_POINTS)) {
		TextureImpl.bindNone();
		GL.glEnable(SGL.GL_POINT_SMOOTH);
		GL.glPointSize(size / 2);
		color.bind();
		GL.glBegin(SGL.GL_POINTS);
		GL.glVertex2f(x, y);
		GL.glEnd();
	} else if (oriented || scaleY != 1.0f) {
		GL.glPushMatrix();

		GL.glTranslatef(x, y, 0f);

		if (oriented) {
			float angle = (float) (Math.atan2(y, x) * 180 / Math.PI);
			GL.glRotatef(angle, 0f, 0f, 1.0f);
		}

		// scale
		GL.glScalef(1.0f, scaleY, 1.0f);

		image.draw((int) (-(size / 2)), (int) (-(size / 2)), (int) size,
				(int) size, color);
		GL.glPopMatrix();
	} else {
		color.bind();
		image.drawEmbedded((int) (x - (size / 2)), (int) (y - (size / 2)),
				(int) size, (int) size);
	}
}
 
Example #6
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draw the outline of the given shape.
 * 
 * @param shape
 *            The shape to draw.
 * @param fill
 *            The fill type to apply
 */
public void draw(Shape shape, ShapeFill fill) {
	predraw();
	TextureImpl.bindNone();

	ShapeRenderer.draw(shape, fill);

	currentColor.bind();
	postdraw();
}
 
Example #7
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draw the outline of the given shape.
 * 
 * @param shape
 *            The shape to draw.
 */
public void draw(Shape shape) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	ShapeRenderer.draw(shape);

	postdraw();
}
 
Example #8
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draw the the given shape filled in.
 * 
 * @param shape
 *            The shape to fill.
 */
public void fill(Shape shape) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	ShapeRenderer.fill(shape);

	postdraw();
}
 
Example #9
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draw the the given shape filled in with a texture
 * 
 * @param shape
 *            The shape to texture.
 * @param image
 *            The image to tile across the shape
 * @param scaleX
 *            The scale to apply on the x axis for texturing
 * @param scaleY
 *            The scale to apply on the y axis for texturing
 * @param fit
 *            True if we want to fit the image on to the shape
 */
public void texture(Shape shape, Image image, float scaleX, float scaleY,
		boolean fit) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	if (fit) {
		ShapeRenderer.textureFit(shape, image, scaleX, scaleY);
	} else {
		ShapeRenderer.texture(shape, image, scaleX, scaleY);
	}
	
	postdraw();
}
 
Example #10
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Fill a rectangle on the canvas in the current color
 * 
 * @param x1
 *            The x coordinate of the top left corner
 * @param y1
 *            The y coordinate of the top left corner
 * @param width
 *            The width of the rectangle to fill
 * @param height
 *            The height of the rectangle to fill
 */
public void fillRect(float x1, float y1, float width, float height) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	GL.glBegin(SGL.GL_QUADS);
	GL.glVertex2f(x1, y1);
	GL.glVertex2f(x1 + width, y1);
	GL.glVertex2f(x1 + width, y1 + height);
	GL.glVertex2f(x1, y1 + height);
	GL.glEnd();
	postdraw();
}
 
Example #11
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Draw an oval to the canvas
 * 
 * @param x1
 *            The x coordinate of the top left corner of a box containing
 *            the arc
 * @param y1
 *            The y coordinate of the top left corner of a box containing
 *            the arc
 * @param width
 *            The width of the arc
 * @param height
 *            The height of the arc
 * @param segments
 *            The number of line segments to use when drawing the arc
 * @param start
 *            The angle the arc starts at
 * @param end
 *            The angle the arc ends at
 */
public void drawArc(float x1, float y1, float width, float height,
		int segments, float start, float end) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	while (end < start) {
		end += 360;
	}

	float cx = x1 + (width / 2.0f);
	float cy = y1 + (height / 2.0f);

	LSR.start();
	int step = 360 / segments;

	for (int a = (int) start; a < (int) (end + step); a += step) {
		float ang = a;
		if (ang > end) {
			ang = end;
		}
		float x = (float) (cx + (FastTrig.cos(Math.toRadians(ang)) * width / 2.0f));
		float y = (float) (cy + (FastTrig.sin(Math.toRadians(ang)) * height / 2.0f));

		LSR.vertex(x,y);
	}
	LSR.end();
	postdraw();
}
 
Example #12
Source Project: slick2d-maven   Author: nguillaumin   File: ParticleSystem.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Render the particles in the system
 * 
 * @param x The x coordinate to render the particle system at (in the current coordinate space)
 * @param y The y coordinate to render the particle system at (in the current coordiante space)
 */
public void render(float x, float y) {
	if ((sprite == null) && (defaultImageName != null)) {
		loadSystemParticleImage();
	}
	
	if (!visible) {
		return;
	}
	
	GL.glTranslatef(x,y,0);
	
	if (blendingMode == BLEND_ADDITIVE) {
		GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
	}
	if (usePoints()) {
		GL.glEnable( SGL.GL_POINT_SMOOTH ); 
		TextureImpl.bindNone();
	}
	
	// iterate over all emitters
	for( int emitterIdx=0; emitterIdx<emitters.size(); emitterIdx++ )
	{
		// get emitter
		ParticleEmitter emitter = (ParticleEmitter) emitters.get(emitterIdx);
		
		if (!emitter.isEnabled()) {
			continue;
		}
		
		// check for additive override and enable when set
		if (emitter.useAdditive()) {
			GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE);
		}
		
		// now get the particle pool for this emitter and render all particles that are in use
		ParticlePool pool = (ParticlePool) particlesByEmitter.get(emitter);
		Image image = emitter.getImage();
		if (image == null) {
			image = this.sprite;
		}
		
		if (!emitter.isOriented() && !emitter.usePoints(this)) {
			image.startUse();
		}
		
		for (int i = 0; i < pool.particles.length; i++)
		{
			if (pool.particles[i].inUse())
				pool.particles[i].render();
		} 
		
		if (!emitter.isOriented() && !emitter.usePoints(this)) {
			image.endUse();
		}

		// reset additive blend mode
		if (emitter.useAdditive()) {
			GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA);
		}
	}

	if (usePoints()) {
		GL.glDisable( SGL.GL_POINT_SMOOTH ); 
	}
	if (blendingMode == BLEND_ADDITIVE) {
		GL.glBlendFunc(SGL.GL_SRC_ALPHA, SGL.GL_ONE_MINUS_SRC_ALPHA);
	}
	
	Color.white.bind();
	GL.glTranslatef(-x,-y,0);
}
 
Example #13
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 #14
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Draw a line with a gradient between the two points.
 * 
 * @param x1
 *            The starting x position to draw the line
 * @param y1
 *            The starting y position to draw the line
 * @param red1
 *            The starting position's shade of red
 * @param green1
 *            The starting position's shade of green
 * @param blue1
 *            The starting position's shade of blue
 * @param alpha1
 *            The starting position's alpha value
 * @param x2
 *            The ending x position to draw the line
 * @param y2
 *            The ending y position to draw the line
 * @param red2
 *            The ending position's shade of red
 * @param green2
 *            The ending position's shade of green
 * @param blue2
 *            The ending position's shade of blue
 * @param alpha2
 *            The ending position's alpha value
 */
public void drawGradientLine(float x1, float y1, float red1, float green1,
								float blue1, float alpha1, float x2, float y2, float red2,
								float green2, float blue2, float alpha2) {
	predraw();

	TextureImpl.bindNone();

	GL.glBegin(SGL.GL_LINES);

	GL.glColor4f(red1, green1, blue1, alpha1);
	GL.glVertex2f(x1, y1);

	GL.glColor4f(red2, green2, blue2, alpha2);
	GL.glVertex2f(x2, y2);

	GL.glEnd();

	postdraw();
}
 
Example #15
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Draw a line with a gradient between the two points.
 * 
 * @param x1
 *            The starting x position to draw the line
 * @param y1
 *            The starting y position to draw the line
 * @param Color1
 *            The starting position's color
 * @param x2
 *            The ending x position to draw the line
 * @param y2
 *            The ending y position to draw the line
 * @param Color2
 *            The ending position's color
 */
public void drawGradientLine(float x1, float y1, Color Color1, float x2,
							 float y2, Color Color2) {
	predraw();

	TextureImpl.bindNone();

	GL.glBegin(SGL.GL_LINES);

	Color1.bind();
	GL.glVertex2f(x1, y1);

	Color2.bind();
	GL.glVertex2f(x2, y2);

	GL.glEnd();

	postdraw();
}
 
Example #16
Source Project: slick2d-maven   Author: nguillaumin   File: Graphics.java    License: BSD 3-Clause "New" or "Revised" License 3 votes vote down vote up
/**
 * Draw the the given shape filled in with a texture
 * 
 * @param shape
 *            The shape to texture.
 * @param image
 *            The image to tile across the shape
 * @param scaleX
 *            The scale to apply on the x axis for texturing
 * @param scaleY
 *            The scale to apply on the y axis for texturing
 * @param fill
 *            The shape fill to apply
 */
public void texture(Shape shape, Image image, float scaleX, float scaleY,
		ShapeFill fill) {
	predraw();
	TextureImpl.bindNone();
	currentColor.bind();

	ShapeRenderer.texture(shape, image, scaleX, scaleY, fill);

	postdraw();
}
 
Example #17
Source Project: opsu-dance   Author: yugecin   File: Image.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create an image from a pixelData of pixels
 * 
 * @param buffer The pixelData to use to create the image
 */
Image(ImageBuffer buffer) {
	this(buffer, FILTER_LINEAR);
       TextureImpl.bindNone();
}
 
Example #18
Source Project: opsu-dance   Author: yugecin   File: Image.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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();
}
 
Example #19
Source Project: opsu   Author: itdelatrisu   File: Image.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * Create an image from a pixelData of pixels
 * 
 * @param buffer The pixelData to use to create the image
 */
Image(ImageBuffer buffer) {
	this(buffer, FILTER_LINEAR);
       TextureImpl.bindNone();
}
 
Example #20
Source Project: opsu   Author: itdelatrisu   File: Image.java    License: GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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();
}
 
Example #21
Source Project: slick2d-maven   Author: nguillaumin   File: Image.java    License: BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Create an image from a pixelData of pixels
 * 
 * @param buffer The pixelData to use to create the image
 */
Image(ImageBuffer buffer) {
	this(buffer, FILTER_LINEAR);
       TextureImpl.bindNone();
}
 
Example #22
Source Project: slick2d-maven   Author: nguillaumin   File: Image.java    License: BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * 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();
}