Search in sources :

Example 1 with Texture

use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class PreviewWorldScreen method genTexture.

private void genTexture() {
    int imgWidth = 384;
    int imgHeight = 384;
    ByteBuffer buffer = ByteBuffer.allocateDirect(imgWidth * imgHeight * Integer.BYTES);
    ByteBuffer[] data = new ByteBuffer[] { buffer };
    ResourceUrn uri = new ResourceUrn("engine:terrainPreview");
    TextureData texData = new TextureData(imgWidth, imgHeight, data, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
    texture = Assets.generateAsset(uri, texData, Texture.class);
    previewImage = find("preview", UIImage.class);
    previewImage.setImage(texture);
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) ResourceUrn(org.terasology.assets.ResourceUrn) UIImage(org.terasology.rendering.nui.widgets.UIImage) ByteBuffer(java.nio.ByteBuffer) Texture(org.terasology.rendering.assets.texture.Texture)

Example 2 with Texture

use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class PlayerSettingsScreen method initialise.

@Override
public void initialise() {
    setAnimationSystem(MenuAnimationSystems.createDefaultSwipeAnimation());
    storageServiceStatus = find("storageServiceStatus", UILabel.class);
    storageServiceAction = find("storageServiceAction", UIButton.class);
    updateStorageServiceStatus();
    nametext = find("playername", UIText.class);
    if (nametext != null) {
        nametext.setTooltipDelay(0);
        nametext.bindTooltipString(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return validateScreen();
            }
        });
    }
    img = find("image", UIImage.class);
    if (img != null) {
        ResourceUrn uri = TextureUtil.getTextureUriForColor(Color.WHITE);
        Texture tex = Assets.get(uri, Texture.class).get();
        img.setImage(tex);
    }
    slider = find("tone", UISlider.class);
    if (slider != null) {
        slider.setIncrement(0.01f);
        // ensure a certain width
        Function<Object, String> constant = Functions.constant("  ");
        slider.setLabelFunction(constant);
    }
    heightSlider = find("height", UISlider.class);
    if (heightSlider != null) {
        heightSlider.setMinimum(1.5f);
        heightSlider.setIncrement(0.1f);
        heightSlider.setRange(0.5f);
        heightSlider.setPrecision(1);
    }
    eyeHeightSlider = find("eye-height", UISlider.class);
    if (eyeHeightSlider != null) {
        eyeHeightSlider.setMinimum(0.5f);
        eyeHeightSlider.setIncrement(0.1f);
        eyeHeightSlider.setRange(1f);
        eyeHeightSlider.setPrecision(1);
    }
    language = find("language", UIDropdownScrollable.class);
    if (language != null) {
        SimpleUri menuUri = new SimpleUri("engine:menu");
        TranslationProject menuProject = translationSystem.getProject(menuUri);
        List<Locale> locales = new ArrayList<>(menuProject.getAvailableLocales());
        for (Locale languageExcluded : languagesExcluded) {
            locales.remove(languageExcluded);
        }
        Collections.sort(locales, ((Object o1, Object o2) -> (o1.toString().compareTo(o2.toString()))));
        language.setOptions(Lists.newArrayList(locales));
        // Set maximum number of options visible for scrolling
        language.setVisibleOptions(5);
        language.setOptionRenderer(new LocaleRenderer(translationSystem));
    }
    WidgetUtil.trySubscribe(this, "close", button -> triggerBackAnimation());
    IdentityIOHelper identityIOHelper = new IdentityIOHelper(context);
    WidgetUtil.trySubscribe(this, "importIdentities", button -> identityIOHelper.importIdentities());
    WidgetUtil.trySubscribe(this, "exportIdentities", button -> identityIOHelper.exportIdentities());
    WidgetUtil.trySubscribe(this, "storageServiceAction", widget -> {
        if (storageService.getStatus() == StorageServiceWorkerStatus.LOGGED_IN) {
            ThreeButtonPopup logoutPopup = getManager().pushScreen(ThreeButtonPopup.ASSET_URI, ThreeButtonPopup.class);
            logoutPopup.setMessage(translationSystem.translate("${engine:menu#storage-service-log-out}"), translationSystem.translate("${engine:menu#storage-service-log-out-popup}"));
            logoutPopup.setLeftButton(translationSystem.translate("${engine:menu#dialog-yes}"), () -> storageService.logout(true));
            logoutPopup.setCenterButton(translationSystem.translate("${engine:menu#dialog-no}"), () -> storageService.logout(false));
            logoutPopup.setRightButton(translationSystem.translate("${engine:menu#dialog-cancel}"), () -> {
            });
        } else if (storageService.getStatus() == StorageServiceWorkerStatus.LOGGED_OUT) {
            getManager().pushScreen(StorageServiceLoginPopup.ASSET_URI, StorageServiceLoginPopup.class);
        }
    });
    UIButton okButton = find("ok", UIButton.class);
    if (okButton != null) {
        okButton.subscribe(button -> {
            savePlayerSettings();
            triggerBackAnimation();
        });
        okButton.bindEnabled(new ReadOnlyBinding<Boolean>() {

            @Override
            public Boolean get() {
                return Strings.isNullOrEmpty(validateScreen());
            }
        });
        okButton.setTooltipDelay(0);
        okButton.bindTooltipString(new ReadOnlyBinding<String>() {

            @Override
            public String get() {
                return validateScreen();
            }
        });
    }
}
Also used : UILabel(org.terasology.rendering.nui.widgets.UILabel) Locale(java.util.Locale) UISlider(org.terasology.rendering.nui.widgets.UISlider) UIDropdownScrollable(org.terasology.rendering.nui.widgets.UIDropdownScrollable) SimpleUri(org.terasology.engine.SimpleUri) ArrayList(java.util.ArrayList) Texture(org.terasology.rendering.assets.texture.Texture) StorageServiceLoginPopup(org.terasology.rendering.nui.layers.mainMenu.StorageServiceLoginPopup) TranslationProject(org.terasology.i18n.TranslationProject) UIButton(org.terasology.rendering.nui.widgets.UIButton) UIText(org.terasology.rendering.nui.widgets.UIText) UIImage(org.terasology.rendering.nui.widgets.UIImage) ResourceUrn(org.terasology.assets.ResourceUrn) ThreeButtonPopup(org.terasology.rendering.nui.layers.mainMenu.ThreeButtonPopup)

