glcanvas texture lost, how to bind it again?

i have a swing app with a glcanvas on top with two textures.
one is created with TextureRenderer, the other using glGenTextures+glTexImage2D+glBindTexture

after i lose context on the canvas i lose both textures. the texture with TextureRenderer can be easily be
restored by creating a new TextureRenderer instance and redrawing on it. not optimal, but it works.

however, the “manual” texture using glGenTextures, i cannot get to work anymore after context was lost once.
calling the init method again is to no avail, i also tried deleting the last texture using glDeleteTextures().
can any tell me how i can recreate a texture when the previous texture got “lost”, and do i need to cleanup the old texture manually?

code, which works until i lose jogl context once in my application


  private int texture_id=-1;
  public void init(GLU glu, GL gl) {
    texture_id = genTexture(gl);
    updateTexture(glu, gl);
//create data buffer
    gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, wd, ht, 0, GL.GL_BGRA, GL.GL_UNSIGNED_BYTE, buffer);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
  }

  private int genTexture(GL gl) {
    int[] tmp = new int[1];
    gl.glGenTextures(1, tmp, 0);
    return tmp[0];
  }

  public void draw(GLU glu, GL gl) {
    gl.glEnable( GL.GL_TEXTURE_2D );
    gl.glBindTexture(GL.GL_TEXTURE_2D, texture_id);
    gl.glBegin(gl.GL_QUADS);
    gl.glTexCoord2f(0.0f, 0.0f);
    gl.glVertex3f(0,  ht, 0f);
    gl.glTexCoord2f(1.0f, 0.0f);
    gl.glVertex3f(wd,  ht, 0f);
    gl.glTexCoord2f(1.0f, 1.0f);
    gl.glVertex3f(wd, 0, 0f);
    gl.glTexCoord2f(0.0f, 1.0f);
    gl.glVertex3f(0, 0, 0f);
    gl.glEnd();
    gl.glDisable( GL.GL_TEXTURE_2D );
  }


the code above is ok, i actually called glTexSubImage2D everytime after the first texture creation, so the textures weren’t really recreated