com.jogamp.opengl.util.texture.Texture Java Examples

The following examples show how to use com.jogamp.opengl.util.texture.Texture. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CubeTexture.java    From MeteoInfo with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void init(GLAutoDrawable drawable) {
    final GL2 gl = drawable.getGL().getGL2();
    gl.glShadeModel(GL2.GL_SMOOTH);
    gl.glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    gl.glClearDepth(1.0f);
    gl.glEnable(GL2.GL_DEPTH_TEST);
    gl.glDepthFunc(GL2.GL_LEQUAL);
    gl.glHint(GL2.GL_PERSPECTIVE_CORRECTION_HINT, GL2.GL_NICEST);
    gl.glEnable(GL2.GL_TEXTURE_2D);
    
    try {
        File im = new File("D:\\Temp\\image\\lenna.jpg ");
        //File im = new File("D:\\Temp\\Map\\GLOBALeb3colshade.jpg");
        BufferedImage image = ImageIO.read(im);
        Texture t = AWTTextureIO.newTexture(gl.getGLProfile(), image, true);
        //Texture t = TextureIO.newTexture(im, true);
        texture = t.getTextureObject(gl);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
Example #2
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Texture getTexture(final File file, final boolean isAnimated, final boolean useCache) {
	if (file == null) { return null; }
	Texture texture = null;
	if (isAnimated || !useCache) {
		final BufferedImage image = ImageUtils.getInstance().getImageFromFile(file, useCache, true);
		texture = volatileTextures.getUnchecked(image);

	} else {
		try {
			texture = staticTextures.get(file.getAbsolutePath(), () -> {
				// DEBUG.OUT("Loading static texture : " + file.getName());
				return buildTexture(gl.getGL(), file);
			});
		} catch (final ExecutionException e) {
			e.printStackTrace();
		}
	}
	return texture;
}
 
Example #3
Source File: Plot3DGL.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void drawImage(GL2 gl, Graphic graphic) {
    ImageShape ishape = (ImageShape) graphic.getShape();
    BufferedImage image = ishape.getImage();
    Texture texture = AWTTextureIO.newTexture(gl.getGLProfile(), image, true);
    //Texture texture = this.imageCache.get(image);
    int idTexture = texture.getTextureObject();
    List<PointZ> coords = ishape.getCoords();

    gl.glColor3f(1f, 1f, 1f);
    gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture);

    // Texture parameterization
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);

    // Draw image
    gl.glBegin(GL2.GL_QUADS);
    // Front Face
    //gl.glTexCoord2f(0.0f, 0.0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(transform_xf((float) coords.get(0).X), transform_yf((float) coords.get(0).Y), transform_zf((float) coords.get(0).Z));
    //gl.glTexCoord2f(1.0f, 0.0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(transform_xf((float) coords.get(1).X), transform_yf((float) coords.get(1).Y), transform_zf((float) coords.get(1).Z));
    //gl.glTexCoord2f(1.0f, 1.0f);
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(transform_xf((float) coords.get(2).X), transform_yf((float) coords.get(2).Y), transform_zf((float) coords.get(2).Z));
    //gl.glTexCoord2f(0.0f, 1.0f);
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(transform_xf((float) coords.get(3).X), transform_yf((float) coords.get(3).Y), transform_zf((float) coords.get(3).Z));
    gl.glEnd();

    // Unbinding the texture
    gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
}
 
Example #4
Source File: Plot3DGL.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void drawImage(GL2 gl) throws IOException {
        File im = new File("D:\\Temp\\image\\lenna.jpg ");
        BufferedImage image = ImageIO.read(im);
        Texture t = AWTTextureIO.newTexture(gl.getGLProfile(), image, true);
        //Texture t = TextureIO.newTexture(im, true);
        //Texture t = this.imageCache.get(image);
        int idTexture = t.getTextureObject(gl);

        gl.glColor3f(1f, 1f, 1f);
        gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture);

