Search in sources :

Example 21 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class VertexGLAttributeTest method testColorPackedBinding.

@Test
public void testColorPackedBinding() {
    VertexResourceBuilder builder = new VertexResourceBuilder();
    VertexAttributeBinding<Colorc, Color> a1 = builder.add(0, GLAttributes.COLOR_4_PACKED_VERTEX_ATTRIBUTE);
    VertexResource resource = builder.build();
    a1.put(Color.white);
    a1.put(Color.red);
    a1.put(Color.green);
    a1.put(Color.blue);
    assertEquals(4, a1.getPosition());
    int stride = Byte.BYTES * 4;
    resource.writeBuffer(buffer -> {
        assertEquals(4 * 4 * Byte.BYTES, buffer.limit());
        assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 0)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 1)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 2)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get(Byte.BYTES * 3)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 0)));
        assertEquals(0, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 1)));
        assertEquals(0, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 2)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get(stride + Byte.BYTES * 3)));
        assertEquals(0, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 0)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 1)));
        assertEquals(0, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 2)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get((2 * stride) + Byte.BYTES * 3)));
        assertEquals(0, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 0)));
        assertEquals(0, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 1)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 2)));
        assertEquals(255, Byte.toUnsignedInt(buffer.get((3 * stride) + Byte.BYTES * 3)));
    });
}
Also used : VertexResource(org.terasology.engine.rendering.assets.mesh.resource.VertexResource) VertexResourceBuilder(org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder) Colorc(org.terasology.nui.Colorc) Color(org.terasology.nui.Color) Test(org.junit.Test)

Example 22 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class TextureDataFactoryTest method testColorTransformedToTextureUri.

@Test
public void testColorTransformedToTextureUri() throws Exception {
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    Color expectedColor = new Color(red, green, blue, alpha);
    int expectedRed = 18;
    int expectedGreen = 3;
    int expectedBlue = -60;
    int expectedAlpha = 14;
    testRepeatedColorInDataTexture(expectedColor, expectedRed, expectedGreen, expectedBlue, expectedAlpha);
}
Also used : Color(org.terasology.nui.Color) Test(org.junit.jupiter.api.Test)

Example 23 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class TextureDataFactoryTest method testRedColorNoAlphaTransformedToTextureUri.

@Test
public void testRedColorNoAlphaTransformedToTextureUri() throws Exception {
    Color expectedColor = Color.RED;
    int expectedRed = -1;
    int expectedGreen = 0;
    int expectedBlue = 0;
    int expectedAlpha = -1;
    testRepeatedColorInDataTexture(expectedColor, expectedRed, expectedGreen, expectedBlue, expectedAlpha);
}
Also used : Color(org.terasology.nui.Color) Test(org.junit.jupiter.api.Test)

Example 24 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class TextureUtilTest method testColorTransformedToAssetUriTransformedToColor.

@Test
public void testColorTransformedToAssetUriTransformedToColor() throws Exception {
    Color expectedColor = Color.RED;
    ResourceUrn assetUri = TextureUtil.getTextureUriForColor(expectedColor);
    Color actualColor = TextureUtil.getColorForColorName(assetUri.getFragmentName().toLowerCase());
    assertEquals(expectedColor, actualColor);
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    expectedColor = new Color(red, green, blue, alpha);
    assetUri = TextureUtil.getTextureUriForColor(expectedColor);
    actualColor = TextureUtil.getColorForColorName(assetUri.getFragmentName().toLowerCase());
    assertEquals(expectedColor, actualColor);
}
Also used : Color(org.terasology.nui.Color) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Test(org.junit.jupiter.api.Test)

Example 25 with Color

use of org.terasology.nui.Color in project Terasology by MovingBlocks.

the class TextureUtilTest method testColorTransformedToTextureUri.

@Test
public void testColorTransformedToTextureUri() throws Exception {
    ResourceUrn assetUri = TextureUtil.getTextureUriForColor(Color.RED);
    assertEquals(TerasologyConstants.ENGINE_MODULE, assetUri.getModuleName());
    assertEquals(new Name("color"), assetUri.getResourceName());
    assertEquals(new Name("ff0000ff"), assetUri.getFragmentName());
    int red = 0x12;
    int green = 0x3;
    int blue = 0xc4;
    int alpha = 0xe;
    assetUri = TextureUtil.getTextureUriForColor(new Color(red, green, blue, alpha));
    assertEquals(TerasologyConstants.ENGINE_MODULE, assetUri.getModuleName());
    assertEquals(new Name("color"), assetUri.getResourceName());
    assertEquals(new Name("1203c40e"), assetUri.getFragmentName());
}
Also used : Color(org.terasology.nui.Color) ResourceUrn(org.terasology.gestalt.assets.ResourceUrn) Name(org.terasology.gestalt.naming.Name) Test(org.junit.jupiter.api.Test)

Aggregations

Color (org.terasology.nui.Color)39 Test (org.junit.jupiter.api.Test)9 Vector3f (org.joml.Vector3f)5 ByteBuffer (java.nio.ByteBuffer)3 Mesh (org.terasology.engine.rendering.assets.mesh.Mesh)3 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)3 Colorc (org.terasology.nui.Colorc)3 ColorModel (java.awt.image.ColorModel)2 DataBufferInt (java.awt.image.DataBufferInt)2 Vector2f (org.joml.Vector2f)2 Vector3fc (org.joml.Vector3fc)2 Vector4f (org.joml.Vector4f)2 Test (org.junit.Test)2 ColorConstraint (org.terasology.engine.config.flexible.constraints.ColorConstraint)2 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)2 StandardMeshData (org.terasology.engine.rendering.assets.mesh.StandardMeshData)2 VertexResource (org.terasology.engine.rendering.assets.mesh.resource.VertexResource)2 VertexResourceBuilder (org.terasology.engine.rendering.assets.mesh.resource.VertexResourceBuilder)2 ParagraphRenderStyle (org.terasology.engine.rendering.nui.widgets.browser.ui.style.ParagraphRenderStyle)2 FastRandom (org.terasology.engine.utilities.random.FastRandom)2