use of org.terasology.engine.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class WorldPreGenerationScreen method updatePreview.
/**
* Updates the preview according to any changes made to the configurator.
* Also pops up a message and keeps track of percentage world preview prepared.
*/
private void updatePreview() {
final NUIManager manager = context.get(NUIManager.class);
final WaitPopup<TextureData> popup = manager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
popup.setMessage("Updating Preview", "Please wait ...");
ProgressListener progressListener = progress -> popup.setMessage("Updating Preview", String.format("Please wait ... %d%%", (int) (progress * 100f)));
Callable<TextureData> operation = () -> {
int zoom = TeraMath.floorToInt(zoomSlider.getValue());
TextureData data = texture.getData();
previewGen.render(data, zoom, progressListener);
return data;
};
popup.onSuccess(texture::reload);
popup.startOperation(operation, true);
}
use of org.terasology.engine.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class PreviewWorldScreen method updatePreview.
private void updatePreview() {
final NUIManager manager = context.get(NUIManager.class);
final WaitPopup<TextureData> popup = manager.pushScreen(WaitPopup.ASSET_URI, WaitPopup.class);
popup.setMessage("Updating Preview", "Please wait ...");
ProgressListener progressListener = progress -> popup.setMessage("Updating Preview", String.format("Please wait ... %d%%", (int) (progress * 100f)));
Callable<TextureData> operation = () -> {
if (seed != null) {
worldGenerator.setWorldSeed(seed.getText());
}
int zoom = TeraMath.floorToInt(zoomSlider.getValue());
TextureData data = texture.getData();
if (zoneSelector.isVisible()) {
previewGen = zoneSelector.getSelection().preview(worldGenerator);
}
previewGen.render(data, zoom, progressListener);
return data;
};
popup.onSuccess(texture::reload);
popup.startOperation(operation, true);
}
use of org.terasology.engine.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class SelectionScreen method loadPreviewImages.
private void loadPreviewImages(final GameInfo gameInfo) {
List<Texture> textures = new ArrayList<>();
if (gameInfo != null && gameInfo.getSavePath() != null) {
final List<BufferedImage> bufferedImages = GamePreviewImageProvider.getAllPreviewImages(gameInfo.getSavePath());
textures = bufferedImages.stream().map(buffImage -> {
TextureData textureData;
try {
textureData = AWTTextureFormat.convertToTextureData(buffImage, Texture.FilterMode.LINEAR);
} catch (IOException e) {
logger.error("Converting preview image to texture data {} failed", e);
return null;
}
return Assets.generateAsset(new ResourceUrn(PREVIEW_IMAGE_URI_PATTERN + bufferedImages.indexOf(buffImage)), textureData, Texture.class);
}).filter(Objects::nonNull).collect(Collectors.toList());
}
if (textures.isEmpty()) {
textures.add(Assets.getTexture(DEFAULT_PREVIEW_IMAGE_URI).get());
}
previewSlideshow.clean();
textures.forEach(tex -> {
UIImage image = new UIImage(null, tex, true);
previewSlideshow.addImage(image);
});
}
use of org.terasology.engine.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class LwjglFrameBufferObject method generateTexture.
private Texture generateTexture(ResourceUrn urn) {
ByteBuffer buffer = ByteBuffer.allocateDirect(size.x() * size.y() * Integer.BYTES);
ByteBuffer[] mipmaps = new ByteBuffer[] { buffer };
TextureData data = new TextureData(size.x(), size.y(), mipmaps, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
return Assets.generateAsset(urn, data, Texture.class);
}
use of org.terasology.engine.rendering.assets.texture.TextureData in project Terasology by MovingBlocks.
the class WorldAtlasImpl method buildAtlas.
private void buildAtlas() {
calculateAtlasSizes();
int numMipMaps = getNumMipmaps();
ByteBuffer[] data = createAtlasMipmaps(numMipMaps, TRANSPARENT_COLOR, tiles, "tiles.png");
ByteBuffer[] dataNormal = createAtlasMipmaps(numMipMaps, UNIT_Z_COLOR, tilesNormal, "tilesNormal.png", tilesGloss);
ByteBuffer[] dataHeight = createAtlasMipmaps(numMipMaps, MID_RED_COLOR, tilesHeight, "tilesHeight.png");
TextureData terrainTexData = new TextureData(atlasSize, atlasSize, data, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
Texture terrainTex = Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainTexData, Texture.class);
TextureData terrainNormalData = new TextureData(atlasSize, atlasSize, dataNormal, Texture.WrapMode.CLAMP, Texture.FilterMode.NEAREST);
Assets.generateAsset(new ResourceUrn("engine:terrainNormal"), terrainNormalData, Texture.class);
TextureData terrainHeightData = new TextureData(atlasSize, atlasSize, dataHeight, Texture.WrapMode.CLAMP, Texture.FilterMode.LINEAR);
Assets.generateAsset(new ResourceUrn("engine:terrainHeight"), terrainHeightData, Texture.class);
MaterialData terrainMatData = new MaterialData(Assets.getShader("engine:block").get());
terrainMatData.setParam("textureAtlas", terrainTex);
terrainMatData.setParam("colorOffset", new float[] { 1, 1, 1 });
terrainMatData.setParam("textured", true);
Assets.generateAsset(new ResourceUrn("engine:terrain"), terrainMatData, Material.class);
createTextureAtlas(terrainTex);
}
Aggregations