Java Code Examples for com.watabou.gltextures.TextureCache

The following examples show how to use com.watabou.gltextures.TextureCache. These examples are extracted from open source projects. 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: YetAnotherPixelDungeon   Source File: Halo.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Halo() {
	super();
	
	if (!TextureCache.contains( CACHE_KEY )) {
		Bitmap bmp = Bitmap.createBitmap( RADIUS * 2, RADIUS * 2, Bitmap.Config.ARGB_8888 );
		Canvas canvas = new Canvas( bmp );
		Paint paint = new Paint();
		paint.setColor( 0xFFFFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS * 0.75f, paint );
		paint.setColor( 0x88FFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS, paint );
		TextureCache.add( CACHE_KEY, new SmartTexture( bmp ) );
	}
	
	texture( CACHE_KEY );
	
	origin.set( RADIUS );
}
 
Example 2
public NinePatch( Object tx, int x, int y, int w, int h, int left, int top, int right, int bottom ) {
	super( 0, 0, 0, 0 );
	
	texture = TextureCache.get( tx );
	w = w == 0 ? texture.width : w;
	h = h == 0 ? texture.height : h;
	
	nWidth = width = w;
	nHeight = height = h;
	
	vertices = new float[16];
	verticesBuffer = Quad.createSet( 9 );

	marginLeft	= left;
	marginRight	= right;
	marginTop	= top;
	marginBottom= bottom;
	
	outterF = texture.uvRect( x, y, x + w, y + h );
	innerF = texture.uvRect( x + left, y + top, x + w - right, y + h - bottom );

	updateVertices();
}
 
Example 3
public TextureFilm( Object tx, int width, int height ) {
	
	SmartTexture texture = TextureCache.get( tx );
	
	texWidth = texture.width;
	texHeight = texture.height;
	
	float uw = (float)width / texWidth;
	float vh = (float)height / texHeight;
	int cols = texWidth / width;
	int rows = texHeight / height;
	
	for (int i=0; i < rows; i++) {
		for (int j=0; j < cols; j++) {
			RectF rect = new RectF( j * uw, i * vh, (j+1) * uw, (i+1) * vh );
			add( i * cols + j, rect );
		}
	}
}
 
Example 4
public WndInfoBuff(Buff buff){
	super();

	IconTitle titlebar = new IconTitle();

	icons = TextureCache.get( Assets.BUFFS_LARGE );
	film = new TextureFilm( icons, 16, 16 );

	Image buffIcon = new Image( icons );
	buffIcon.frame( film.get(buff.icon()) );
	buff.tintIcon(buffIcon);

	titlebar.icon( buffIcon );
	titlebar.label( Messages.titleCase(buff.toString()), Window.TITLE_COLOR );
	titlebar.setRect( 0, 0, WIDTH, 0 );
	add( titlebar );

	RenderedTextBlock txtInfo = PixelScene.renderTextBlock(buff.desc(), 6);
	txtInfo.maxWidth(WIDTH);
	txtInfo.setPos(titlebar.left(), titlebar.bottom() + 2*GAP);
	add( txtInfo );

	resize( WIDTH, (int)txtInfo.bottom() + 2 );
}
 
Example 5
public WndInfoBuff(Buff buff){
	super();

	IconTitle titlebar = new IconTitle();

	icons = TextureCache.get( Assets.BUFFS_LARGE );
	film = new TextureFilm( icons, 16, 16 );

	Image buffIcon = new Image( icons );
	buffIcon.frame( film.get(buff.icon()) );

	titlebar.icon( buffIcon );
	titlebar.label( Utils.capitalize(buff.toString()), Window.TITLE_COLOR );
	titlebar.setRect( 0, 0, WIDTH, 0 );
	add( titlebar );

	BitmapTextMultiline txtInfo = PixelScene.createMultiline(buff.desc(), 6);
	txtInfo.maxWidth = WIDTH;
	txtInfo.measure();
	txtInfo.x = titlebar.left();
	txtInfo.y = titlebar.bottom() + GAP;
	add( txtInfo );

	resize( WIDTH, (int)(txtInfo.y + txtInfo.height()) );
}
 