Example 3 with Texture

use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class BlockSelectionRenderSystem method renderOverlay.

@Override
public void renderOverlay() {
    for (EntityRef entity : entityManager.getEntitiesWith(BlockSelectionComponent.class)) {
        BlockSelectionComponent blockSelectionComponent = entity.getComponent(BlockSelectionComponent.class);
        if (blockSelectionComponent.shouldRender) {
            Texture texture = blockSelectionComponent.texture;
            if (null == texture) {
                texture = Assets.getTexture("engine:selection").get();
            }
            Vector2i textureDimensions = new Vector2i(texture.getWidth(), texture.getHeight());
            BlockSelectionRenderer selectionRenderer = cachedBlockSelectionRendererByTextureDimensionsMap.get(textureDimensions);
            if (null == selectionRenderer) {
                selectionRenderer = new BlockSelectionRenderer(texture);
                cachedBlockSelectionRendererByTextureDimensionsMap.put(textureDimensions, selectionRenderer);
            } else {
                selectionRenderer.setEffectsTexture(texture);
            }
            renderOverlayForOneBlockSelection(blockSelectionComponent, selectionRenderer);
        }
    }
}
Also used : BlockSelectionComponent(org.terasology.world.selection.BlockSelectionComponent) Vector2i(org.terasology.math.geom.Vector2i) EntityRef(org.terasology.entitySystem.entity.EntityRef) Texture(org.terasology.rendering.assets.texture.Texture)