//        // Texture parameterization
//        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR);
//        gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
        // Draw image
        gl.glBegin(GL2.GL_QUADS);
        // Front Face
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(-1.0f, -1.0f, 1.0f);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(1.0f, -1.0f, 1.0f);
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(1.0f, 1.0f, 1.0f);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(-1.0f, 1.0f, 1.0f);
        gl.glEnd();

        // Unbinding the texture
        gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
    }
 
Example #5
Source File: GLTools.java    From constellation with Apache License 2.0 5 votes vote down vote up
public static Texture loadTexture(final GL3 gl, final InputStream in, final String ext, final int minFilter, final int magFilter, final int wrapMode) throws IOException {
        // NVS-415: Appears to be a bug in JOGL where texture provider for PNG files does not flip the texture.
//         final TextureData data = TextureIO.newTextureData(gl.getGLProfile(), in, false, ext);
        final TextureData data = TextureIO.newTextureData(gl.getGLProfile(), in, false, null);
        final Texture tex = TextureIO.newTexture(data);

        gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_WRAP_S, wrapMode);
        gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_WRAP_T, wrapMode);

        gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_MIN_FILTER, minFilter);
        gl.glTexParameteri(GL3.GL_TEXTURE_2D, GL3.GL_TEXTURE_MAG_FILTER, magFilter);

        return tex;
    }
 
Example #6
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
Texture buildTexture(final GL gl, final BufferedImage im) {
	try {
		final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), im, true);
		final Texture texture = new Texture(gl, data);
		data.flush();
		return texture;
	} catch (final GLException e) {
		e.printStackTrace();
		return null;
	}
}
 