Example 6
Source Project: unleashed-pixel-dungeon   Source File: Halo.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Halo() {
	super();
	
	if (!TextureCache.contains( CACHE_KEY )) {
		Bitmap bmp = Bitmap.createBitmap( RADIUS * 2, RADIUS * 2, Bitmap.Config.ARGB_8888 );
		Canvas canvas = new Canvas( bmp );
		Paint paint = new Paint();
		paint.setColor( 0xFFFFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS * 0.75f, paint );
		paint.setColor( 0x88FFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS, paint );
		TextureCache.add( CACHE_KEY, new SmartTexture( bmp ) );
	}
	
	texture( CACHE_KEY );
	
	origin.set( RADIUS );
}
 
Example 7
Source Project: pixel-dungeon   Source File: Halo.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Halo() {
	super();
	
	if (!TextureCache.contains( CACHE_KEY )) {
		Bitmap bmp = Bitmap.createBitmap( RADIUS * 2, RADIUS * 2, Bitmap.Config.ARGB_8888 );
		Canvas canvas = new Canvas( bmp );
		Paint paint = new Paint();
		paint.setColor( 0xFFFFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS * 0.75f, paint );
		paint.setColor( 0x88FFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS, paint );
		TextureCache.add( CACHE_KEY, new SmartTexture( bmp ) );
	}
	
	texture( CACHE_KEY );
	
	origin.set( RADIUS );
}
 
Example 8
public NinePatch( Object tx, int x, int y, int w, int h, int left, int top, int right, int bottom ) {
	super( 0, 0, 0, 0 );
	
	texture = TextureCache.get( tx );
	w = w == 0 ? texture.width : w;
	h = h == 0 ? texture.height : h;
	
	nWidth = width = w;
	nHeight = height = h;
	
	vertices = new float[16];
	quads = Quad.createSet( 9 );

	marginLeft	= left;
	marginRight	= right;
	marginTop	= top;
	marginBottom= bottom;
	
	outterF = texture.uvRect( x, y, x + w, y + h );
	innerF = texture.uvRect( x + left, y + top, x + w - right, y + h - bottom );

	updateVertices();
}
 
Example 9
@Override
public void resize( int width, int height ) {
	Gdx.gl.glViewport( 0, 0, width, height );

	if (width != Game.width || height != Game.height) {
		Game.width = width;
		Game.height = height;

		Scene sc = scene();
		if (sc != null) {
			TextureCache.reload();
			Camera.reset();
			switchScene(sc.getClass());
		}
	}
}
 
Example 10
public TextureFilm( Object tx, int width, int height ) {
	
	texture = TextureCache.get( tx );
	
	texWidth = texture.width;
	texHeight = texture.height;
	
	float uw = (float)width / texWidth;
	float vh = (float)height / texHeight;
	int cols = texWidth / width;
	int rows = texHeight / height;
	
	for (int i=0; i < rows; i++) {
		for (int j=0; j < cols; j++) {
			RectF rect = new RectF( j * uw, i * vh, (j+1) * uw, (i+1) * vh );
			add( i * cols + j, rect );
		}
	}
}
 
Example 11
public WndInfoBuff(Buff buff){
	super();

	IconTitle titlebar = new IconTitle();

	icons = TextureCache.get( Assets.Interfaces.BUFFS_LARGE );
	film = new TextureFilm( icons, 16, 16 );

	Image buffIcon = new Image( icons );
	buffIcon.frame( film.get(buff.icon()) );
	buff.tintIcon(buffIcon);

	titlebar.icon( buffIcon );
	titlebar.label( Messages.titleCase(buff.toString()), Window.TITLE_COLOR );
	titlebar.setRect( 0, 0, WIDTH, 0 );
	add( titlebar );

	RenderedTextBlock txtInfo = PixelScene.renderTextBlock(buff.desc(), 6);
	txtInfo.maxWidth(WIDTH);
	txtInfo.setPos(titlebar.left(), titlebar.bottom() + 2*GAP);
	add( txtInfo );

	resize( WIDTH, (int)txtInfo.bottom() + 2 );
}
 
