Java Code Examples for com.jogamp.opengl.util.texture.TextureIO#newTextureData()

The following examples show how to use com.jogamp.opengl.util.texture.TextureIO#newTextureData() . 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: 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 2
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 3
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 4
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 5
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);
        }
    }