Question

I'm making all my gui element with custom method using OpenGL (Button, checkbox...). I want to make those method modulable so they can be used with different API different than OpenGL (ex:Swing). I'm using the abstract factory pattern to do this.

Here a method than implement an abstract function of my factory:

    public void select(GL2 gl, List<Integer> resultat, int index,
        MouseEventEnum event) {
    if(m_actif) {
        switch(event) {
        case CLICK:
            if(error_cle_message != null) {
                MiniLogModifiableData mlog = new MiniLogModifiableData(
                        error_cle_message, 3);
                mlog.envoieMessage(this.getClass().getSimpleName());
            }
        }
    }

}

The problem is, in all those method I need the GL2 context to perform the operation. Is there a way to access this GL2 context without having to pass it in argument or any other things i'm doing wrong?

Here is a call in another function:

m_listeBoutons.get(i)).select(null, null, -1, MouseEventEnum.CLICKED);
Was it helpful?

Solution

You can call GLContext.getCurrentGL() to get the GL instance but your method must be called when the OpenGL context is current. Look at the source code of Ardor3D JOGL renderer to see how I use it.

Why not using GL2ES2 and GL2ES1 where it is possible so that your code has a chance to work with OpenGL-ES too? Your source code would be easier to read if your variables weren't named in French and without respecting Java code conventions. Finally, the official JogAmp forum is a better place to ask questions about JOGL.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top