Example #7
Source File: JOGLRenderer.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
@Deprecated
	static Texture importTexture(final GL gl, final String string) throws IOException {
		final FileInputStream f = new FileInputStream("test.png");
		final TextureData tx_dat = TextureIO.newTextureData(gl.getGLProfile(), f, false, TextureIO.PNG);
		final Texture tex = new Texture(gl, tx_dat);
		tex.setTexParameteri(gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
		tex.setTexParameteri(gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
//		tex.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
//		tex.setTexParameteri(gl, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
		return tex;
	}
 
Example #8
Source File: JOGLRenderer.java    From WarpPI with Apache License 2.0 5 votes vote down vote up
static Texture importTexture(File f, final boolean deleteOnExit) throws GLException, IOException {
	final Texture tex = TextureIO.newTexture(f, false);
	if (deleteOnExit && f.exists())
		try {
			if (WarpPI.getPlatform().getSettings().isDebugEnabled())
				throw new IOException("Delete on exit!");
			f.delete();
		} catch (final Exception ex) {
			f.deleteOnExit();
		}
	tex.setTexParameteri(JOGLRenderer.gl, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
	tex.setTexParameteri(JOGLRenderer.gl, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
	f = null;
	return tex;
}
 
Example #9
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
private Texture buildTexture(final GL gl, final File file) {

		return buildTexture(gl, ImageUtils.getInstance().getImageFromFile(file, true, true));

		// try {
		// final TextureData data = AWTTextureIO.newTextureData(gl.getGLProfile(), file, true, null);
		// final Texture texture = new Texture(gl, data);
		// data.flush();
		// return texture;
		// } catch (final GLException | IOException e) {
		// e.printStackTrace();
		// return null;
		// }
	}
 
Example #10
Source File: DrawingPlugin.java    From depan with Apache License 2.0 5 votes vote down vote up
/**
 * Render a texture to the given position.
 *
 * @param texture Texture to draw
 * @param centerX X coordinate for the center of the texture
 * @param centerY Y coordinate for the center of the texture
 */
private void renderTexture(Texture texture, double centerX, double centerY) {
  TextureCoords tc = texture.getImageTexCoords();
  float tx1 = tc.left();
  float ty1 = tc.top();
  float tx2 = tc.right();
  float ty2 = tc.bottom();
  float halfWidth = quarterValue(texture.getWidth());
  float halfHeight = quarterValue(texture.getHeight());

  GL2 gl = scene.gl;
  texture.bind(gl);
  texture.enable(gl);

  Color foreground = scene.getForegroundColor();
  gl.glColor4f(foreground.getRed() / 255f,
      foreground.getGreen() / 255f,
      foreground.getBlue() / 255f,
      foreground.getAlpha() / 255f);

  gl.glPushMatrix();
  float[] translate = GLScene.P((float) centerX, (float) centerY);
  gl.glTranslatef(translate[0], translate[1], translate[2]);
  gl.glBegin(GL2.GL_QUADS);
  // divided by 2 to get nicer textures
  // divided by 4 when we center it : 1/2 on each side of x axis for instance.
  gl.glTexCoord2f(tx1, ty1);
  GLScene.V(gl, -halfWidth, halfHeight);
  gl.glTexCoord2f(tx2, ty1);
  GLScene.V(gl, halfWidth,  halfHeight);
  gl.glTexCoord2f(tx2, ty2);
  GLScene.V(gl, halfWidth, -halfHeight);
  gl.glTexCoord2f(tx1, ty2);
  GLScene.V(gl, -halfWidth, -halfHeight);
  gl.glEnd();
  gl.glPopMatrix();

  texture.disable(gl);
}
 
Example #11
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public TextureCache2(final OpenGL gl) {
	this.gl = gl;
	volatileTextures = CacheBuilder.newBuilder().build(new CacheLoader<BufferedImage, Texture>() {

		@Override
		public Texture load(final BufferedImage key) throws Exception {
			return buildTexture(gl.getGL(), key);
		}
	});
}
 
Example #12
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void deleteVolatileTextures() {
	final Collection<Texture> textures = volatileTextures.asMap().values();
	for (final Texture t : textures) {
		t.destroy(gl.getGL());
	}
	volatileTextures.invalidateAll();
}
 
Example #13
Source File: OpenGL.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public Texture getTexture(final File file, final boolean isAnimated, final boolean useCache) {
	return textureCache.getTexture(file, isAnimated, useCache);
}
 
Example #14
Source File: OpenGL.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public int getTextureId(final BufferedImage img) {
	final Texture r = textureCache.getTexture(img);
	if (r == null) { return NO_TEXTURE; }
	return r.getTextureObject();
}
 
Example #15
Source File: OpenGL.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public int getTextureId(final GamaImageFile file, final boolean useCache) {
	final Texture r = textureCache.getTexture(file.getFile(null), file.isAnimated(), useCache);
	if (r == null) { return NO_TEXTURE; }
	return r.getTextureObject();
}
 
Example #16
Source File: TextureCache2.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Texture getTexture(final BufferedImage img) {
	return volatileTextures.getUnchecked(img);
}
 
Example #17
Source File: GLEventListenerButton.java    From jogl-samples with MIT License 4 votes vote down vote up
@Override
public void drawShape(final GL2ES2 gl, final RegionRenderer renderer, final int[] sampleCount) {
    if( null == fboGLAD ) {
        final ImageSequence imgSeq = (ImageSequence)texSeq;

        final GLContext ctx = gl.getContext();
        final GLDrawable drawable = ctx.getGLDrawable();
        final GLCapabilitiesImmutable reqCaps = drawable.getRequestedGLCapabilities();
        final GLCapabilities caps = (GLCapabilities) reqCaps.cloneMutable();
        caps.setFBO(true);
        caps.setDoubleBuffered(false);
        if( !useAlpha ) {
            caps.setAlphaBits(0);
        }
        final GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());

        fboGLAD = (GLOffscreenAutoDrawable.FBO) factory.createOffscreenAutoDrawable(
                        drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(),
                        caps, null, fboWidth, fboHeight);
        fboWidth = 0;
        fboHeight = 0;
        fboGLAD.setSharedContext(ctx);
        fboGLAD.setTextureUnit(imgSeq.getTextureUnit());
        fboGLAD.addGLEventListener(glel);
        fboGLAD.display(); // 1st init!

        final FBObject.TextureAttachment texA01 = fboGLAD.getColorbuffer(GL.GL_FRONT).getTextureAttachment();
        final Texture tex = new Texture(texA01.getName(), imgSeq.getTextureTarget(),
                                fboGLAD.getSurfaceWidth(), fboGLAD.getSurfaceHeight(), fboGLAD.getSurfaceWidth(), fboGLAD.getSurfaceHeight(),
                                false /* mustFlipVertically */);
        imgSeq.addFrame(gl, tex);
        markStateDirty();
    } else if( 0 != fboWidth*fboHeight ) {
        fboGLAD.setSurfaceSize(fboWidth, fboHeight);
        fboWidth = 0;
        fboHeight = 0;
        markStateDirty();
    } else if( animateGLEL ) {
        fboGLAD.display();
    }

    super.drawShape(gl, renderer, sampleCount);

    if( animateGLEL ) {
        markStateDirty(); // keep on going
    }
}
 
Example #18
Source File: JOGLEngine.java    From WarpPI with Apache License 2.0 4 votes vote down vote up
public void registerTexture(final Texture t) {
	unregisteredTextures.addLast(t);
}
 
Example #19
Source File: JOGLRenderer.java    From WarpPI with Apache License 2.0 4 votes vote down vote up
void useTexture(final Texture t, final float w, final float h) {
	currentTex = t;
	currentTexWidth = w;
	currentTexHeight = h;
	enableTexture();
}
 
Example #20
Source File: TextureShape.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Constructor
 * @param texture Texture
 */
public TextureShape(Texture texture) {
    super();
    this.texture = texture;
}
 
Example #21
Source File: Plot3DGL.java    From MeteoInfo with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void drawTexture(GL2 gl, Graphic graphic) {
    TextureShape ishape = (TextureShape) graphic.getShape();
    Texture texture = ishape.getTexture();
    if (texture == null) {
        try {
            ishape.loadTexture();
            texture = ishape.getTexture();
        } catch (IOException ex) {
            Logger.getLogger(Plot3DGL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    if (texture == null) {
        return;
    }

    int idTexture = texture.getTextureObject();
    List<PointZ> coords = ishape.getCoords();

    gl.glColor3f(1f, 1f, 1f);
    gl.glBindTexture(GL2.GL_TEXTURE_2D, idTexture);

    // Texture parameterization
    //gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_LINEAR);
    gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);

    // Draw image
    gl.glBegin(GL2.GL_QUADS);
    // Front Face
    gl.glTexCoord2f(0.0f, 0.0f);
    //gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(transform_xf((float) coords.get(0).X), transform_yf((float) coords.get(0).Y), transform_zf((float) coords.get(0).Z));
    gl.glTexCoord2f(1.0f, 0.0f);
    //gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(transform_xf((float) coords.get(1).X), transform_yf((float) coords.get(1).Y), transform_zf((float) coords.get(1).Z));
    gl.glTexCoord2f(1.0f, 1.0f);
    //gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(transform_xf((float) coords.get(2).X), transform_yf((float) coords.get(2).Y), transform_zf((float) coords.get(2).Z));
    gl.glTexCoord2f(0.0f, 1.0f);
    //gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(transform_xf((float) coords.get(3).X), transform_yf((float) coords.get(3).Y), transform_zf((float) coords.get(3).Z));
    gl.glEnd();

    // Unbinding the texture
    gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
}
 
Example #22
Source File: TextureShape.java    From MeteoInfo with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Set texture
 * @param value Texture 
 */
public void setTexture(Texture value) {
    this.texture = value;
}
 
Example #23
Source File: TextureShape.java    From MeteoInfo with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Get texture
 * @return Texture
 */
public Texture getTexture() {
    return this.texture;
}
 
Example #24
Source File: ITextureCache.java    From gama with GNU General Public License v3.0 votes vote down vote up
Texture getTexture(BufferedImage img); 
Example #25
Source File: ITextureCache.java    From gama with GNU General Public License v3.0 votes vote down vote up
Texture getTexture(File file, boolean isAnimated, boolean useCache);