use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TestImageRaster method simpleInitApp.
@Override
public void simpleInitApp() {
cam.setLocation(new Vector3f(16, 6, 36));
flyCam.setMoveSpeed(10);
Texture tex = assetManager.loadTexture("com/jme3/app/Monkey.png");
// Texture tex = assetManager.loadTexture("Textures/HdrTest/Memorial.hdr");
Image originalImage = tex.getImage();
Image image = convertImage(originalImage, Format.RGBA32F);
convertAndPutImage(image, 0, 0);
image = convertImage(image, Format.RGB32F);
convertAndPutImage(image, 5, 0);
image = convertImage(image, Format.RGBA16F);
convertAndPutImage(image, 10, 0);
image = convertImage(image, Format.RGB16F);
convertAndPutImage(image, 15, 0);
image = convertImage(image, Format.RGB16F_to_RGB9E5);
convertAndPutImage(image, 20, 0);
image = convertImage(image, Format.RGB16F_to_RGB111110F);
convertAndPutImage(image, 25, 0);
image = convertImage(image, Format.RGBA8);
convertAndPutImage(image, 10, 5);
image = convertImage(image, Format.RGB8);
convertAndPutImage(image, 15, 5);
image = convertImage(image, Format.ABGR8);
convertAndPutImage(image, 20, 5);
image = convertImage(image, Format.BGR8);
convertAndPutImage(image, 25, 5);
image = convertImage(image, Format.ARGB8);
convertAndPutImage(image, 30, 5);
image = convertImage(image, Format.BGRA8);
convertAndPutImage(image, 35, 5);
image = convertImage(image, Format.RGB5A1);
convertAndPutImage(image, 0, 10);
image = convertImage(image, Format.RGB565);
convertAndPutImage(image, 5, 10);
image = convertImage(image, Format.Luminance32F);
convertAndPutImage(image, 0, 15);
image = convertImage(image, Format.Luminance16FAlpha16F);
convertAndPutImage(image, 5, 15);
image = convertImage(image, Format.Luminance16F);
convertAndPutImage(image, 10, 15);
image = convertImage(image, Format.Luminance8Alpha8);
convertAndPutImage(image, 15, 15);
image = convertImage(image, Format.Luminance8);
convertAndPutImage(image, 20, 15);
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TestImageRaster method convertImage.
private Image convertImage(Image image, Format newFormat) {
int width = image.getWidth();
int height = image.getHeight();
ByteBuffer data = BufferUtils.createByteBuffer((int) Math.ceil(newFormat.getBitsPerPixel() / 8.0) * width * height);
Image convertedImage = new Image(newFormat, width, height, data, null, image.getColorSpace());
ImageRaster sourceReader = ImageRaster.create(image);
ImageRaster targetWriter = ImageRaster.create(convertedImage);
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
ColorRGBA color = sourceReader.getPixel(x, y);
targetWriter.setPixel(x, y, color);
}
}
return convertedImage;
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TestTexture3D method getTexture.
/**
* This method creates a RGB8 texture with the sizes of 10x10x10 pixels.
*/
private Texture getTexture() throws IOException {
ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(1);
//all data must be inside one buffer
ByteBuffer bb = BufferUtils.createByteBuffer(10 * 10 * 10 * 3);
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 10 * 10; ++j) {
bb.put((byte) (255f * i / 10f));
bb.put((byte) (255f * i / 10f));
bb.put((byte) (255f));
}
}
bb.rewind();
data.add(bb);
return new Texture3D(new Image(Format.RGB8, 10, 10, 10, data, null, ColorSpace.Linear));
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class TextureUtil method uploadTexture.
public static void uploadTexture(Image image, int target, int index, int border, boolean linearizeSrgb) {
GL gl = GLContext.getCurrentGL();
Image.Format fmt = image.getFormat();
GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
ByteBuffer data;
if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
data = image.getData(index);
} else {
data = null;
}
int width = image.getWidth();
int height = image.getHeight();
int depth = image.getDepth();
if (data != null) {
if (abgrToRgbaConversionEnabled) {
convertABGRtoRGBA(data);
}
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
}
int[] mipSizes = image.getMipMapSizes();
int pos = 0;
// TODO: Remove unneccessary allocation
if (mipSizes == null) {
if (data != null)
mipSizes = new int[] { data.capacity() };
else
mipSizes = new int[] { width * height * fmt.getBitsPerPixel() / 8 };
}
boolean subtex = false;
int samples = image.getMultiSamples();
for (int i = 0; i < mipSizes.length; i++) {
int mipWidth = Math.max(1, width >> i);
int mipHeight = Math.max(1, height >> i);
int mipDepth = Math.max(1, depth >> i);
if (data != null) {
data.position(pos);
data.limit(pos + mipSizes[i]);
}
if (glFmt.compressed && data != null) {
if (target == GL2ES2.GL_TEXTURE_3D) {
gl.getGL2ES2().glCompressedTexImage3D(target, i, glFmt.internalFormat, mipWidth, mipHeight, mipDepth, data.remaining(), border, data);
} else {
//all other targets use 2D: array, cubemap, 2d
gl.glCompressedTexImage2D(target, i, glFmt.internalFormat, mipWidth, mipHeight, data.remaining(), border, data);
}
} else {
if (target == GL2ES2.GL_TEXTURE_3D) {
gl.getGL2ES2().glTexImage3D(target, i, glFmt.internalFormat, mipWidth, mipHeight, mipDepth, border, glFmt.format, glFmt.dataType, data);
} else if (target == GL2ES3.GL_TEXTURE_2D_ARRAY) {
// or upload slice
if (index == -1) {
gl.getGL2ES2().glTexImage3D(target, 0, glFmt.internalFormat, mipWidth, mipHeight, //# of slices
image.getData().size(), border, glFmt.format, glFmt.dataType, data);
} else {
gl.getGL2ES2().glTexSubImage3D(target, // level
i, // xoffset
0, // yoffset
0, // zoffset
index, // width
width, // height
height, // depth
1, glFmt.format, glFmt.dataType, data);
}
} else {
if (subtex) {
if (samples > 1) {
throw new IllegalStateException("Cannot update multisample textures");
}
gl.glTexSubImage2D(target, i, 0, 0, mipWidth, mipHeight, glFmt.format, glFmt.dataType, data);
} else {
if (samples > 1) {
if (gl.isGL2GL3()) {
gl.getGL3().glTexImage2DMultisample(target, samples, glFmt.internalFormat, mipWidth, mipHeight, true);
}
} else {
gl.glTexImage2D(target, i, glFmt.internalFormat, mipWidth, mipHeight, border, glFmt.format, glFmt.dataType, data);
}
}
}
}
pos += mipSizes[i];
}
}
use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.
the class RenderDeviceJme method renderImage.
public void renderImage(RenderImage image, int x, int y, int w, int h, int srcX, int srcY, int srcW, int srcH, Color color, float scale, int centerX, int centerY) {
RenderImageJme jmeImage = (RenderImageJme) image;
Texture2D texture = jmeImage.getTexture();
textureColorMaterial.setColor("Color", convertColor(color, tempColor));
textureColorMaterial.setTexture("ColorMap", texture);
float imageWidth = jmeImage.getWidth();
float imageHeight = jmeImage.getHeight();
FloatBuffer texCoords = (FloatBuffer) quadModTC.getData();
float startX = srcX / imageWidth;
float startY = srcY / imageHeight;
float endX = startX + (srcW / imageWidth);
float endY = startY + (srcH / imageHeight);
startY = 1f - startY;
endY = 1f - endY;
texCoords.rewind();
texCoords.put(startX).put(startY);
texCoords.put(endX).put(startY);
texCoords.put(endX).put(endY);
texCoords.put(startX).put(endY);
texCoords.flip();
quadModTC.updateData(texCoords);
quad.clearBuffer(Type.TexCoord);
quad.setBuffer(quadModTC);
float x0 = centerX + (x - centerX) * scale;
float y0 = centerY + (y - centerY) * scale;
tempMat.loadIdentity();
tempMat.setTranslation(x0, getHeight() - y0, 0);
tempMat.setScale(w * scale, h * scale, 0);
rm.setWorldMatrix(tempMat);
rm.setForcedRenderState(renderState);
textureColorMaterial.render(quadGeom, rm);
//System.out.format("renderImage2(%s, %d, %d, %d, %d, %d, %d, %d, %d, %s, %f, %d, %d)\n", texture.getKey().toString(),
// x, y, w, h, srcX, srcY, srcW, srcH,
// color.toString(), scale, centerX, centerY);
}
Aggregations