use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method loadImage.
@Override
public Image loadImage(final String filename) {
TextureKey key = new TextureKey(filename, false);
key.setAnisotropy(0);
key.setGenerateMips(false);
Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key);
return new ImageImpl(texture.getImage());
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method createNonAtlasTexture.
@Override
public int createNonAtlasTexture(final Image image) {
ImageImpl imageImpl = (ImageImpl) image;
Texture2D texture = new Texture2D(imageImpl.image);
texture.setMinFilter(MinFilter.NearestNoMipMaps);
texture.setMagFilter(MagFilter.Nearest);
return addTexture(texture);
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class JmeBatchRenderBackend method modifyTexture.
private void modifyTexture(final Texture2D textureAtlas, final com.jme3.texture.Image image, final int x, final int y) {
Renderer renderer = display.getRenderer();
if (renderer == null) {
// we have no renderer (yet) so we'll need to cache this call to the next beginFrame() call
modifyTextureCalls.add(new ModifyTexture(textureAtlas, image, x, y));
return;
}
// all is well, we can execute the modify right away
renderer.modifyTexture(textureAtlas, image, x, y);
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class CombinedTexture method generateSkyTexture.
/**
* Generates a texture that will be used by the sky spatial.
* The result texture has 6 layers. Every image in each layer has equal size and its shape is a square.
* The size of each image is the maximum size (width or height) of the textures given.
* The default sky generated texture size is used (this value is set in the BlenderKey) if no picture textures
* are present or their sizes is lower than the generated texture size.
* The textures of lower sizes are properly scaled.
* All the textures are mixed into one and put as layers in the result texture.
*
* @param horizontalColor
* the horizon color
* @param zenithColor
* the zenith color
* @param blenderContext
* the blender context
* @return texture for the sky
*/
public TextureCubeMap generateSkyTexture(ColorRGBA horizontalColor, ColorRGBA zenithColor, BlenderContext blenderContext) {
LOGGER.log(Level.FINE, "Preparing sky texture from {0} applied textures.", textureDatas.size());
LOGGER.fine("Computing the texture size.");
int size = -1;
for (TextureData textureData : textureDatas) {
if (textureData.texture instanceof Texture2D) {
size = Math.max(textureData.texture.getImage().getWidth(), size);
size = Math.max(textureData.texture.getImage().getHeight(), size);
}
}
if (size < 0) {
size = blenderContext.getBlenderKey().getSkyGeneratedTextureSize();
}
LOGGER.log(Level.FINE, "The sky texture size will be: {0}x{0}.", size);
TextureCubeMap result = null;
for (TextureData textureData : textureDatas) {
TextureCubeMap texture = null;
if (textureData.texture instanceof GeneratedTexture) {
texture = ((GeneratedTexture) textureData.texture).generateSkyTexture(size, horizontalColor, zenithColor, blenderContext);
} else {
// first create a grayscale version of the image
Image image = textureData.texture.getImage();
if (image.getWidth() != image.getHeight() || image.getWidth() != size) {
image = ImageUtils.resizeTo(image, size, size);
}
Image grayscaleImage = ImageUtils.convertToGrayscaleTexture(image);
// add the sky colors to the image
PixelInputOutput sourcePixelIO = PixelIOFactory.getPixelIO(grayscaleImage.getFormat());
PixelInputOutput targetPixelIO = PixelIOFactory.getPixelIO(image.getFormat());
TexturePixel texturePixel = new TexturePixel();
for (int x = 0; x < image.getWidth(); ++x) {
for (int y = 0; y < image.getHeight(); ++y) {
sourcePixelIO.read(grayscaleImage, 0, texturePixel, x, y);
// no matter which factor we use here, in grayscale they are all equal
texturePixel.intensity = texturePixel.red;
ImageUtils.color(texturePixel, horizontalColor, zenithColor);
targetPixelIO.write(image, 0, texturePixel, x, y);
}
}
// create the cubemap texture from the coloured image
ByteBuffer sourceData = image.getData(0);
ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(6);
for (int i = 0; i < 6; ++i) {
data.add(BufferUtils.clone(sourceData));
}
texture = new TextureCubeMap(new Image(image.getFormat(), image.getWidth(), image.getHeight(), 6, data, ColorSpace.Linear));
}
if (result == null) {
result = texture;
} else {
ImageUtils.mix(result.getImage(), texture.getImage());
}
}
return result;
}
use of com.jme3.texture.Texture2D in project jmonkeyengine by jMonkeyEngine.
the class CombinedTexture method scale.
/**
* This method scales the given texture to the given size.
*
* @param texture
* the texture to be scaled
* @param width
* new width of the texture
* @param height
* new height of the texture
*/
private void scale(Texture2D texture, int width, int height) {
// first determine if scaling is required
boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height;
if (scaleRequired) {
Image image = texture.getImage();
BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0);
int sourceWidth = sourceImage.getWidth();
int sourceHeight = sourceImage.getHeight();
BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType());
Graphics2D g = targetImage.createGraphics();
g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null);
g.dispose();
Image output = new ImageLoader().load(targetImage, false);
image.setWidth(width);
image.setHeight(height);
image.setData(output.getData(0));
image.setFormat(output.getFormat());
}
}
Aggregations