Example 12
public CircleArc( int triangles, float radius ) {
	
	super( 0, 0, 0, 0 );

	texture = TextureCache.createSolid( 0xFFFFFFFF );
	
	this.nTris = triangles;
	this.rad = radius;
	
	vertices = ByteBuffer.
			allocateDirect( (nTris * 2 + 1) * 4 * (Float.SIZE / 8) ).
			order( ByteOrder.nativeOrder() ).
			asFloatBuffer();
	
	indices = ByteBuffer.
			allocateDirect( nTris * 3 * Short.SIZE / 8 ).
			order( ByteOrder.nativeOrder() ).
			asShortBuffer();
	
	sweep = 1f;
	updateTriangles();
}
 
Example 13
public TextureFilm( Object tx, int width, int height ) {
	
	texture = TextureCache.get( tx );
	
	texWidth = texture.width;
	texHeight = texture.height;
	
	float uw = (float)width / texWidth;
	float vh = (float)height / texHeight;
	int cols = texWidth / width;
	int rows = texHeight / height;
	
	for (int i=0; i < rows; i++) {
		for (int j=0; j < cols; j++) {
			RectF rect = new RectF( j * uw, i * vh, (j+1) * uw, (i+1) * vh );
			add( i * cols + j, rect );
		}
	}
}
 
Example 14
public CircleArc( int triangles, float radius ) {
	
	super( 0, 0, 0, 0 );

	texture = TextureCache.createSolid( 0xFFFFFFFF );
	
	this.nTris = triangles;
	this.rad = radius;
	
	vertices = ByteBuffer.
			allocateDirect( (nTris * 2 + 1) * 4 * (Float.SIZE / 8) ).
			order( ByteOrder.nativeOrder() ).
			asFloatBuffer();
	
	indices = ByteBuffer.
			allocateDirect( nTris * 3 * Short.SIZE / 8 ).
			order( ByteOrder.nativeOrder() ).
			asShortBuffer();
	
	sweep = 1f;
	updateTriangles();
}
 
Example 15
public NinePatch( Object tx, int x, int y, int w, int h, int left, int top, int right, int bottom ) {
	super( 0, 0, 0, 0 );

	texture = TextureCache.get( tx );
	w = w == 0 ? texture.width : w;
	h = h == 0 ? texture.height : h;
	
	nWidth = width = w;
	nHeight = height = h;
	
	vertices = new float[16];
	quads = Quad.createSet( 9 );

	marginLeft	= left;
	marginRight	= right;
	marginTop	= top;
	marginBottom= bottom;
	
	outterF = texture.uvRect( x, y, x + w, y + h );
	innerF = texture.uvRect( x + left, y + top, x + w - right, y + h - bottom );

	updateVertices();
}
 
Example 16
Source Project: PD-classes   Source File: TextureFilm.java    License: GNU General Public License v3.0 6 votes vote down vote up
public TextureFilm( Object tx, int width, int height ) {
	
	SmartTexture texture = TextureCache.get( tx );
	
	texWidth = texture.width;
	texHeight = texture.height;
	
	float uw = (float)width / texWidth;
	float vh = (float)height / texHeight;
	int cols = texWidth / width;
	int rows = texHeight / height;
	
	for (int i=0; i < rows; i++) {
		for (int j=0; j < cols; j++) {
			RectF rect = new RectF( j * uw, i * vh, (j+1) * uw, (i+1) * vh );
			add( i * cols + j, rect );
		}
	}
}
 
