Problem with JUnit and TextureIO

Hi,

We are using JOGL now for a while and are very satisfied with it. Thanks for the great job :slight_smile:

Now I have a problem with JUnit. I have a test method like this:

@Test public void getImageTexture()
  {
    GL gl = OpenGLCaps.createGL();
    //...
    TextureIO.newTexture(...);
    //...
  }

The line with the TextureIO throws an Exception:

[quote]javax.media.opengl.GLException: No OpenGL context current on this thread
at javax.media.opengl.glu.GLU.getCurrentGL(GLU.java:234)
at com.sun.opengl.util.texture.Texture.(Texture.java:146)
at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:440)
at com.sun.opengl.util.texture.TextureIO.newTexture(TextureIO.java:489)
at com.xenoage.score.app.opengl.ManagedTexture.load(ManagedTexture.java:59)
[…]
[/quote]
I can understand why it happens, but I do not understand how I can solve the problem. Is there any way?
createGL() gives me a valid GL object, since other simple tests work with it (e.g. get maximum texture size).

Thanks :slight_smile:

Maybe you could run the test-suite out of the GLEventListener.display()-Method or something? This would ensure, the context is current on the thread.

You need a GLContext, and call its makeCurrent() method. I reckon you should be able to create a context through GLDrawableFactory() (either associated with a window, or a pbuffer).

As Saxer says it might be easier to use the event listener approach, although the above approach (immediate mode?) might be better suited for unit testing.

Thanks for the quick responses :slight_smile: The createGL() method looks like this:

static GL createGL()
  {
    GLDrawableFactory f = GLDrawableFactory.getFactory();
    if (f.canCreateGLPbuffer())
    {
      try
      {
        pbuffer = f.createGLPbuffer(new GLCapabilities(),
          null, 1, 1, null);
        pbuffer.display();
        if (pbuffer.getContext().makeCurrent() != GLContext.CONTEXT_NOT_CURRENT)
          return pbuffer.getGL();
      }
      catch (Exception ex)
      {
        ex.printStackTrace();
      }
    }
    return null;
  }

Unfortunately I get the exception

[quote]javax.media.opengl.GLException: javax.media.opengl.GLException: pbuffer creation error: glXCreatePbuffer() failed
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:271)
at com.sun.opengl.impl.x11.X11GLDrawableFactory.maybeDoSingleThreadedWorkaround(X11GLDrawableFactory.java:668)
at com.sun.opengl.impl.x11.X11GLDrawableFactory.createGLPbuffer(X11GLDrawableFactory.java:327)
at com.xenoage.score.app.opengl.OpenGLCaps.createGL(OpenGLCaps.java:97)
at com.xenoage.score.app.opengl.TextureManagerTest.getImageTexture(TextureManagerTest.java:31)
[…]
[/quote]
Am I using bad parameters or is my video card not able to create pbuffers? I have a ATI Mobility Radeon 9700 and Linux is running:

[quote]andi@andi-laptop:~$ fglrxinfo
display: :0.0 screen: 0
OpenGL vendor string: ATI Technologies Inc.
OpenGL renderer string: MOBILITY RADEON 9700
OpenGL version string: 2.0.6334 (8.34.8)
[/quote]
With the FireGL-drivers deactivated, using the default ATI drivers supplied with Ubuntu 7.04:

[quote]javax.media.opengl.GLException: javax.media.opengl.GLException: pbuffer creation error: glXChooseFBConfig() failed
at javax.media.opengl.Threading.invokeOnOpenGLThread(Threading.java:271)
at com.sun.opengl.impl.x11.X11GLDrawableFactory.maybeDoSingleThreadedWorkaround(X11GLDrawableFactory.java:668)
at com.sun.opengl.impl.x11.X11GLDrawableFactory.createGLPbuffer(X11GLDrawableFactory.java:327)
at com.xenoage.score.app.opengl.OpenGLCaps.createGL(OpenGLCaps.java:97)
at com.xenoage.score.app.opengl.TextureManagerTest.getImageTexture(TextureManagerTest.java:31)
[/quote]
My fault or driver’s fault?

Please, can anybody tell me if this parameters are correct?

f.createGLPbuffer(new GLCapabilities(), null, 1, 1, null);

If they are ok, then I know that my video card is not able to create offscreen pbuffers. Thanks :slight_smile:

I just made a test using TestNG (should translate well to JUnit), this works here :

@BeforeTest
public void setUp() {
	GLPbuffer pbuffer = GLDrawableFactory.getFactory().createGLPbuffer(
			new GLCapabilities(), new DefaultGLCapabilitiesChooser(), 256, 256, null);
	
	pbuffer.getContext().makeCurrent();
}
	
@Test
public void testMethod()
{
	GL gl = GLContext.getCurrent().getGL();
	// ...
}

Try putting a power-of-two dimension for your pbuffer, I wouldn’t be surprised to see that this is the problem.