use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class HelloEffects method simpleInitApp.
@Override
public void simpleInitApp() {
ParticleEmitter fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
mat_red.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
fire.setMaterial(mat_red);
fire.setImagesX(2);
// 2x2 texture animation
fire.setImagesY(2);
// red
fire.setEndColor(new ColorRGBA(1f, 0f, 0f, 1f));
// yellow
fire.setStartColor(new ColorRGBA(1f, 1f, 0f, 0.5f));
fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 2, 0));
fire.setStartSize(1.5f);
fire.setEndSize(0.1f);
fire.setGravity(0, 0, 0);
fire.setLowLife(1f);
fire.setHighLife(3f);
fire.getParticleInfluencer().setVelocityVariation(0.3f);
rootNode.attachChild(fire);
ParticleEmitter debris = new ParticleEmitter("Debris", ParticleMesh.Type.Triangle, 10);
Material debris_mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
debris_mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/Debris.png"));
debris.setMaterial(debris_mat);
debris.setImagesX(3);
// 3x3 texture animation
debris.setImagesY(3);
debris.setSelectRandomImage(true);
debris.setRotateSpeed(4);
debris.getParticleInfluencer().setInitialVelocity(new Vector3f(0, 4, 0));
debris.setStartColor(ColorRGBA.White);
debris.setGravity(0, 6, 0);
debris.getParticleInfluencer().setVelocityVariation(.60f);
rootNode.attachChild(debris);
debris.emitAllParticles();
// ParticleEmitter water =
// new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 20);
// Material mat_blue = new Material(assetManager,
// "Common/MatDefs/Misc/Particle.j3md");
// mat_blue.setTexture("Texture", assetManager.loadTexture(
// "Effects/Explosion/flame.png"));
// water.setMaterial(mat_blue);
// water.setImagesX(2);
// water.setImagesY(2); // 2x2 texture animation
// water.setStartColor( ColorRGBA.Blue);
// water.setEndColor( ColorRGBA.Cyan);
// water.getParticleInfluencer().setInitialVelocity(new Vector3f(0, -4, 0));
// water.setStartSize(1f);
// water.setEndSize(1.5f);
// water.setGravity(0,1,0);
// water.setLowLife(1f);
// water.setHighLife(1f);
// water.getParticleInfluencer().setVelocityVariation(0.1f);
// water.setLocalTranslation(0, 6, 0);
// rootNode.attachChild(water);
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class HelloMaterial method simpleInitApp.
@Override
public void simpleInitApp() {
/** A simple textured cube -- in good MIP map quality. */
Box cube1Mesh = new Box(1f, 1f, 1f);
Geometry cube1Geo = new Geometry("My Textured Box", cube1Mesh);
cube1Geo.setLocalTranslation(new Vector3f(-3f, 1.1f, 0f));
Material cube1Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
Texture cube1Tex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
cube1Mat.setTexture("ColorMap", cube1Tex);
cube1Geo.setMaterial(cube1Mat);
rootNode.attachChild(cube1Geo);
/** A translucent/transparent texture, similar to a window frame. */
Box cube2Mesh = new Box(1f, 1f, 0.01f);
Geometry cube2Geo = new Geometry("window frame", cube2Mesh);
Material cube2Mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
cube2Mat.setTexture("ColorMap", assetManager.loadTexture("Textures/ColoredTex/Monkey.png"));
// activate transparency
cube2Mat.getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
cube2Geo.setQueueBucket(Bucket.Transparent);
cube2Geo.setMaterial(cube2Mat);
rootNode.attachChild(cube2Geo);
/** A bumpy rock with a shiny light effect. To make bumpy objects you must create a NormalMap. */
Sphere sphereMesh = new Sphere(32, 32, 2f);
Geometry sphereGeo = new Geometry("Shiny rock", sphereMesh);
// better quality on spheres
sphereMesh.setTextureMode(Sphere.TextureMode.Projected);
// for lighting effect
TangentBinormalGenerator.generate(sphereMesh);
Material sphereMat = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
sphereMat.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond.jpg"));
sphereMat.setTexture("NormalMap", assetManager.loadTexture("Textures/Terrain/Pond/Pond_normal.png"));
sphereMat.setBoolean("UseMaterialColors", true);
sphereMat.setColor("Diffuse", ColorRGBA.White);
sphereMat.setColor("Specular", ColorRGBA.White);
// [0,128]
sphereMat.setFloat("Shininess", 64f);
sphereGeo.setMaterial(sphereMat);
//sphereGeo.setMaterial((Material) assetManager.loadMaterial("Materials/MyCustomMaterial.j3m"));
// Move it a bit
sphereGeo.setLocalTranslation(0, 2, -2);
// Rotate it a bit
sphereGeo.rotate(1.6f, 0, 0);
rootNode.attachChild(sphereGeo);
/** Must add a light to make the lit object visible! */
DirectionalLight sun = new DirectionalLight();
sun.setDirection(new Vector3f(1, 0, -2).normalizeLocal());
sun.setColor(ColorRGBA.White);
rootNode.addLight(sun);
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class ImageTileLoader method getHeightMapAt.
/**
* Lets you specify the type of images that are being loaded. All images
* must be the same type.
* @param imageType eg. BufferedImage.TYPE_USHORT_GRAY
*/
/*public void setImageType(int imageType) {
this.imageType = imageType;
}*/
/**
* The ImageHeightmap that will parse the image type that you
* specify with setImageType().
* @param customImageHeightmap must extend AbstractHeightmap
*/
/*public void setCustomImageHeightmap(ImageHeightmap customImageHeightmap) {
if (!(customImageHeightmap instanceof AbstractHeightMap)) {
throw new IllegalArgumentException("customImageHeightmap must be an AbstractHeightMap!");
}
this.customImageHeightmap = customImageHeightmap;
}*/
private HeightMap getHeightMapAt(Vector3f location) {
// HEIGHTMAP image (for the terrain heightmap)
int x = (int) location.x;
int z = (int) location.z;
AbstractHeightMap heightmap = null;
//BufferedImage im = null;
String name = null;
try {
name = namer.getName(x, z);
logger.log(Level.FINE, "Loading heightmap from file: {0}", name);
final Texture texture = assetManager.loadTexture(new TextureKey(name));
heightmap = new ImageBasedHeightMap(texture.getImage());
/*if (assetInfo != null){
InputStream in = assetInfo.openStream();
im = ImageIO.read(in);
} else {
im = new BufferedImage(patchSize, patchSize, imageType);
logger.log(Level.WARNING, "File: {0} not found, loading zero heightmap instead", name);
}*/
// CREATE HEIGHTMAP
/*if (imageType == BufferedImage.TYPE_USHORT_GRAY) {
heightmap = new Grayscale16BitHeightMap(im);
} else if (imageType == BufferedImage.TYPE_3BYTE_BGR) {
heightmap = new ImageBasedHeightMap(im);
} else if (customImageHeightmap != null && customImageHeightmap instanceof AbstractHeightMap) {
// If it gets here, it means you have specified a different image type, and you must
// then also supply a custom image heightmap class that can parse that image into
// a heightmap.
customImageHeightmap.setImage(im);
heightmap = (AbstractHeightMap) customImageHeightmap;
} else {
// error, no supported image format and no custom image heightmap specified
if (customImageHeightmap == null)
logger.log(Level.SEVERE, "Custom image type specified [{0}] but no customImageHeightmap declared! Use setCustomImageHeightmap()",imageType);
if (!(customImageHeightmap instanceof AbstractHeightMap))
logger.severe("customImageHeightmap must be an AbstractHeightMap!");
return null;
}*/
heightmap.setHeightScale(1);
heightmap.load();
//} catch (IOException e) {
// e.printStackTrace();
} catch (AssetNotFoundException e) {
logger.log(Level.WARNING, "Asset {0} not found, loading zero heightmap instead", name);
}
return heightmap;
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method updateTexImageData.
/**
* Uploads the given image to the GL driver.
*
* @param img The image to upload
* @param type How the data in the image argument should be interpreted.
* @param unit The texture slot to be used to upload the image, not important
* @param scaleToPot If true, the image will be scaled to power-of-2 dimensions
* before being uploaded.
*/
public void updateTexImageData(Image img, Texture.Type type, int unit, boolean scaleToPot) {
int texId = img.getId();
if (texId == -1) {
// create texture
gl.glGenTextures(intBuf1);
texId = intBuf1.get(0);
img.setId(texId);
objManager.registerObject(img);
statistics.onNewTexture();
}
// bind texture
int target = convertTextureType(type, img.getMultiSamples(), -1);
bindTextureAndUnit(target, img, unit);
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired()) {
if (!caps.contains(Caps.FrameBuffer) && gl2 != null) {
gl2.glTexParameteri(target, GL2.GL_GENERATE_MIPMAP, GL.GL_TRUE);
img.setMipmapsGenerated(true);
} else {
// For OpenGL3 and up.
// We'll generate mipmaps via glGenerateMipmapEXT (see below)
}
} else if (img.hasMipmaps()) {
// Image already has mipmaps, set the max level based on the
// number of mipmaps we have.
gl.glTexParameteri(target, GL.GL_TEXTURE_MAX_LEVEL, img.getMipMapSizes().length - 1);
} else {
// Image does not have mipmaps and they are not required.
// Specify that that the texture has no mipmaps.
gl.glTexParameteri(target, GL.GL_TEXTURE_MAX_LEVEL, 0);
}
int imageSamples = img.getMultiSamples();
if (imageSamples > 1) {
if (img.getFormat().isDepthFormat()) {
img.setMultiSamples(Math.min(limits.get(Limits.DepthTextureSamples), imageSamples));
} else {
img.setMultiSamples(Math.min(limits.get(Limits.ColorTextureSamples), imageSamples));
}
}
// Check if graphics card doesn't support multisample textures
if (!caps.contains(Caps.TextureMultisample)) {
if (img.getMultiSamples() > 1) {
throw new RendererException("Multisample textures are not supported by the video hardware");
}
}
// Check if graphics card doesn't support depth textures
if (img.getFormat().isDepthFormat() && !caps.contains(Caps.DepthTexture)) {
throw new RendererException("Depth textures are not supported by the video hardware");
}
if (target == GL.GL_TEXTURE_CUBE_MAP) {
// Check max texture size before upload
int cubeSize = limits.get(Limits.CubemapSize);
if (img.getWidth() > cubeSize || img.getHeight() > cubeSize) {
throw new RendererException("Cannot upload cubemap " + img + ". The maximum supported cubemap resolution is " + cubeSize);
}
if (img.getWidth() != img.getHeight()) {
throw new RendererException("Cubemaps must have square dimensions");
}
} else {
int texSize = limits.get(Limits.TextureSize);
if (img.getWidth() > texSize || img.getHeight() > texSize) {
throw new RendererException("Cannot upload texture " + img + ". The maximum supported texture resolution is " + texSize);
}
}
Image imageForUpload;
if (scaleToPot) {
imageForUpload = MipMapGenerator.resizeToPowerOf2(img);
} else {
imageForUpload = img;
}
if (target == GL.GL_TEXTURE_CUBE_MAP) {
List<ByteBuffer> data = imageForUpload.getData();
if (data.size() != 6) {
logger.log(Level.WARNING, "Invalid texture: {0}\n" + "Cubemap textures must contain 6 data units.", img);
return;
}
for (int i = 0; i < 6; i++) {
texUtil.uploadTexture(imageForUpload, GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, i, linearizeSrgbImages);
}
} else if (target == GLExt.GL_TEXTURE_2D_ARRAY_EXT) {
if (!caps.contains(Caps.TextureArray)) {
throw new RendererException("Texture arrays not supported by graphics hardware");
}
List<ByteBuffer> data = imageForUpload.getData();
// -1 index specifies prepare data for 2D Array
texUtil.uploadTexture(imageForUpload, target, -1, linearizeSrgbImages);
for (int i = 0; i < data.size(); i++) {
// upload each slice of 2D array in turn
// this time with the appropriate index
texUtil.uploadTexture(imageForUpload, target, i, linearizeSrgbImages);
}
} else {
texUtil.uploadTexture(imageForUpload, target, 0, linearizeSrgbImages);
}
if (img.getMultiSamples() != imageSamples) {
img.setMultiSamples(imageSamples);
}
if (caps.contains(Caps.FrameBuffer) || gl2 == null) {
if (!img.hasMipmaps() && img.isGeneratedMipmapsRequired() && img.getData(0) != null) {
glfbo.glGenerateMipmapEXT(target);
img.setMipmapsGenerated(true);
}
}
img.clearUpdateNeeded();
}
use of com.jme3.texture.Texture in project jmonkeyengine by jMonkeyEngine.
the class GLRenderer method setFrameBuffer.
public void setFrameBuffer(FrameBuffer fb) {
if (fb == null && mainFbOverride != null) {
fb = mainFbOverride;
}
if (context.boundFB == fb) {
if (fb == null || !fb.isUpdateNeeded()) {
return;
}
}
if (!caps.contains(Caps.FrameBuffer)) {
throw new RendererException("Framebuffer objects are not supported" + " by the video hardware");
}
// generate mipmaps for last FB if needed
if (context.boundFB != null) {
for (int i = 0; i < context.boundFB.getNumColorBuffers(); i++) {
RenderBuffer rb = context.boundFB.getColorBuffer(i);
Texture tex = rb.getTexture();
if (tex != null && tex.getMinFilter().usesMipMapLevels()) {
setTexture(0, rb.getTexture());
int textureType = convertTextureType(tex.getType(), tex.getImage().getMultiSamples(), rb.getFace());
glfbo.glGenerateMipmapEXT(textureType);
}
}
}
if (fb == null) {
bindFrameBuffer(null);
setReadDrawBuffers(null);
} else {
if (fb.isUpdateNeeded()) {
updateFrameBuffer(fb);
} else {
bindFrameBuffer(fb);
setReadDrawBuffers(fb);
}
// update viewport to reflect framebuffer's resolution
setViewPort(0, 0, fb.getWidth(), fb.getHeight());
assert fb.getId() > 0;
assert context.boundFBO == fb.getId();
context.boundFB = fb;
}
}
Aggregations