Example 17
Source Project: remixed-dungeon   Source File: CircleMask.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static void ensureTexture() {
	if (!TextureCache.contains( CACHE_KEY )) {

		Bitmap bmp = Bitmap.createBitmap( RADIUS * 2, RADIUS * 2, Bitmap.Config.ARGB_8888 );
		Canvas canvas = new Canvas( bmp );
		Paint paint = new Paint();
		canvas.drawColor(Color.WHITE, PorterDuff.Mode.SRC);

		paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
		paint.setColor( 0xf7ffffff);
		canvas.drawCircle( RADIUS, RADIUS, RADIUS, paint );

		paint.setColor( 0x77ffffff);
		canvas.drawCircle( RADIUS, RADIUS, RADIUS*0.75f, paint );

		paint.setColor( 0x00ffffff);
		canvas.drawCircle( RADIUS, RADIUS, RADIUS*0.5f, paint );
		TextureCache.add( CACHE_KEY, new SmartTexture( bmp ) );
	}
}
 
Example 18
Source Project: remixed-dungeon   Source File: Halo.java    License: GNU General Public License v3.0 6 votes vote down vote up
public Halo() {
	if (!TextureCache.contains( CACHE_KEY )) {
		Bitmap bmp = Bitmap.createBitmap( RADIUS * 2, RADIUS * 2, Bitmap.Config.ARGB_8888 );
		Canvas canvas = new Canvas( bmp );
		Paint paint = new Paint();
		paint.setColor( 0xFFFFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS * 0.75f, paint );
		paint.setColor( 0x88FFFFFF );
		canvas.drawCircle( RADIUS, RADIUS, RADIUS, paint );
		TextureCache.add( CACHE_KEY, new SmartTexture( bmp ) );
	}
	
	texture( CACHE_KEY );
	
	origin.set( RADIUS );
}
 
Example 19
public static int pick( int index, int x, int y ) {
	Bitmap bmp = TextureCache.get( Assets.ITEMS ).bitmap;
	int rows = bmp.getWidth() / SIZE;
	int row = index / rows;
	int col = index % rows;
	return bmp.getPixel( col * SIZE + x, row * SIZE + y );
}
 
Example 20
public CheckedCell( int pos ) {
	super( TextureCache.createSolid( 0xFF55AAFF ) );

	origin.set( 0.5f );
	
	point( DungeonTilemap.tileToWorld( pos ).offset( 
		DungeonTilemap.SIZE / 2, 
		DungeonTilemap.SIZE / 2 ) );
	
	alpha = 0.8f;
}
 
Example 21
public FogOfWar( int mapWidth, int mapHeight ) {
	
	super();

	this.mapWidth = mapWidth;
	this.mapHeight = mapHeight;
	mapLength = mapHeight * mapWidth;
	
	pWidth = mapWidth * PIX_PER_TILE;
	pHeight = mapHeight * PIX_PER_TILE;
	
	width2 = 1;
	while (width2 < pWidth) {
		width2 <<= 1;
	}
	
	height2 = 1;
	while (height2 < pHeight) {
		height2 <<= 1;
	}
	
	float size = DungeonTilemap.SIZE / PIX_PER_TILE;
	width = width2 * size;
	height = height2 * size;
	
	BufferTexture tx = new BufferTexture(width2, height2);
	TextureCache.add(FogOfWar.class, tx);
	texture( tx );
	
	scale.set(
		DungeonTilemap.SIZE / PIX_PER_TILE,
		DungeonTilemap.SIZE / PIX_PER_TILE);

	toUpdate = new ArrayList<>();
	toUpdate.add(new Rect(0, 0, mapWidth, mapHeight));
}
 
Example 22
@Override
public void destroy() {
	super.destroy();
	if (texture != null){
		TextureCache.remove(FogOfWar.class);
	}
}
 
Example 23
Source Project: YetAnotherPixelDungeon   Source File: Game.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onSurfaceCreated( GL10 gl, EGLConfig config ) {
	GLES20.glEnable( GL10.GL_BLEND );
	// For premultiplied alpha:
	// GLES20.glBlendFunc( GL10.GL_ONE, GL10.GL_ONE_MINUS_SRC_ALPHA );
	GLES20.glBlendFunc( GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA );
	
	GLES20.glEnable( GL10.GL_SCISSOR_TEST );
	
	TextureCache.reload();
}
 
