textures don't work with reshape()

Hey,

I have a problem that whenever the “reshape” method is called on my GLJPanel. I know for sure it’s when reshape is called since I put a print statement in that method (not to mention i can actually watch the JPanel being reshaped…)

Any textures I have on the screen will instantly disappear, leaving just white space (the clear color) on the screen where they were (making some lines look like I have GL_LINE_STIPPLE activated, actually). I can then have them drawn again (by pushing the button that originally drew them to the screen) but even in this case some of the textures aren’t redrawn, and, nonetheless, when I reshape again it deletes them all anyway. This is really messy and quite the disaster, as the functionality that causes the re-shaping of the GLJpanel is absolutely essential to the program I’m writing.

Is there any reason why reshape() would be unbinding textures, not letting them be redrawn properly, etc…?

Thank you very much!

The GLJPanel works differently from the GLCanvas in that every resize operation basically implies that the underlying OpenGL context is destroyed, since it is usually implemented with a pbuffer and pbuffers can’t be resized. This is why your textures are disappearing.

You could work around this in at least two ways. One would be to restructure your code to reload your textures in your init() method. This is the most correct fix. However, you could also make a small (e.g., 2x2) GLPbuffer yourself and have your GLJPanel share textures and display lists with it. Your GLPbuffer would keep your texture objects alive across re-creations of the GLJPanel’s underlying OpenGL context. Your application would then have to know that when both the GLJPanel and your GLPbuffer are destroyed that the textures would have to be reloaded if another GLJPanel is created.

since my textures are created dynamically I think I’ll have to go with the second option

time to learn to use a pbuffer!!

thanks :slight_smile:

the examples seem to use pbuffers to do the displaying rather than sharing information with some other GLAutoDrawable. Is there a line of code that links the two and allows them to share resources?

Something like


  GLPbuffer sharingPbuffer = GLDrawableFactory.getFactory().createGLPbuffer(new GLCapabilities(), null, 2, 2, null);
  GLJPanel myPanel = new GLJPanel(null, null, sharingPbuffer);

Note that the pbuffer’s context is fed in to the GLJPanel rather than vice versa. The GLJPanel needs to know about the other GLContext so when it repeatedly recreates its internal context it keeps re-setting up sharing appropriately.

That doesn’t work, it requires a GLContext to that constructor of glJPanel, and unless I really missed something with looking through the API, GLPbuffer isn’t one of those. I’ll try it with sharingPbuffer.getContext() instead.

Making that change got it to compile, but the textures still disappear whenever reshape() is called. I had to do things slightly differently since i’m not explicity creating the GLJPanel, I’m using classes which inherit from GLJPanel, so I had to create the PBuffer in a static method and then pass it to the constructor. But other than that little detail the code is essentially the same thing you just posted right above.

Do I have to include any other references to the pbuffer at all, like when creating the textures and stuff? Or should that just be done automatically.

I think it should just work automatically. What version of JOGL are you using? What is the output of java -Djogl.verbose demos.printext.PrintExt?

Could you try the current nightly build on the JOGL web page if you aren’t using a recent version? A lot of issues with the GLJPanel and GLPbuffers have been fixed since the last “official” 1.1.1 build.

well i get an exception when I try to run that JOGL build command. But i downloaded the most recent version yesterday (thinking that might have been the problem) and there was no change.

here’s some code, in case there’s anything in it to indicate what i might’ve left out:



public PlotPanel() { 
	
	    super(sharingPBuffer);
		this.addGLEventListener(this);
		
	} //PlotPanel()
	
	public static void createPBuffer() {
	
		sharingPBuffer = GLDrawableFactory.getFactory().createGLPbuffer(caps,null,2, 2, null);
		
	} // createPBuffer()


PlotPanel extends the following class:



public GraphicsComponent(GLPbuffer pbuffer) {
	
		super(caps, null, pbuffer.getContext());
		
	}

public static void setUpCapabilities() {
	
		System.out.println("Set up capabilities");
		caps = new GLCapabilities();
		caps.setHardwareAccelerated(true);
		caps.setDoubleBuffered(true);
		
	}


I really can’t make a guess without a small and self-contained test case. Could you try to write one?