Login  Register

Re: Texture NPOT

Posted by paolofuse on Sep 14, 2015; 9:20am
URL: https://forum.jogamp.org/Texture-NPOT-tp4035280p4035289.html

This is my simple full code:

private Texture texture;
private int textureID;

public void init(GLAutoDrawable drawable)
{
     try
    {
           texture = TextureIO.newTexture(new File(filename), true);

//           TextureData textureData = TextureIO.newTextureData(gl.getGLProfile(), new File(filename), false, null);
//           IntBuffer buffer = IntBuffer.allocate(1);
//           gl.glGenTextures(1, buffer);
//           textureID = buffer.get(0);
//           gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID);
//           gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
//           gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);
//           gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, textureData.getPixelFormat(), textureData.getWidth(), textureData.getHeight(), 0, GL2.GL_RGBA, textureData.getPixelType(), textureData.getBuffer());
//           gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);
    }
    catch (Exception e)
    {
          e.printStackTrace();
     }
}

public void display(GLAutoDrawable drawable)
{
    GL2 gl = drawable.getGL().getGL2();
    gl.glClearColor(0f, 0f, 0f, 1f);
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

    texture.enable(gl);
    texture.bind(gl);
    texture.setTexParameteri(gl, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_LINEAR);
    texture.setTexParameteri(gl, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_LINEAR);

//    gl.glEnable(GL2.GL_TEXTURE_2D);
//    gl.glBindTexture(GL2.GL_TEXTURE_2D, textureID);

    gl.glBegin(GL2.GL_QUADS);
    gl.glTexCoord2d(0, 0);
    gl.glVertex2d(0, 0);
    gl.glTexCoord2d(1, 0);
    gl.glVertex2d(texture.getWidth(), 0);
    gl.glTexCoord2d(1, 1);
    gl.glVertex2d(texture.getWidth(), texture.getHeight());
    gl.glTexCoord2d(0, 1);
    gl.glVertex2d(0, texture.getHeight());
    gl.glEnd();

// gl.glBindTexture(GL2.GL_TEXTURE_2D, 0);

    texture.disable(gl);
}

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
{
    GL2 gl = drawable.getGL().getGL2();
    gl.glMatrixMode(GL2.GL_PROJECTION );
    gl.glLoadIdentity();
    gl.glOrtho(0, width, 0, height, -1, 1);
    gl.glMatrixMode(GL2.GL_MODELVIEW );
    gl.glLoadIdentity();
}

public void dispose(GLAutoDrawable drawable)
{
}


Don't care if this code is deprecated, I know, but it must work. The commented code works, as wrote before.
Thanks