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

The following examples show how to use com.jogamp.opengl.util.texture.TextureIO. 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: TextureEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
public void render(GL2 gl2) {
	if(textureDirty) {
		// texture has changed, load the new texture.
		if(t == null || t.length()==0) texture = null;
		else {
			try {
				texture = TextureIO.newTexture(FileAccess.open(t), false, t.substring(t.lastIndexOf('.')+1));
			} catch(IOException e) {
				//e.printStackTrace();
				Log.error("I can't load "+t);
			}
			textureDirty=false;
		}
	}
    if(texture==null) {
		gl2.glDisable(GL2.GL_TEXTURE_2D);
    } else {
		gl2.glEnable(GL2.GL_TEXTURE_2D);
    	texture.bind(gl2);
    }
}
 
Example #2
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 #3
Source File: HelloGlobe.java    From CPE552-Java with GNU General Public License v3.0 5 votes vote down vote up
private void initTexture(GL4 gl) {

        try {
            URL texture = getClass().getClassLoader().getResource("images/globe.png");

            TextureData textureData = TextureIO.newTextureData(gl.getGLProfile(), texture, false, TextureIO.PNG);

            gl.glCreateTextures(GL_TEXTURE_2D, 1, textureName);

            gl.glTextureParameteri(textureName.get(0), GL_TEXTURE_BASE_LEVEL, 0);
            gl.glTextureParameteri(textureName.get(0), GL_TEXTURE_MAX_LEVEL, 0);

            gl.glTextureStorage2D(textureName.get(0),
                    1, // level
                    textureData.getInternalFormat(),
                    textureData.getWidth(), textureData.getHeight());

            gl.glTextureSubImage2D(textureName.get(0),
                    0, // level
                    0, 0, // offset
                    textureData.getWidth(), textureData.getHeight(),
                    textureData.getPixelFormat(), textureData.getPixelType(),
                    textureData.getBuffer());

        } catch (IOException ex) {
            Logger.getLogger(HelloGlobe.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
Example #4
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 #5
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 #6
Source File: HelloGlobe.java    From hello-triangle with MIT License 5 votes vote down vote up
private void initTexture(GL4 gl) {

        try {
            URL texture = getClass().getClassLoader().getResource("images/globe.png");

            TextureData textureData = TextureIO.newTextureData(gl.getGLProfile(), texture, false, TextureIO.PNG);

            gl.glCreateTextures(GL_TEXTURE_2D, 1, textureName);

            gl.glTextureParameteri(textureName.get(0), GL_TEXTURE_BASE_LEVEL, 0);
            gl.glTextureParameteri(textureName.get(0), GL_TEXTURE_MAX_LEVEL, 0);

            gl.glTextureStorage2D(textureName.get(0),
                    1, // level
                    textureData.getInternalFormat(),
                    textureData.getWidth(), textureData.getHeight());

            gl.glTextureSubImage2D(textureName.get(0),
                    0, // level
                    0, 0, // offset
                    textureData.getWidth(), textureData.getHeight(),
                    textureData.getPixelFormat(), textureData.getPixelType(),
                    textureData.getBuffer());

        } catch (IOException ex) {
            Logger.getLogger(HelloGlobe.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
Example #7
Source File: HelloTexture.java    From hello-triangle with MIT License 5 votes vote down vote up
private void initTexture(GL3 gl) {

        try {
            URL texture = getClass().getClassLoader().getResource("images/door.png");

            /* Texture data is an object containing all the relevant information about texture.    */
            TextureData data = TextureIO.newTextureData(gl.getGLProfile(), texture, false, TextureIO.PNG);

            int level = 0;

            gl.glGenTextures(1, textureName);

            gl.glBindTexture(GL_TEXTURE_2D, textureName.get(0));
            {
                gl.glTexImage2D(GL_TEXTURE_2D,
                        level,
                        data.getInternalFormat(),
                        data.getWidth(), data.getHeight(),
                        data.getBorder(),
                        data.getPixelFormat(), data.getPixelType(),
                        data.getBuffer());

                gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
                gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, level);

                IntBuffer swizzle = GLBuffers.newDirectIntBuffer(new int[]{GL_RED, GL_GREEN, GL_BLUE, GL_ONE});
                gl.glTexParameterIiv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle);

                destroyBuffer(swizzle);
            }
            gl.glBindTexture(GL_TEXTURE_2D, 0);

        } catch (IOException ex) {
            Logger.getLogger(HelloTextureK.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
 
Example #8
Source File: TextureShape.java    From MeteoInfo with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Load texture from file
 * @throws IOException 
 */
public void loadTexture() throws IOException {
    this.texture = TextureIO.newTexture(new File(fileName), true);
}