Context creation failed on MacBook Pro

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Context creation failed on MacBook Pro

pjcozzi
Hi,

Can anyone spot anything wrong with the following code?  It works on several flavors of Windows but fails on a MacBook Pro:  gl (the last line) is null.

public class OpenGLReport extends JApplet {
  public void init() {
    GLProfile profile = GLProfile.get(new String[] { GLProfile.GL4bc, GLProfile.GL3bc, GLProfile.GL2 });
    GLCapabilities capabilities = new GLCapabilities(profile);
    GLCanvas canvas = new GLCanvas(capabilities);
    add(canvas);
    GLContext context = canvas.getContext();
    context.makeCurrent();
    GL gl = canvas.getGL();

This is in an applet that doesn't need to draw anything; it just needs to query OpenGL information.  I am using the signed jars hosted here:

   http://download.java.net/media/jogl/jsr-231-2.x-webstart

The MacBook has two video cards:  a NVIDIA GeForce GT 330M and an Intel one.  The NVIDIA card was active at the time.

Perhaps I am creating the context incorrectly?

Regards,
Patrick
Reply | Threaded
Open this post in threaded view
|

Re: Context creation failed on MacBook Pro

gouessej
Administrator
Hi!

You call getContext() too early. Rather use a GLEventListener and perform your calls in the method display(GLAutoDrawable) or even in init(GLAutoDrawable).
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: Context creation failed on MacBook Pro

pjcozzi
Thanks for the suggestion.  I can believe I am creating the context wrong because sometimes the applet comes up black on Windows, and a browser refresh is required.  Perhaps it is a timing issue.

Given your suggestion, I've changed my code to the following:

  public class OpenGLReport extends JApplet implements GLEventListener  {

  public void init() {
    GLProfile profile = GLProfile.get(new String[] { /* ... */ });
    GLCapabilities capabilities = new GLCapabilities(profile);
    GLCanvas canvas = new GLCanvas(capabilities);
    add(canvas);
    canvas.addGLEventListener(this);

    Animator animator = new Animator(canvas);
    animator.start();
  }

  @Override
  public void init(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();
    String[] extensions = gl.glGetString(GL.GL_EXTENSIONS).split(" ");
    // ...

This works in Eclipse on Windows, but fails with a null reference exception in JOGL on Mac:

  java.lang.NullPointerException
    at com.jogamp.opengl.impl.gl4.GL4bcImpl.glGetString(GL4bcImpl.java:10315)

Also, it appears that I need to create the animator for init(GLAutoDrawable) to get called, but this class is not in the old signed jars for web applets.  Is there another way to do this?  Do you have a simple example that just creates a context and makes GL calls?

What initialization is my original code missing that I achieve by using init(GLAutoDrawable)?

Thanks!
Patrick
Reply | Threaded
Open this post in threaded view
|

Re: Context creation failed on MacBook Pro

gouessej
Administrator
Hi!

Use the short example that I put onto Wikipedia:
http://en.wikipedia.org/wiki/Java_OpenGL

What is null on Mac? The GL instance?

Please use the latest autobuild, not the old JARs.
Julien Gouesse | Personal blog | Website