Example 24
public Sky( boolean dayTime ) {
	super( 0, 0, 1, 1 );

	texture = TextureCache.createGradient( dayTime ? day : night );
	
	float[] vertices = new float[16];
	verticesBuffer = Quad.create();
	
	vertices[2]		= 0.25f;
	vertices[6]		= 0.25f;
	vertices[10]	= 0.75f;
	vertices[14]	= 0.75f;
	
	vertices[3]		= 0;
	vertices[7]		= 1;
	vertices[11]	= 1;
	vertices[15]	= 0;
	
	
	vertices[0] 	= 0;
	vertices[1] 	= 0;
	
	vertices[4] 	= 1;
	vertices[5] 	= 0;
	
	vertices[8] 	= 1;
	vertices[9] 	= 1;
	
	vertices[12]	= 0;
	vertices[13]	= 1;
	
	verticesBuffer.position( 0 );
	verticesBuffer.put( vertices );
}
 
Example 25
public static int pick( int index, int x, int y ) {
	Bitmap bmp = TextureCache.get( Assets.ITEMS ).bitmap;
	int rows = bmp.getWidth() / SIZE;
	int row = index / rows;
	int col = index % rows;
	return bmp.getPixel( col * SIZE + x, row * SIZE + y );
}
 
Example 26
@Override
protected void createChildren() {
	bg = new Image( TextureCache.createSolid( 0xFFcc0000 ) );
	bg.scale.y = HEIGHT;
	add( bg );
	
	level = new Image( TextureCache.createSolid( 0xFF00cc00 ) );
	level.scale.y = HEIGHT;
	add( level );
}
 
Example 27
Source Project: pixel-dungeon   Source File: ItemSprite.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static int pick( int index, int x, int y ) {
	Bitmap bmp = TextureCache.get( Assets.ITEMS ).bitmap;
	int rows = bmp.getWidth() / SIZE;
	int row = index / rows;
	int col = index % rows;
	return bmp.getPixel( col * SIZE + x, row * SIZE + y );
}
 
Example 28
Source Project: pixel-dungeon   Source File: HeroSprite.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static TextureFilm tiers() {
	if (tiers == null) {
		SmartTexture texture = TextureCache.get( Assets.ROGUE );
		tiers = new TextureFilm( texture, texture.width, FRAME_HEIGHT );
	}
	
	return tiers;
}
 
Example 29
Source Project: pixel-dungeon   Source File: CheckedCell.java    License: GNU General Public License v3.0 5 votes vote down vote up
public CheckedCell( int pos ) {
	super( TextureCache.createSolid( 0xFF55AAFF ) );

	origin.set( 0.5f );
	
	point( DungeonTilemap.tileToWorld( pos ).offset( 
		DungeonTilemap.SIZE / 2, 
		DungeonTilemap.SIZE / 2 ) );
	
	alpha = 0.8f;
}
 
Example 30
Source Project: shattered-pixel-dungeon   Source File: Game.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void resize(int width, int height) {
	if (width == 0 || height == 0){
		return;
	}

	//If the EGL context was destroyed, we need to refresh some data stored on the GPU.
	// This checks that by seeing if GLVersion has a new object reference
	if (versionContextRef != Gdx.graphics.getGLVersion()) {
		versionContextRef = Gdx.graphics.getGLVersion();
		Blending.useDefault();
		TextureCache.reload();
		Vertexbuffer.refreshAllBuffers();
	}
	
	if (height != Game.height || width != Game.width) {
		
		Game.width = width;
		Game.height = height;
		
		//TODO might be better to put this in platform support
		if (Gdx.app.getType() != Application.ApplicationType.Android){
			Game.dispWidth = Game.width;
			Game.dispHeight = Game.height;
		}
		
		resetScene();
	}
}