Search in sources :

Example 1 with ColorBlender

use of org.terasology.world.viewer.color.ColorBlender in project Terasology by MovingBlocks.

the class FieldFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    FieldFacet2D facet = region.getFacet(clazz);
    int width = img.getWidth();
    int height = img.getHeight();
    ColorModel colorModel = img.getColorModel();
    ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
    DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
    for (int z = 0; z < height; z++) {
        for (int x = 0; x < width; x++) {
            Color col = getColor(facet, x, z);
            int src = col.rgba();
            int dst = dataBuffer.getElem(z * width + x);
            int mix = blender.add(src, dst);
            dataBuffer.setElem(z * width + x, mix);
        }
    }
}
Also used : FieldFacet2D(org.terasology.world.generation.facets.base.FieldFacet2D) ColorBlender(org.terasology.world.viewer.color.ColorBlender) ColorModel(java.awt.image.ColorModel) Color(org.terasology.rendering.nui.Color) DataBufferInt(java.awt.image.DataBufferInt)

Example 2 with ColorBlender

use of org.terasology.world.viewer.color.ColorBlender in project Terasology by MovingBlocks.

the class NominalFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    ObjectFacet2D<E> facet = region.getFacet(facetClass);
    int width = img.getWidth();
    int height = img.getHeight();
    ColorModel colorModel = img.getColorModel();
    ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
    DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
    for (int z = 0; z < height; z++) {
        for (int x = 0; x < width; x++) {
            Color src = getColor(facet, x, z);
            if (src != null) {
                int blend = blender.get(src.rgba());
                dataBuffer.setElem(z * width + x, blend);
            }
        }
    }
}
Also used : ColorBlender(org.terasology.world.viewer.color.ColorBlender) ColorModel(java.awt.image.ColorModel) Color(org.terasology.rendering.nui.Color) DataBufferInt(java.awt.image.DataBufferInt)

Example 3 with ColorBlender

use of org.terasology.world.viewer.color.ColorBlender in project Terasology by MovingBlocks.

the class FloraFacetLayer method render.

@Override
public void render(BufferedImage img, Region region) {
    FloraFacet treeFacet = region.getFacet(FloraFacet.class);
    Graphics2D g = img.createGraphics();
    int width = img.getWidth();
    ColorModel colorModel = img.getColorModel();
    ColorBlender blender = ColorBlenders.forColorModel(ColorModels.RGBA, colorModel);
    DataBufferInt dataBuffer = (DataBufferInt) img.getRaster().getDataBuffer();
    for (Entry<BaseVector3i, FloraType> entry : treeFacet.getRelativeEntries().entrySet()) {
        FloraType treeGen = entry.getValue();
        int wx = entry.getKey().getX();
        int wz = entry.getKey().getZ();
        Color color = colorFunc.apply(treeGen);
        int src = color.rgba();
        int dst = dataBuffer.getElem(wz * width + wx);
        int mix = blender.blend(src, dst);
        dataBuffer.setElem(wz * width + wx, mix);
    }
    g.dispose();
}
Also used : FloraType(org.terasology.core.world.generator.rasterizers.FloraType) ColorBlender(org.terasology.world.viewer.color.ColorBlender) FloraFacet(org.terasology.core.world.generator.facets.FloraFacet) ColorModel(java.awt.image.ColorModel) Color(org.terasology.rendering.nui.Color) BaseVector3i(org.terasology.math.geom.BaseVector3i) DataBufferInt(java.awt.image.DataBufferInt) Graphics2D(java.awt.Graphics2D)

Aggregations

ColorModel (java.awt.image.ColorModel)3 DataBufferInt (java.awt.image.DataBufferInt)3 Color (org.terasology.rendering.nui.Color)3 ColorBlender (org.terasology.world.viewer.color.ColorBlender)3 Graphics2D (java.awt.Graphics2D)1 FloraFacet (org.terasology.core.world.generator.facets.FloraFacet)1 FloraType (org.terasology.core.world.generator.rasterizers.FloraType)1 BaseVector3i (org.terasology.math.geom.BaseVector3i)1 FieldFacet2D (org.terasology.world.generation.facets.base.FieldFacet2D)1