Login  Register

Re: Texture Problem (probably gl.glTexImage2D)

Posted by PedDavid on Jun 02, 2015; 6:18pm
URL: https://forum.jogamp.org/Texture-Problem-probably-gl-glTexImage2D-tp4034564p4034588.html

Just tested it, I don't need to use BGR that way what is actually nice. If it helps cross platform and image support even better. Although I just wrapped the method and it seems to take quite a lot more time to process:

        textures = new int[1];
        gl.glGenTextures(1, textures, 0);
        textureID = textures[0];
        gl.glBindTexture(GL_TEXTURE_2D, textures[0]);
        try {
            long start = System.nanoTime();
            //BufferedImage image = ImageIO.read(getClass().getClassLoader().getResource(textureFileName));
            TextureData image = TextureIO.newTextureData(getGLProfile(), getClass().getClassLoader().getResource(textureFileName)
                    , false, null);
            //DataBufferByte dbb = (DataBufferByte)image.getRaster().getDataBuffer();
            //byte[] data = dbb.getData();
            //ByteBuffer pixels = ByteBuffer.wrap(data);
            gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, image.getWidth(), image.getHeight(),
                    0, GL_BGR, GL_UNSIGNED_BYTE, image.getBuffer());
            gl.glBindTexture(GL_TEXTURE_2D, 0);
            long time = System.nanoTime() - start;
            System.out.println("Average time was " + time);
        } catch(Throwable t) {
            t.printStackTrace();
        }

*the comments are from the previous version with ImageIO

ImageIO timings: Time~=30 000 000
TextureData timings: Time~=60 000 000
Texture (TextureIO.newTexture) timings: Time~=52 000 000

Edit: Tried that getTextureObject() method

        try {
            texture = TextureIO.newTexture(
                    getClass().getClassLoader().getResource(textureFileName), // relative to project root
                    false, textureFileType);
            gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            gl.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            textureID = texture.getTextureObject(gl);
        } catch (GLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

I only noticed that I didn't even bind a texture before creating this one and it's all working so I guess it isn't needed?

Edit2: Well, just noticed the second method (TextureData) is displaying upside down... Just tried pass extension as ".png" isntead of null and the image is now in the correct orientation, but it is in BGR again...