Example usage for com.badlogic.gdx.graphics.g2d TextureRegion getTexture

List of usage examples for com.badlogic.gdx.graphics.g2d TextureRegion getTexture

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g2d TextureRegion getTexture.

Prototype

public Texture getTexture() 

Source Link

Usage

From source file:br.com.animvs.koalory.entities.engine.graphics.tiles.TileRenderer.java

License:Apache License

@Override
public void renderTileLayer(TiledMapTileLayer layer) {
    final float color = Color.toFloatBits(1, 1, 1, layer.getOpacity());

    final int layerWidth = layer.getWidth();
    final int layerHeight = layer.getHeight();

    final float layerTileWidth = layer.getTileWidth() * unitScale;
    final float layerTileHeight = layer.getTileHeight() * unitScale;

    final int col1 = Math.max(0, (int) (cacheBounds.x / layerTileWidth));
    final int col2 = Math.min(layerWidth,
            (int) ((cacheBounds.x + cacheBounds.width + layerTileWidth) / layerTileWidth));

    final int row1 = Math.max(0, (int) (cacheBounds.y / layerTileHeight));
    final int row2 = Math.min(layerHeight,
            (int) ((cacheBounds.y + cacheBounds.height + layerTileHeight) / layerTileHeight));

    canCacheMoreN = row2 < layerHeight;
    canCacheMoreE = col2 < layerWidth;
    canCacheMoreW = col1 > 0;//from  w w  w  .  j  av  a2s.  com
    canCacheMoreS = row1 > 0;

    float[] vertices = this.vertices;
    for (int row = row2; row >= row1; row--) {
        for (int col = col1; col < col2; col++) {
            final TiledMapTileLayer.Cell cell = layer.getCell(col, row);
            if (cell == null)
                continue;

            final TiledMapTile tile = cell.getTile();
            if (tile == null)
                continue;

            count++;
            final boolean flipX = cell.getFlipHorizontally();
            final boolean flipY = cell.getFlipVertically();
            final int rotations = cell.getRotation();

            final TextureRegion region = tile.getTextureRegion();
            final Texture texture = region.getTexture();

            final float x1 = col * layerTileWidth + tile.getOffsetX() * unitScale;
            final float y1 = row * layerTileHeight + tile.getOffsetY() * unitScale;
            final float x2 = x1 + region.getRegionWidth() * unitScale;
            final float y2 = y1 + region.getRegionHeight() * unitScale;

            final float adjustX = 0.5f / texture.getWidth();
            final float adjustY = 0.5f / texture.getHeight();
            final float u1 = region.getU() + adjustX;
            final float v1 = region.getV2() - adjustY;
            final float u2 = region.getU2() - adjustX;
            final float v2 = region.getV() + adjustY;

            vertices[X1] = x1;
            vertices[Y1] = y1;
            vertices[C1] = color;
            vertices[U1] = u1;
            vertices[V1] = v1;

            vertices[X2] = x1;
            vertices[Y2] = y2;
            vertices[C2] = color;
            vertices[U2] = u1;
            vertices[V2] = v2;

            vertices[X3] = x2;
            vertices[Y3] = y2;
            vertices[C3] = color;
            vertices[U3] = u2;
            vertices[V3] = v2;

            vertices[X4] = x2;
            vertices[Y4] = y1;
            vertices[C4] = color;
            vertices[U4] = u2;
            vertices[V4] = v1;

            if (flipX) {
                float temp = vertices[U1];
                vertices[U1] = vertices[U3];
                vertices[U3] = temp;
                temp = vertices[U2];
                vertices[U2] = vertices[U4];
                vertices[U4] = temp;
            }
            if (flipY) {
                float temp = vertices[V1];
                vertices[V1] = vertices[V3];
                vertices[V3] = temp;
                temp = vertices[V2];
                vertices[V2] = vertices[V4];
                vertices[V4] = temp;
            }
            if (rotations != 0) {
                switch (rotations) {
                case Cell.ROTATE_90: {
                    float tempV = vertices[V1];
                    vertices[V1] = vertices[V2];
                    vertices[V2] = vertices[V3];
                    vertices[V3] = vertices[V4];
                    vertices[V4] = tempV;

                    float tempU = vertices[U1];
                    vertices[U1] = vertices[U2];
                    vertices[U2] = vertices[U3];
                    vertices[U3] = vertices[U4];
                    vertices[U4] = tempU;
                    break;
                }
                case Cell.ROTATE_180: {
                    float tempU = vertices[U1];
                    vertices[U1] = vertices[U3];
                    vertices[U3] = tempU;
                    tempU = vertices[U2];
                    vertices[U2] = vertices[U4];
                    vertices[U4] = tempU;
                    float tempV = vertices[V1];
                    vertices[V1] = vertices[V3];
                    vertices[V3] = tempV;
                    tempV = vertices[V2];
                    vertices[V2] = vertices[V4];
                    vertices[V4] = tempV;
                    break;
                }
                case Cell.ROTATE_270: {
                    float tempV = vertices[V1];
                    vertices[V1] = vertices[V4];
                    vertices[V4] = vertices[V3];
                    vertices[V3] = vertices[V2];
                    vertices[V2] = tempV;

                    float tempU = vertices[U1];
                    vertices[U1] = vertices[U4];
                    vertices[U4] = vertices[U3];
                    vertices[U3] = vertices[U2];
                    vertices[U2] = tempU;
                    break;
                }
                }
            }
            spriteCache.add(texture, vertices, 0, 20);
        }
    }
}

