Search in sources :

Example 1 with ITexture

use of org.andengine.opengl.texture.ITexture in project AndEngine by nicolasgramlich.

the class TexturePackParser method parseTexture.

private ITexture parseTexture(final Attributes pAttributes) throws TexturePackParseException {
    final String file = SAXUtils.getAttributeOrThrow(pAttributes, TexturePackParser.TAG_TEXTURE_ATTRIBUTE_FILE);
    if (this.mTextureManager.hasMappedTexture(file)) {
        return this.mTextureManager.getMappedTexture(file);
    }
    final String type = SAXUtils.getAttributeOrThrow(pAttributes, TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE);
    final PixelFormat pixelFormat = TexturePackParser.parsePixelFormat(pAttributes);
    final TextureOptions textureOptions = this.parseTextureOptions(pAttributes);
    final ITexture texture;
    if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_BITMAP)) {
        try {
            texture = new BitmapTexture(this.mTextureManager, new IInputStreamOpener() {

                @Override
                public InputStream open() throws IOException {
                    return TexturePackParser.this.onGetInputStream(file);
                }
            }, BitmapTextureFormat.fromPixelFormat(pixelFormat), textureOptions);
        } catch (final IOException e) {
            throw new TexturePackParseException(e);
        }
    } else if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_PVR)) {
        try {
            texture = new PVRTexture(this.mTextureManager, PVRTextureFormat.fromPixelFormat(pixelFormat), new SmartPVRTexturePixelBufferStrategy(DataConstants.BYTES_PER_MEGABYTE / 8), textureOptions) {

                @Override
                protected InputStream onGetInputStream() throws IOException {
                    return TexturePackParser.this.onGetInputStream(file);
                }
            };
        } catch (final IOException e) {
            throw new TexturePackParseException(e);
        }
    } else if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_PVRGZ)) {
        try {
            texture = new PVRGZTexture(this.mTextureManager, PVRTextureFormat.fromPixelFormat(pixelFormat), new SmartPVRTexturePixelBufferStrategy(DataConstants.BYTES_PER_MEGABYTE / 8), textureOptions) {

                @Override
                protected InputStream onGetInputStream() throws IOException {
                    return TexturePackParser.this.onGetInputStream(file);
                }
            };
        } catch (final IOException e) {
            throw new TexturePackParseException(e);
        }
    } else if (type.equals(TexturePackParser.TAG_TEXTURE_ATTRIBUTE_TYPE_VALUE_PVRCCZ)) {
        try {
            texture = new PVRCCZTexture(this.mTextureManager, PVRTextureFormat.fromPixelFormat(pixelFormat), new SmartPVRTexturePixelBufferStrategy(DataConstants.BYTES_PER_MEGABYTE / 8), textureOptions) {

                @Override
                protected InputStream onGetInputStream() throws IOException {
                    return TexturePackParser.this.onGetInputStream(file);
                }
            };
        } catch (final IOException e) {
            throw new TexturePackParseException(e);
        }
    } else {
        throw new TexturePackParseException(new IllegalArgumentException("Unsupported pTextureFormat: '" + type + "'."));
    }
    this.mTextureManager.addMappedTexture(file, texture);
    return texture;
}
Also used : PVRGZTexture(org.andengine.opengl.texture.compressed.pvr.PVRGZTexture) InputStream(java.io.InputStream) PVRTexture(org.andengine.opengl.texture.compressed.pvr.PVRTexture) SmartPVRTexturePixelBufferStrategy(org.andengine.opengl.texture.compressed.pvr.pixelbufferstrategy.SmartPVRTexturePixelBufferStrategy) IOException(java.io.IOException) TexturePackParseException(org.andengine.util.texturepack.exception.TexturePackParseException) PVRCCZTexture(org.andengine.opengl.texture.compressed.pvr.PVRCCZTexture) IInputStreamOpener(org.andengine.util.adt.io.in.IInputStreamOpener) PixelFormat(org.andengine.opengl.texture.PixelFormat) TextureOptions(org.andengine.opengl.texture.TextureOptions) ITexture(org.andengine.opengl.texture.ITexture) BitmapTexture(org.andengine.opengl.texture.bitmap.BitmapTexture)

Example 2 with ITexture

use of org.andengine.opengl.texture.ITexture in project AndEngine by nicolasgramlich.

the class TextureRegion method updateUV.

// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
// ===========================================================
// Methods
// ===========================================================
public void updateUV() {
    final ITexture texture = this.mTexture;
    final float textureWidth = texture.getWidth();
    final float textureHeight = texture.getHeight();
    final float x = this.getTextureX();
    final float y = this.getTextureY();
    this.mU = x / textureWidth;
    this.mU2 = (x + this.mTextureWidth) / textureWidth;
    this.mV = y / textureHeight;
    this.mV2 = (y + this.mTextureHeight) / textureHeight;
// this.mU = (x + 0.5f) / textureWidth;
// this.mU2 = (x + this.mTextureWidth - 0.5f) / textureWidth;
// 
// this.mV = (y + 0.5f) / textureHeight;
// this.mV2 = (y + this.mTextureHeight - 0.5f) / textureHeight;
}
Also used : ITexture(org.andengine.opengl.texture.ITexture)

Example 3 with ITexture

use of org.andengine.opengl.texture.ITexture in project AndEngine by nicolasgramlich.

the class BitmapFont method parseCharacters.

private void parseCharacters(final int pCharacterCount, final BufferedReader pBufferedReader) throws IOException {
    for (int i = pCharacterCount - 1; i >= 0; i--) {
        final String character = pBufferedReader.readLine();
        final String[] charAttributes = TextUtils.SPLITPATTERN_SPACES.split(character, BitmapFont.TAG_CHAR_ATTRIBUTECOUNT + 1);
        if ((charAttributes.length - 1) != BitmapFont.TAG_CHAR_ATTRIBUTECOUNT) {
            throw new FontException("Expected: '" + BitmapFont.TAG_CHAR_ATTRIBUTECOUNT + "' " + BitmapFont.TAG_CHAR + " attributes, found: '" + (charAttributes.length - 1) + "'.");
        }
        if (!charAttributes[0].equals(BitmapFont.TAG_CHAR)) {
            throw new FontException("Expected: '" + BitmapFont.TAG_CHAR + "' attributes.");
        }
        final char id = BitmapFont.getCharAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_ID_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_ID);
        final int x = this.mBitmapFontOptions.mTextureOffsetX + BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_X_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_X);
        final int y = this.mBitmapFontOptions.mTextureOffsetY + BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_Y_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_Y);
        final int width = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_WIDTH_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_WIDTH);
        final int height = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_HEIGHT_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_HEIGHT);
        final int xOffset = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_XOFFSET_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_XOFFSET);
        final int yOffset = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_YOFFSET_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_YOFFSET);
        final int xAdvance = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_XADVANCE_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_XADVANCE);
        final int page = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_PAGE_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_PAGE);
        // final int channel = BitmapFont.getIntAttribute(charAttributes, BitmapFont.TAG_CHAR_ATTRIBUTE_CHANNEL_INDEX, BitmapFont.TAG_CHAR_ATTRIBUTE_CHANNEL);
        final ITexture bitmapFontPageTexture = this.mBitmapFontPages[page].getTexture();
        final float textureWidth = bitmapFontPageTexture.getWidth();
        final float textureHeight = bitmapFontPageTexture.getHeight();
        final float u = x / textureWidth;
        final float v = y / textureHeight;
        final float u2 = (x + width) / textureWidth;
        final float v2 = (y + height) / textureHeight;
        this.mCharacterToLetterMap.put(id, new Letter(id, x, y, width, height, xOffset, yOffset, xAdvance, u, v, u2, v2));
    }
}
Also used : FontException(org.andengine.opengl.font.exception.FontException) ITexture(org.andengine.opengl.texture.ITexture)

Aggregations

ITexture (org.andengine.opengl.texture.ITexture)3 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 FontException (org.andengine.opengl.font.exception.FontException)1 PixelFormat (org.andengine.opengl.texture.PixelFormat)1 TextureOptions (org.andengine.opengl.texture.TextureOptions)1 BitmapTexture (org.andengine.opengl.texture.bitmap.BitmapTexture)1 PVRCCZTexture (org.andengine.opengl.texture.compressed.pvr.PVRCCZTexture)1 PVRGZTexture (org.andengine.opengl.texture.compressed.pvr.PVRGZTexture)1 PVRTexture (org.andengine.opengl.texture.compressed.pvr.PVRTexture)1 SmartPVRTexturePixelBufferStrategy (org.andengine.opengl.texture.compressed.pvr.pixelbufferstrategy.SmartPVRTexturePixelBufferStrategy)1 IInputStreamOpener (org.andengine.util.adt.io.in.IInputStreamOpener)1 TexturePackParseException (org.andengine.util.texturepack.exception.TexturePackParseException)1