[Contents] [TitleIndex] [WordIndex


JOGL2PS is not yet a Scilab module. However it should be removed from the Scilab repository and created as a thrid party library. It's a wrapping of the GL2PS library which can be used from JOGL.

JOGL2PS in use

From JOGL JOGL2PS is quite easy to use. The most important class is GL2PS. Once instanciated, it gives access to all GL2PS functions and constants.

It is also advised to use the GL2PSGL class which can be used to hide most of GL2PS functions calls. Its an implementation of the GL interface that should be provided to the current GLAutodrawable.

The a standard use of JOGL2PS is the following:

public void display(GLAutoDrawable gLDrawable) {
  GL2PS gl2ps = new GL2PS(); // new instance of GL2PS
  // Use a GL2PSGL
  GL gl = gLDrawable.getGL();
  GL2PSGL newGL = new GL2PSGL(gl, gl2ps);

  gl2ps.gl2psBeginPage(...); // begin the postscript file creation

  // draw the scene using JOGL commands

  gl2ps.gl2psEndPage(); // end the postcript file creation

  gLDrawable.setGL(gl); // restore previous GL

Implementation details

Here is the lists of JOGL2PS files and their purposes.

As described above this is the entry point for GL2PS functions. It contains all the GL2PS constants and functions with the same parameters. The only modfied function is gl2psBeginPage, there are some differences in the parameters. The colormap must be specified by providing four seperate arrays of same size, each one containing a color channel. The stream file name is specified by its path and not by a File object. The filename parameter as been removed.

This file is an implementation of the GL interface. For convenience it derives from the DebugGL class. Consequentely all the OpenGL classes are already implemented and only a few of them needs to be overidden. The overriden functions are the one which must be followed by a GL2PS calls to works. For example in order to be considered in the output file, gl2psLinewith must be followed by a call to gl2psLinewidth. The GL2PSGL class automatically performs such calls.

These files are generated by Swig. They contains functions to retrive the constants located in GL2PS such as GL2PS_PS. Retrieving the constants from GL2PS avoids to hard code them. Each time their value change there are no impact on JOGL2PS, especially the release verion.

GL2PSWrapping and GL2PSWrapping are classes generated by Swig. They contains the wrapping of all the gl2ps functions

These are the c counter parts of the aboves classes and are also generated by Swig.

These are the two Swig files reponsible for generating the above files.

These two files containes the implementation of the wrapping classes. Bascially, they are just calling the actual GL2PS functions and retrieve the actual GL2PS constants. The only excpptions are gl2psBeginPage and gl2psEndPage. These two functions open and close the file in which the data will be stored.

These files contains the gl2ps actual code. Only slight modifications have been done to adapt the code to JOGL. Theorically, the code could be used as if. However, since the gl2ps code contains some calls to OpenGL and to avoid any conflicts we chose to repalce the OpenGL calls by calls to JOGL. This way the code is only linked to JOGL and the interface to OpenGL is only done through OpenGL. The drawbacks of this methods is that the gl2ps code will call JOGL again, probably reducing performances but essentialy giving more complexity to the tool. Also this method uses Giws to perform the java calls. For each Java method call, Giws requires an instance a C pointer to a JVM instance to run. Inside Scilab, the JVM can be easily accessed, but it might be problematic for other applications. Practically, in the gl2ps code, all the glxxx functions have been replaced by joglxxx functions. Both of the function shares the samethe same prototype. For example glPassTrough has been raplaced by a joglPassthroug function. Also the OpenGL constants are taken from JOGL and are retrived using functions. For example, GL_SRC_ALPHA has been replaced by joglGL_SRC_ALPHA().

This files contains all the joglxxx functions and constants.

These two files are generated by Giws. The contains the entry points for the Java class providing the methods and data needed by JOGLInterface.cpp.

These two files described the generation of GL2PSToJOGL.cpp and JOGLConstant.cpp.

It constains the actual code of methods returning the needed constants.

It contains the actual JOGL functions calls needed by GL2PS. The methods are only direct calls to JOGL functions.

Extracting JOGL2PS and making it independant of Scilab

As described above, the only thing which might prevent from remving JOGL2PS from Scilab is the need of a JVM pointer when calling JOGL functions. However, these JOGL calls might not be really needed. They were added to avoid any conflict between OpenGL calls (the ones from the main JOGL application and the ones from GL2PS). Some more work needs to be perform in order to be sure that such conflict can't happen, but apparently their con be only one OpenGL implementation on a computer. Consequentlely, such conflicts may not have reason to appear.

Moreover, removing the JOGL calls would simplify the API and would make the GL2PS source code modifications no longer needed.


JOGL2PS could be improved by providing a TextRenderer class that could work in postscript. Actually, it's quite easy to make such a class by overriding the TextRenderer draw or draw3D method. This methods should call glRasterPos3d and gl2psTextOpt to place and draw the text. An idea on how to build the class can be found in the GL2PSRenderer.java file.

Also there are two functions which are not yet implemented: gl2psDrawPixels and gl2psGetOptions.

2022-09-08 09:27