From source file:CB_UI_Base.GL_UI.Fonts.java

License:Open Source License

private static BitmapFont loadFontFromFile(FreeTypeFontGenerator generator, int scale) {
    String fs = Global.fs;//from  w ww  .j a va 2s  . co  m
    String fontPath = "";
    // fonts-Verzeichnis "lokal" im cachebox/skins/small oder ..normal oder christmas

    if (cfg.SkinFolder.type() == FileType.Absolute) {
        String FolderPath = cfg.SkinFolder.path();
        String path = FolderPath.replace("/", fs) + fs + "fnts";
        if (FileIO.DirectoryExists(path)) {
            // fonts-Verzeichnis "lokal" im cachebox/skins/small oder ..normal oder christmas
            fontPath = path + fs + String.valueOf(scale) + ".fnt";
        } else {
            // fonts-Verzeichnis "global" im cachebox/skins
            path = FolderPath.replace("/", fs) + fs + ".." + fs + "fnts";
            fontPath = path + fs + String.valueOf(scale) + ".fnt";
        }

    }

    // Wenn der font nicht vorberechnet ist, dann wird er generiert
    if (FileIO.FileExists(fontPath)) {
        Log.debug(log, "load font for scale " + scale + " from " + fontPath);
        // automatic load of png does not work on Android, so
        // return new BitmapFont(Gdx.files.absolute(fontPath),false);
        Texture tex = new Texture(Gdx.files.absolute(fontPath.replace(".fnt", ".png")));
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        TextureRegion region = new TextureRegion(tex);
        BitmapFont ret = new BitmapFont(Gdx.files.absolute(fontPath), region, false);
        return ret;
    } else {
        Log.debug(log, "generate font for scale " + scale);
        FreeTypeFontParameter parameter = new FreeTypeFontParameter();
        parameter.size = scale;
        parameter.characters = DEFAULT_CHARACTER;
        BitmapFont ret = generator.generateFont(parameter);
        TextureRegion region = ret.getRegion();
        Texture tex = region.getTexture();
        tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
        return ret;
    }
}

From source file:CB_UI_Base.graphics.GL_Fonts.java

License:Open Source License

private BitmapFont generateFont(FileHandle file, int textSize) {
    FreeTypeFontGenerator generator = new FreeTypeFontGenerator(file);

    FreeTypeFontParameter parameter = new FreeTypeFontParameter();
    parameter.size = textSize;//from   w  ww.  jav a 2s .c o m
    parameter.characters = Fonts.DEFAULT_CHARACTER;
    BitmapFont ret = generator.generateFont(parameter);

    TextureRegion region = ret.getRegion();
    Texture tex = region.getTexture();
    tex.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    generator.dispose();

    return ret;
}

From source file:com.agateau.pixelwheels.racer.SkidmarksRenderer.java

License:Open Source License

