JOGL中的.bmp纹理问题

时间:2018-01-24 05:02:07

标签: image textures jogl bmp

我尝试使用JOGL为纹理设置3个滤镜。

        File txtr = new File( "Glass_jpeg.jpg" );
        Texture t = TextureIO.newTexture( txtr, true );
        texture = t.getTextureObject();
        //TextureData txData = AWTTextureIO.newTextureData( gl.getGLProfile(), ImageIO.read( txtr ), true );
        TextureData txData = TextureIO.newTextureData( gl.getGLProfile(), txtr, true, null );

        gl.glGenTextures( 3, textures );

        gl.glBindTexture( GL2.GL_TEXTURE_2D, textures.get( 0 ) );
        gl.glTexParameteri( GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST );
        gl.glTexParameteri( GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST );
        gl.glTexImage2D( GL2.GL_TEXTURE_2D, 0, 3, t.getWidth(),  t.getWidth(), 0,
                GL2.GL_RGB, GL2.GL_UNSIGNED_BYTE, txData.getBuffer() );

        gl.glBindTexture( GL2.GL_TEXTURE_2D, textures.get( 1 ) );
        gl.glTexParameteri( GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR );
        gl.glTexParameteri( GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR );
        gl.glTexImage2D( GL2.GL_TEXTURE_2D, 0, 3, t.getWidth(), t.getHeight(), 0,
                GL2.GL_RGB, GL2.GL_UNSIGNED_BYTE, txData.getBuffer() );

        gl.glBindTexture( GL2.GL_TEXTURE_2D, textures.get( 2 ) );
        gl.glTexParameteri( GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR );
        gl.glTexParameteri( GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR_MIPMAP_NEAREST );
        GLU glu = GLU.createGLU( gl );
        glu.gluBuild2DMipmaps( GL2.GL_TEXTURE_2D, 3, t.getWidth(), t.getHeight(), GL2.GL_RGB,
                GL2.GL_UNSIGNED_BYTE, txData.getBuffer() );

问题是我的代码只有在我使用TextureIO类并且我的图像格式为.jpg时才能正常工作。当我尝试使用AWTTextureIO和/或16,24,256 .bmp格式时,纹理翻转并且纹理的颜色从红色变为蓝色。解释是否可以在JOGl中正确使用.bmp格式?

0 个答案:

没有答案