Example 4 with Texture

use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class FontDataBuilder method endCharacter.

public FontDataBuilder endCharacter() {
    Texture page = pages.get(characterPage);
    FontCharacter character = new FontCharacter(((float) characterX / page.getWidth()), ((float) characterY / page.getHeight()), characterWidth, characterHeight, characterXOffset, characterYOffset, characterXAdvance, page, pageMats.get(characterPage));
    characters.put(currentCharacterId, character);
    return this;
}
Also used : Texture(org.terasology.rendering.assets.texture.Texture)

Example 5 with Texture

use of org.terasology.rendering.assets.texture.Texture in project Terasology by MovingBlocks.

the class AmbientOcclusionNode method generateNoiseTexture.

private Texture generateNoiseTexture() {
    Optional<Texture> texture = Assets.getTexture("engine:ssaoNoise");
    if (!texture.isPresent()) {
        ByteBuffer noiseValues = BufferUtils.createByteBuffer(SSAO_NOISE_SIZE * SSAO_NOISE_SIZE * 4);
        for (int i = 0; i < SSAO_NOISE_SIZE * SSAO_NOISE_SIZE; ++i) {
            Vector3f noiseVector = new Vector3f(randomGenerator.nextFloat(-1.0f, 1.0f), randomGenerator.nextFloat(-1.0f, 1.0f), 0.0f);
            noiseVector.normalize();
            noiseValues.put((byte) ((noiseVector.x * 0.5 + 0.5) * 255.0f));
            noiseValues.put((byte) ((noiseVector.y * 0.5 + 0.5) * 255.0f));
            noiseValues.put((byte) ((noiseVector.z * 0.5 + 0.5) * 255.0f));
            noiseValues.put((byte) 0x0);
        }
        noiseValues.flip();
        return Assets.generateAsset(new ResourceUrn("engine:ssaoNoise"), new TextureData(SSAO_NOISE_SIZE, SSAO_NOISE_SIZE, new ByteBuffer[] { noiseValues }, Texture.WrapMode.REPEAT, Texture.FilterMode.NEAREST), Texture.class);
    }
    return texture.get();
}
Also used : TextureData(org.terasology.rendering.assets.texture.TextureData) Vector3f(org.terasology.math.geom.Vector3f) ResourceUrn(org.terasology.assets.ResourceUrn) Texture(org.terasology.rendering.assets.texture.Texture) DepthStencilTexture(org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo.FboTexturesTypes.DepthStencilTexture) NormalsTexture(org.terasology.rendering.dag.stateChanges.SetInputTextureFromFbo.FboTexturesTypes.NormalsTexture) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Texture (org.terasology.rendering.assets.texture.Texture)15 ResourceUrn (org.terasology.assets.ResourceUrn)7 TextureData (org.terasology.rendering.assets.texture.TextureData)7 ByteBuffer (java.nio.ByteBuffer)6 MaterialData (org.terasology.rendering.assets.material.MaterialData)5 ModuleAwareAssetTypeManager (org.terasology.assets.module.ModuleAwareAssetTypeManager)4 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 AssetFactory (org.terasology.assets.AssetFactory)3 Config (org.terasology.config.Config)3 Context (org.terasology.context.Context)3 MeshAnimation (org.terasology.rendering.assets.animation.MeshAnimation)3 MeshAnimationData (org.terasology.rendering.assets.animation.MeshAnimationData)3 MeshAnimationImpl (org.terasology.rendering.assets.animation.MeshAnimationImpl)3 Atlas (org.terasology.rendering.assets.atlas.Atlas)3 AtlasData (org.terasology.rendering.assets.atlas.AtlasData)3 Font (org.terasology.rendering.assets.font.Font)3 Lists (com.google.common.collect.Lists)2 IOException (java.io.IOException)2 List (java.util.List)2