private void drawSkidmark(Batch batch, Vector2 pos1, Vector2 pos2, float alpha1, float alpha2) {
    TextureRegion region = mAssets.skidmark;
    float c = Color.toFloatBits(1, 1, 1, alpha1);
    float c2 = Color.toFloatBits(1, 1, 1, alpha2);
    float u = region.getU();
    float v = region.getV();
    float u2 = region.getU2();
    float v2 = region.getV2();

    /*//  w  w w .  j  a v a  2  s  . c o  m
    0            3
     x----------x        ^
     |          |        |
    pos1 x          x pos2   | thickness
     |          |
     x----------x
    1            2
     */
    float x0 = pos1.x + mThickX1;
    float y0 = pos1.y + mThickY1;

    float x1 = pos1.x - mThickX1;
    float y1 = pos1.y - mThickY1;

    float x2 = pos2.x - mThickX2;
    float y2 = pos2.y - mThickY2;

    float x3 = pos2.x + mThickX2;
    float y3 = pos2.y + mThickY2;

    initVertex(0, x0, y0, c, u, v);
    initVertex(1, x1, y1, c, u2, v);
    initVertex(2, x2, y2, c2, u2, v2);
    initVertex(3, x3, y3, c2, u, v2);

    batch.draw(region.getTexture(), mVertices, 0, mVertices.length);
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified region to the cache. */
public void add(TextureRegion region, float x, float y, float width, float height) {
    final float fx2 = x + width;
    final float fy2 = y + height;
    final float u = region.getU();
    final float v = region.getV2();
    final float u2 = region.getU2();
    final float v2 = region.getV();

    tempVertices[0] = x;//  www . j  av a2s  .  c  o m
    tempVertices[1] = y;
    tempVertices[2] = color;
    tempVertices[3] = u;
    tempVertices[4] = v;

    tempVertices[5] = x;
    tempVertices[6] = fy2;
    tempVertices[7] = color;
    tempVertices[8] = u;
    tempVertices[9] = v2;

    tempVertices[10] = fx2;
    tempVertices[11] = fy2;
    tempVertices[12] = color;
    tempVertices[13] = u2;
    tempVertices[14] = v2;

    if (mesh.getNumIndices() > 0) {
        tempVertices[15] = fx2;
        tempVertices[16] = y;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v;
        add(region.getTexture(), tempVertices, 0, 20);
    } else {
        tempVertices[15] = fx2;
        tempVertices[16] = fy2;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v2;

        tempVertices[20] = fx2;
        tempVertices[21] = y;
        tempVertices[22] = color;
        tempVertices[23] = u2;
        tempVertices[24] = v;

        tempVertices[25] = x;
        tempVertices[26] = y;
        tempVertices[27] = color;
        tempVertices[28] = u;
        tempVertices[29] = v;
        add(region.getTexture(), tempVertices, 0, 30);
    }
}

From source file:com.anythingmachine.gdxwrapper.SpriteCache.java

License:Apache License

/** Adds the specified region to the cache. */
public void add(TextureRegion region, float x, float y, float originX, float originY, float width, float height,
        float scaleX, float scaleY, float rotation) {

    // bottom left and top right corner points relative to origin
    final float worldOriginX = x + originX;
    final float worldOriginY = y + originY;
    float fx = -originX;
    float fy = -originY;
    float fx2 = width - originX;
    float fy2 = height - originY;

    // scale/* w w w  . j a  v  a2s.co m*/
    if (scaleX != 1 || scaleY != 1) {
        fx *= scaleX;
        fy *= scaleY;
        fx2 *= scaleX;
        fy2 *= scaleY;
    }

    // construct corner points, start from top left and go counter clockwise
    final float p1x = fx;
    final float p1y = fy;
    final float p2x = fx;
    final float p2y = fy2;
    final float p3x = fx2;
    final float p3y = fy2;
    final float p4x = fx2;
    final float p4y = fy;

    float x1;
    float y1;
    float x2;
    float y2;
    float x3;
    float y3;
    float x4;
    float y4;

    // rotate
    if (rotation != 0) {
        final float cos = MathUtils.cosDeg(rotation);
        final float sin = MathUtils.sinDeg(rotation);

        x1 = cos * p1x - sin * p1y;
        y1 = sin * p1x + cos * p1y;

        x2 = cos * p2x - sin * p2y;
        y2 = sin * p2x + cos * p2y;

        x3 = cos * p3x - sin * p3y;
        y3 = sin * p3x + cos * p3y;

        x4 = x1 + (x3 - x2);
        y4 = y3 - (y2 - y1);
    } else {
        x1 = p1x;
        y1 = p1y;

        x2 = p2x;
        y2 = p2y;

        x3 = p3x;
        y3 = p3y;

        x4 = p4x;
        y4 = p4y;
    }

    x1 += worldOriginX;
    y1 += worldOriginY;
    x2 += worldOriginX;
    y2 += worldOriginY;
    x3 += worldOriginX;
    y3 += worldOriginY;
    x4 += worldOriginX;
    y4 += worldOriginY;

    final float u = region.getU();
    final float v = region.getV2();
    final float u2 = region.getU2();
    final float v2 = region.getV();

    tempVertices[0] = x1;
    tempVertices[1] = y1;
    tempVertices[2] = color;
    tempVertices[3] = u;
    tempVertices[4] = v;

    tempVertices[5] = x2;
    tempVertices[6] = y2;
    tempVertices[7] = color;
    tempVertices[8] = u;
    tempVertices[9] = v2;

    tempVertices[10] = x3;
    tempVertices[11] = y3;
    tempVertices[12] = color;
    tempVertices[13] = u2;
    tempVertices[14] = v2;

    if (mesh.getNumIndices() > 0) {
        tempVertices[15] = x4;
        tempVertices[16] = y4;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v;
        add(region.getTexture(), tempVertices, 0, 20);
    } else {
        tempVertices[15] = x3;
        tempVertices[16] = y3;
        tempVertices[17] = color;
        tempVertices[18] = u2;
        tempVertices[19] = v2;

        tempVertices[20] = x4;
        tempVertices[21] = y4;
        tempVertices[22] = color;
        tempVertices[23] = u2;
        tempVertices[24] = v;

        tempVertices[25] = x1;
        tempVertices[26] = y1;
        tempVertices[27] = color;
        tempVertices[28] = u;
        tempVertices[29] = v;
        add(region.getTexture(), tempVertices, 0, 30);
    }
}

From source file:com.badlydrawngames.veryangryrobots.WorldView.java

License:Apache License

private void drawClipped(GameObject go, TextureRegion region) {
    float boundsMinX = worldMinX + World.OUTER_WALL_ADJUST + World.WALL_HEIGHT;
    float boundsMaxX = worldMaxX - World.OUTER_WALL_ADJUST - World.WALL_HEIGHT;
    float boundsMinY = worldMinY + World.OUTER_WALL_ADJUST + World.WALL_HEIGHT;
    float boundsMaxY = worldMaxY - World.OUTER_WALL_ADJUST - World.WALL_HEIGHT;

    // Don't draw if it's completely out of bounds.
    float maxX = go.x + go.width;
    if (maxX < boundsMinX)
        return;/*from ww  w  .j  a  va  2s . c o m*/
    float minX = go.x;
    if (minX > boundsMaxX)
        return;
    float maxY = go.y + go.height;
    if (maxY < boundsMinY)
        return;
    float minY = go.y;
    if (minY > boundsMaxY)
        return;

    // Clip to the visible bounds.
    float x = go.x;
    float y = go.y;
    int srcX = region.getRegionX();
    int srcY = region.getRegionY();
    int srcWidth = region.getRegionWidth();
    int srcHeight = region.getRegionHeight();
    if (minX < boundsMinX) {
        float n = (boundsMinX - minX);
        x += n;
        n *= (srcWidth / go.width);
        srcX += n;
        srcWidth -= n;
    } else if (maxX > boundsMaxX) {
        float n = (maxX - boundsMaxX);
        srcWidth -= n * (srcWidth / go.width);
    }
    if (minY < boundsMinY) {
        float n = (boundsMinY - minY);
        y += n;
        srcHeight -= n * (srcHeight / go.height);
    } else if (maxY > boundsMaxY) {
        float n = (maxY - boundsMaxY) * (srcHeight / go.height);
        srcHeight -= n;
        srcY += n;
    }
    float width = go.width * srcWidth / region.getRegionWidth();
    float height = go.height * srcHeight / region.getRegionHeight();

    spriteBatch.draw(region.getTexture(), x, y, width, height, srcX, srcY, srcWidth, srcHeight, false, false);
}

From source file:com.balloongame.handlers.CustomSpriteBatch.java

License:Apache License

/** Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. */
public void draw(TextureRegion region, float x, float y, float width, float height) {
    if (!drawing)
        throw new IllegalStateException("SpriteBatch.begin must be called before draw.");

    Texture texture = region.getTexture();
    if (texture != lastTexture) {
        switchTexture(texture);//from  www .ja v  a  2s . c  om
    } else if (idx == vertices.length) //
        renderMesh();

    final float fx2 = x + width;
    final float fy2 = y + height;
    final float u = region.getU();
    final float v = region.getV2();
    final float u2 = region.getU2();
    final float v2 = region.getV();

    vertices[idx++] = x;
    vertices[idx++] = y;
    vertices[idx++] = color;
    vertices[idx++] = u;
    vertices[idx++] = v;

    vertices[idx++] = x;
    vertices[idx++] = fy2;
    vertices[idx++] = color;
    vertices[idx++] = u;
    vertices[idx++] = v2;

    vertices[idx++] = fx2;
    vertices[idx++] = fy2;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v2;

    vertices[idx++] = fx2;
    vertices[idx++] = y;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v;
}

From source file:com.balloongame.handlers.CustomSpriteBatch.java

License:Apache License

/** Draws a rectangle with the bottom left corner at x,y and stretching the region to cover the given width and height. The
 * rectangle is offset by originX, originY relative to the origin. Scale specifies the scaling factor by which the rectangle
 * should be scaled around originX, originY. Rotation specifies the angle of counter clockwise rotation of the rectangle around
 * originX, originY. *///ww  w. j  a  va 2s .c om
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width,
        float height, float scaleX, float scaleY, float rotation) {
    if (!drawing)
        throw new IllegalStateException("SpriteBatch.begin must be called before draw.");

    Texture texture = region.getTexture();
    if (texture != lastTexture) {
        switchTexture(texture);
    } else if (idx == vertices.length) //
        renderMesh();

    // bottom left and top right corner points relative to origin
    final float worldOriginX = x + originX;
    final float worldOriginY = y + originY;
    float fx = -originX;
    float fy = -originY;
    float fx2 = width - originX;
    float fy2 = height - originY;

    // scale
    if (scaleX != 1 || scaleY != 1) {
        fx *= scaleX;
        fy *= scaleY;
        fx2 *= scaleX;
        fy2 *= scaleY;
    }

    // construct corner points, start from top left and go counter clockwise
    final float p1x = fx;
    final float p1y = fy;
    final float p2x = fx;
    final float p2y = fy2;
    final float p3x = fx2;
    final float p3y = fy2;
    final float p4x = fx2;
    final float p4y = fy;

    float x1;
    float y1;
    float x2;
    float y2;
    float x3;
    float y3;
    float x4;
    float y4;

    // rotate
    if (rotation != 0) {
        final float cos = MathUtils.cosDeg(rotation);
        final float sin = MathUtils.sinDeg(rotation);

        x1 = cos * p1x - sin * p1y;
        y1 = sin * p1x + cos * p1y;

        x2 = cos * p2x - sin * p2y;
        y2 = sin * p2x + cos * p2y;

        x3 = cos * p3x - sin * p3y;
        y3 = sin * p3x + cos * p3y;

        x4 = x1 + (x3 - x2);
        y4 = y3 - (y2 - y1);
    } else {
        x1 = p1x;
        y1 = p1y;

        x2 = p2x;
        y2 = p2y;

        x3 = p3x;
        y3 = p3y;

        x4 = p4x;
        y4 = p4y;
    }

    x1 += worldOriginX;
    y1 += worldOriginY;
    x2 += worldOriginX;
    y2 += worldOriginY;
    x3 += worldOriginX;
    y3 += worldOriginY;
    x4 += worldOriginX;
    y4 += worldOriginY;

    final float u = region.getU();
    final float v = region.getV2();
    final float u2 = region.getU2();
    final float v2 = region.getV();

    vertices[idx++] = x1;
    vertices[idx++] = y1;
    vertices[idx++] = color;
    vertices[idx++] = u;
    vertices[idx++] = v;

    vertices[idx++] = x2;
    vertices[idx++] = y2;
    vertices[idx++] = color;
    vertices[idx++] = u;
    vertices[idx++] = v2;

    vertices[idx++] = x3;
    vertices[idx++] = y3;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v2;

    vertices[idx++] = x4;
    vertices[idx++] = y4;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v;
}

