/** * Parametrized constructor. * * @param id The ID to assign to the widget */ public UIText(String id) { super(id); cursorTexture = Assets.getTexture("engine:white").get(); }
/** * Default constructor. */ public UIText() { cursorTexture = Assets.getTexture("engine:white").get(); }
@Override public Texture getTexture(Locale value) { Optional<Texture> texture = Assets.getTexture(String.format("engine:flag_%s", value.getLanguage())); if (texture.isPresent()) { return texture.get(); } else { return Assets.getTexture(ICON_BLANK).get(); } } }
@Override public FrameBufferObject getFBO(ResourceUrn urn, BaseVector2i size) { LwjglFrameBufferObject frameBufferObject = fboMap.get(urn); if (frameBufferObject == null || !Assets.getTexture(urn).isPresent()) { // If a FBO exists, but no texture, then the texture was disposed // TODO: update fboMap whenever a texture is disposed (or convert FBO instances to assets?) if (frameBufferObject != null) { frameBufferObject.dispose(); } frameBufferObject = new LwjglFrameBufferObject(urn, size); fboMap.put(urn, frameBufferObject); } return frameBufferObject; }
/** * The constructor, to be used in the initialise method of a node. * * Sample use: * addDesiredStateChange(new SetInputTexture(GL_TEXTURE_2D, 0, "engine:water", "engine:prog.chunk", "textureWater")); * * @param textureType an opengl constant, can be GL_TEXTURE_2D, GL_TEXTURE_3D and any other texture type listed in https://www.khronos.org/opengl/wiki/Texture#Theory * @param textureSlot a 0-based integer. Notice that textureUnit = GL_TEXTURE0 + textureSlot. See OpenGL spects for maximum allowed values. * @param textureUrn a String identifying a loaded texture, whose id will then be used by this StateChange. * @param materialUrn a ResourceURN object uniquely identifying a Material asset. * @param materialParameter a String representing the variable within the shader holding the texture. */ protected SetInputTexture(int textureType, int textureSlot, String textureUrn, ResourceUrn materialUrn, String materialParameter) { this.textureType = textureType; this.textureSlot = textureSlot; this.materialUrn = materialUrn; this.materialParameter = materialParameter; this.material = getMaterial(materialUrn); Optional<Texture> optionalTexture = Assets.getTexture(textureUrn); if (optionalTexture.isPresent()) { this.textureId = optionalTexture.get().getId(); } else { this.textureId = 0; // TODO: Maybe throw some exception or use Logger.error()? } // TODO: take advantage of Texture.subscribeToDisposal(Runnable) to reobtain the asset if necessary }
private void reloadHeightmap() { logger.info("Reading height map '{}'", configuration.heightMap); ResourceUrn urn = new ResourceUrn("core", configuration.heightMap); Texture texture = Assets.getTexture(urn).get(); ByteBuffer[] bb = texture.getData().getBuffers(); IntBuffer intBuf = bb[0].asIntBuffer(); mapWidth = texture.getWidth(); mapHeight = texture.getHeight(); heightmap = new float[mapWidth][mapHeight]; while (intBuf.position() < intBuf.limit()) { int pos = intBuf.position(); long val = intBuf.get() & 0xFFFFFFFFL; heightmap[pos % mapWidth][pos / mapWidth] = val / (256 * 256 * 256 * 256f); } }
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(); } }
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); }); }
Optional<Texture> terrainTex = Assets.getTexture("engine:terrain"); if (terrainTex.isPresent()) { icon.setMeshTexture(terrainTex.get()); } else { icon.setMeshTexture(Assets.getTexture("engine:default").get());
@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); } } }
public CanvasImpl(NUIManager nuiManager, Context context, CanvasRenderer renderer) { this.renderer = renderer; this.nuiManager = nuiManager; this.time = context.get(Time.class); this.keyboard = context.get(InputSystem.class).getKeyboard(); this.mouse = context.get(InputSystem.class).getMouseDevice(); this.meshMat = Assets.getMaterial("engine:UILitMesh").get(); this.whiteTexture = Assets.getTexture("engine:white").get(); this.renderingConfig = context.get(Config.class).getRendering(); this.uiScale = this.renderingConfig.getUiScale() / 100f; this.renderingConfig.subscribe(RenderingConfig.UI_SCALE, this); }
/** * Creates a new entity for the block damage particle effect. * * If the terrain texture of the damaged block is available, the particles will have the block texture. Otherwise, * the default sprite (smoke) is used. * * @param family the {@link BlockFamily} of the damaged block * @param location the location of the damaged block */ private void createBlockParticleEffect(BlockFamily family, Vector3f location) { EntityBuilder builder = entityManager.newBuilder("core:defaultBlockParticles"); builder.getComponent(LocationComponent.class).setWorldPosition(location); Optional<Texture> terrainTexture = Assets.getTexture("engine:terrain"); if (terrainTexture.isPresent() && terrainTexture.get().isLoaded()) { final BlockAppearance blockAppearance = family.getArchetypeBlock().getPrimaryAppearance(); final float relativeTileSize = worldAtlas.getRelativeTileSize(); final float particleScale = 0.25f; final float spriteSize = relativeTileSize * particleScale; ParticleDataSpriteComponent spriteComponent = builder.getComponent(ParticleDataSpriteComponent.class); spriteComponent.texture = terrainTexture.get(); spriteComponent.textureSize.set(spriteSize, spriteSize); final List<Vector2f> offsets = computeOffsets(blockAppearance, particleScale); TextureOffsetGeneratorComponent textureOffsetGeneratorComponent = builder.getComponent(TextureOffsetGeneratorComponent.class); textureOffsetGeneratorComponent.validOffsets.addAll(offsets); } builder.build(); }
@Test public void testNoiseTextures() { int size = 256; ResourceUrn textureUriForWhiteNoise = TextureUtil.getTextureUriForWhiteNoise(size, 123354, 0, 255); String simpleString = textureUriForWhiteNoise.toString(); Optional<Texture> tex = Assets.getTexture(simpleString); assertTrue(tex.isPresent()); assertTrue(tex.get().getWidth() == size); assertTrue(tex.get().getHeight() == size); } }
Optional<Texture> texture = Assets.getTexture(textureName != null ? String.format("engine:editor_%s", textureName) : ICON_BLANK);
icon.setMeshTexture(Assets.getTexture("engine:terrain").get()); icon.bindQuantity(new ReadOnlyBinding<Integer>() { @Override
@Test public void testColorTextures() { Random r = new FastRandom(123456); for (int i = 0; i < 10; i++) { int rgba = r.nextInt(); Color red = new Color(rgba); ResourceUrn textureUriForColor = TextureUtil.getTextureUriForColor(red); String simpleString = textureUriForColor.toString(); Optional<Texture> tex = Assets.getTexture(simpleString); assertTrue(tex.isPresent()); ByteBuffer dataBuffer = tex.get().getData().getBuffers()[0]; int firstPixel = dataBuffer.asIntBuffer().get(0); Assert.assertEquals(rgba, firstPixel); } }