From source file:com.balloongame.handlers.CustomSpriteBatch.java

License:Apache License

/** Draws a rectangle with the texture coordinates rotated 90 degrees. The bottom left corner at x,y and stretching the region
 * to cover the given width and height. The rectangle is offset by originX, originY relative to the origin. Scale specifies the
 * scaling factor by which the rectangle should be scaled around originX, originY. Rotation specifies the angle of counter
 * clockwise rotation of the rectangle around originX, originY.
 * @param clockwise If true, the texture coordinates are rotated 90 degrees clockwise. If false, they are rotated 90 degrees
 *           counter clockwise. */
public void draw(TextureRegion region, float x, float y, float originX, float originY, float width,
        float height, float scaleX, float scaleY, float rotation, boolean clockwise) {
    if (!drawing)
        throw new IllegalStateException("SpriteBatch.begin must be called before draw.");

    Texture texture = region.getTexture();
    if (texture != lastTexture) {
        switchTexture(texture);//from  w w  w. j av  a 2s.  c o  m
    } else if (idx == vertices.length) //
        renderMesh();

    // bottom left and top right corner points relative to origin
    final float worldOriginX = x + originX;
    final float worldOriginY = y + originY;
    float fx = -originX;
    float fy = -originY;
    float fx2 = width - originX;
    float fy2 = height - originY;

    // scale
    if (scaleX != 1 || scaleY != 1) {
        fx *= scaleX;
        fy *= scaleY;
        fx2 *= scaleX;
        fy2 *= scaleY;
    }

    // construct corner points, start from top left and go counter clockwise
    final float p1x = fx;
    final float p1y = fy;
    final float p2x = fx;
    final float p2y = fy2;
    final float p3x = fx2;
    final float p3y = fy2;
    final float p4x = fx2;
    final float p4y = fy;

    float x1;
    float y1;
    float x2;
    float y2;
    float x3;
    float y3;
    float x4;
    float y4;

    // rotate
    if (rotation != 0) {
        final float cos = MathUtils.cosDeg(rotation);
        final float sin = MathUtils.sinDeg(rotation);

        x1 = cos * p1x - sin * p1y;
        y1 = sin * p1x + cos * p1y;

        x2 = cos * p2x - sin * p2y;
        y2 = sin * p2x + cos * p2y;

        x3 = cos * p3x - sin * p3y;
        y3 = sin * p3x + cos * p3y;

        x4 = x1 + (x3 - x2);
        y4 = y3 - (y2 - y1);
    } else {
        x1 = p1x;
        y1 = p1y;

        x2 = p2x;
        y2 = p2y;

        x3 = p3x;
        y3 = p3y;

        x4 = p4x;
        y4 = p4y;
    }

    x1 += worldOriginX;
    y1 += worldOriginY;
    x2 += worldOriginX;
    y2 += worldOriginY;
    x3 += worldOriginX;
    y3 += worldOriginY;
    x4 += worldOriginX;
    y4 += worldOriginY;

    float u1, v1, u2, v2, u3, v3, u4, v4;
    if (clockwise) {
        u1 = region.getU2();
        v1 = region.getV2();
        u2 = region.getU();
        v2 = region.getV2();
        u3 = region.getU();
        v3 = region.getV();
        u4 = region.getU2();
        v4 = region.getV();
    } else {
        u1 = region.getU();
        v1 = region.getV();
        u2 = region.getU2();
        v2 = region.getV();
        u3 = region.getU2();
        v3 = region.getV2();
        u4 = region.getU();
        v4 = region.getV2();
    }

    vertices[idx++] = x1;
    vertices[idx++] = y1;
    vertices[idx++] = color;
    vertices[idx++] = u1;
    vertices[idx++] = v1;

    vertices[idx++] = x2;
    vertices[idx++] = y2;
    vertices[idx++] = color;
    vertices[idx++] = u2;
    vertices[idx++] = v2;

    vertices[idx++] = x3;
    vertices[idx++] = y3;
    vertices[idx++] = color;
    vertices[idx++] = u3;
    vertices[idx++] = v3;

    vertices[idx++] = x4;
    vertices[idx++] = y4;
    vertices[idx++] = color;
    vertices[idx++] = u4;
    vertices[idx++] = v4;
}