netgen with togl 2.0?

2010-05-19
2013-05-27
  • Hi,
    I would like to know if netgen can be compiled with togl 2.0?

     
  • No, it cannot

    I once started the port. It was a serious change (improvement) from Togl 1.7 to Togl 2.0.
    But I did not manage to get the fonts working on Linux. Help is welcome.

    Joachim

     
  • So far I manage to build netgen
    But the main windons in netgen has some "refresh" troubles (seems like a copy of the desktop before lunching netgen and then it gets somehow stuck)

    Did you manage to have a "running" version (if we don't consider the problems with fonts)?

     
  • yes, I had the graphics working. But, I didn't look into Togl 2.0 recently

     
  • It tried with Togl 2.1 cvs version…
    We still have some trouble with fonts but it runs fine…

    I think that we need to check with Togl developpers for this issue with fonts.

    Here is the patch I applied

    Change togl.
    Index: netgen-4.9.13.dfsg/ng/Makefile.am
    ===================================================================
    --- netgen-4.9.13.dfsg.orig/ng/Makefile.am  2010-08-19 10:49:25.000000000 +0200
    +++ netgen-4.9.13.dfsg/ng/Makefile.am   2010-08-19 13:52:31.000000000 +0200
    @@ -3,7 +3,7 @@
     AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include -I$(top_srcdir)/libsrc/interface -DOPENGL  -D$(TOGL_WINDOWINGSYSTEM) $(OCCFLAGS)  $(TCL_INCLUDES) $(MPI_INCLUDES) $(FFMPEG_INCLUDES) $(JPEGLIB_INCLUDES)
    
     bin_PROGRAMS = netgen
    -netgen_SOURCES = demoview.cpp ngappinit.cpp ngpkg.cpp onetcl.cpp nginterface.cpp nginterface_v2.cpp parallelfunc.cpp parallelinterface.cpp demoview.hpp parallelfunc.hpp togl_1_7.h
    +netgen_SOURCES = demoview.cpp ngappinit.cpp ngpkg.cpp onetcl.cpp nginterface.cpp nginterface_v2.cpp parallelfunc.cpp parallelinterface.cpp demoview.hpp parallelfunc.hpp
    
     netgen_LDADD = $(top_builddir)/libsrc/visualization/libvisual.a \
    @@ -16,7 +16,7 @@
        $(top_builddir)/libsrc/gprim/libgprim.la \
        $(top_builddir)/libsrc/linalg/libla.la \
        $(top_builddir)/libsrc/general/libgen.la \
    -   $(OCCLIBS) -L$(TK_BIN_DIR)/Togl1.7 $(TOGLLIBDIR) -lTogl1.7 $(LIBGLU) $(TK_LIB_SPEC) $(TCL_LIB_SPEC) $(MPI_LIBS) $(FFMPEG_LIBS) $(JPEGLIB_LIBS) $(PKG_LIBS) 
    +   $(OCCLIBS) -lTogl -lToglstub $(LIBGLU) $(TK_LIB_SPEC) $(TCL_LIB_SPEC) $(MPI_LIBS) $(FFMPEG_LIBS) $(JPEGLIB_LIBS) $(PKG_LIBS)
    
     # add for static linkage of ngsolve:
     #   /opt/netgen/lib/libngsolve.a /opt/netgen/lib/libngcomp.a /opt/netgen/lib/libngcomp.a  /opt/netgen/lib/libngfemng.a   /opt/netgen/lib/libngmg.a  /opt/netgen/lib/libngla.a  /opt/netgen/lib/libngbla.a  /opt/netgen/lib/libngstd.a -L/opt/intel/mkl/10.2.1.017/lib/em64t /opt/intel/mkl/10.2.1.017/lib/em64t/libmkl_solver_lp64.a  -lmkl_intel_lp64  -lmkl_gnu_thread -lmkl_core
    Index: netgen-4.9.13.dfsg/configure.ac
    ===================================================================
    --- netgen-4.9.13.dfsg.orig/configure.ac    2010-08-19 12:09:32.000000000 +0200
    +++ netgen-4.9.13.dfsg/configure.ac 2010-08-19 13:51:55.000000000 +0200
    @@ -22,7 +22,7 @@
    
     AC_LANG([C++])
     AC_PROG_CXX
    -AC_PROG_LIBTOOL
    +LT_INIT
     LT_INIT
    
    @@ -30,11 +30,11 @@
     # OpenCASCADE configuration
    
     AC_ARG_ENABLE([occ], 
    -        [AC_HELP_STRING([--enable-occ],[compile with OpenCascade geometry kernel])],
    +        [AS_HELP_STRING([--enable-occ],[compile with OpenCascade geometry kernel])],
             [occon=true])
    
     AC_ARG_WITH([occ], 
    -        [AC_HELP_STRING([--with-occ=dir],[use OpenCascade installed in directory dir])],
    +        [AS_HELP_STRING([--with-occ=dir],[use OpenCascade installed in directory dir])],
             [occdir=$withval] 
        [occon=true],
        [occdir=/opt/OpenCASCADE]
    @@ -73,7 +73,7 @@
    
     AC_ARG_WITH([togl], 
    -        [AC_HELP_STRING([--with-togl=dir],[directory containing libTogl1.7])],
    +        [AS_HELP_STRING([--with-togl=dir],[directory containing libTogl1.7])],
             [togldir=$withval]
             [togllibfl="-L$withval$"]
             )
    @@ -83,12 +83,12 @@
    
     nglibon=true
     AC_ARG_ENABLE([nglib],
    -        [AC_HELP_STRING([--enable-nglib],[generate shared library nglib])],
    +        [AS_HELP_STRING([--enable-nglib],[generate shared library nglib])],
             [if test "$enableval" = yes; then nglibon=true; else nglibon=false; fi])
    
     AC_ARG_ENABLE([parallel],
    -        [AC_HELP_STRING([--enable-parallel],[enable mpi parallelization])],
    +        [AS_HELP_STRING([--enable-parallel],[enable mpi parallelization])],
             [AC_SUBST([MPI_INCLUDES], "-I/opt/mpich/include -DPARALLEL  -I/usr/share/metis/Lib -DMETIS")
             AC_SUBST([MPI_LIBS], "-lmetis -L/opt/mpich/ch-p4/lib -lmpich")
             ]
    Index: netgen-4.9.13.dfsg/ng/ngpkg.cpp
    ===================================================================
    --- netgen-4.9.13.dfsg.orig/ng/ngpkg.cpp    2010-08-19 10:49:25.000000000 +0200
    +++ netgen-4.9.13.dfsg/ng/ngpkg.cpp 2010-08-19 13:51:29.000000000 +0200
    @@ -33,8 +33,7 @@
     // #include <parallel.hpp>
    
     // to be sure to include the 'right' togl-version
    -#include "togl_1_7.h"
    -// #include "Togl2/togl.h"
    +#include "togl.h"
    
     extern bool nodisplay;
    
    @@ -3224,11 +3223,12 @@
    
       // Sorry, Togl 2.0 not supported
    
    -  Tcl_Obj * togl_font;
    +  static Tcl_Obj * togl_font;
      
       void MyOpenGLText (const char * text)
       {
         cout << "togl - text" << endl;
    +    //Togl_WriteChars(togl, togl_font, text, 0);
       }
    
    @@ -3236,15 +3236,29 @@
       static int
       init(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
       {
    -    cout << "call init" << endl;
    -
         Togl * togl = NULL;
    
         if (Togl_GetToglFromObj(interp, objv[1], &togl) != TCL_OK) 
           return TCL_ERROR;
    
    -    cout << "call Togl - load font (crash on my Linux64)" << endl;
    -    // togl_font = Togl_LoadBitmapFont( togl, "Times"); // TOGL_BITMAP_8_BY_13 );
    +    //cout << "call Togl - load font (crash on my Linux64)" << endl;
    +    if (!togl_font)
    +        togl_font = Togl_LoadBitmapFont(togl, "Times");
    +    if (!togl_font) {
    +        static int shown;
    +
    +        if (!shown) {
    +            cerr << "Couldn't load font!\n" << endl;
    +            shown = 1;
    +        }
    +    }
    +    /*
    +    togl_font = Togl_LoadBitmapFont( togl, "Times"); // TOGL_BITMAP_8_BY_13 );
    +    if (!togl_font) {
    +        printf("Couldn't load font!\n");
    +        exit(1);
    +    }
    +    */
         // togl_font = Togl_LoadBitmapFont( togl, TOGL_BITMAP_8_BY_13 );
         // togl_font = Togl_LoadBitmapFont( togl, NULL );
         // cout << "success" << endl;
    @@ -3273,6 +3287,26 @@
           return TCL_ERROR;
    
    +#ifdef STEREO
    +   glMatrixMode (GL_MODELVIEW);
    +   glPushMatrix();
    +
    +   glLoadIdentity ();
    +
    +   //  glTranslatef (0.1, 0, 0);
    +   gluLookAt (0.3, 0, 6, 0, 0, 0, 0, 1, 0);
    +   Togl_StereoDrawBuffer(GL_BACK_RIGHT);
    +   vs->DrawScene();
    +
    +   glLoadIdentity ();
    +   // glTranslatef (-0.1, 0, 0);
    +   gluLookAt (-0.3, 0, 6, 0, 0, 0, 0, 1, 0);
    +   Togl_StereoDrawBuffer(GL_BACK_LEFT);
    +   vs->DrawScene();
    +   glPopMatrix();
    +
    +   Togl_SwapBuffers(togl);
    +#else
         SetVisualScene (interp);
    
         glPushMatrix();
    @@ -3282,6 +3316,7 @@
         
         Togl_SwapBuffers(togl);
         glPopMatrix();
    +#endif
    
         return TCL_OK;
       }
    @@ -3303,12 +3338,35 @@
         gluPerspective(20.0f, double(w) / h, pnear, pfar);
         glMatrixMode(GL_MODELVIEW);
    
    -    // draw (togl);
    +    //draw (clientData, interp, objc, objv);
    
         return TCL_OK;
       }
    
    +#ifndef JPEGLIB
    +  static int
    +  Ng_SnapShot(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    +  {
    +    cout << "call Ng_SnapShot" << endl << flush;
    +    return TCL_OK;
    +  }
    +#else
    +  static int
    +  Ng_SnapShot(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    +  {
    +    cout << "call Ng_SnapShot" << endl << flush;
    +    return TCL_OK;
    +  }
    +#endif
    
    +#ifdef FFMPEG
    +  static int
    +  Ng_VideoClip(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *const *objv)
    +  {
    +    cout << "call Ng_VideoClip" << endl << flush;
    +    return TCL_OK;
    +  }
    +#endif
    
    @@ -3375,72 +3433,6 @@
       }
    
    -
    -#else
    -
    -
    -  static int Ng_SnapShot (struct Togl * togl,
    -             int argc, tcl_const char *argv[])
    -  {
    -    const char * filename = argv[2];
    -    int len = strlen(filename);
    -
    -    if (strcmp ("jpg", filename+len-3) == 0)
    -      {
    -        cout << "Snapshot to file '" << filename << "'" << endl;
    -
    -        int w = Togl_Width (togl);
    -        w = int((w + 1) / 4) * 4 + 4;
    -        int h = Togl_Height (togl);
    -
    -        // unsigned char * buffer = new unsigned char[w*h*4];
    -        unsigned char * buffer = new unsigned char[w*h*3];
    -        glReadPixels (0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, buffer);
    -
    -        struct jpeg_compress_struct cinfo;
    -        struct jpeg_error_mgr jerr;
    -        FILE *outfile = fopen(filename,"wb");
    -        JSAMPROW row_pointer[1];
    -        int row_stride, quality = 85; // 1...100
    -
    -        cinfo.err = jpeg_std_error( &jerr );
    -        jpeg_create_compress( &cinfo );
    -        jpeg_stdio_dest( &cinfo, outfile );
    -
    -
    -        cinfo.image_width = w;
    -        cinfo.image_height = h;
    -        cinfo.input_components = 3;
    -        cinfo.in_color_space = JCS_RGB;
    -
    -        jpeg_set_defaults( &cinfo );
    -        jpeg_set_quality( &cinfo, quality, TRUE );
    -        jpeg_start_compress( &cinfo, TRUE );
    -
    -        row_stride = 3*w;
    -        while( cinfo.next_scanline < cinfo.image_height ) {
    -          row_pointer[0] = &buffer[ (h-1-cinfo.next_scanline) * row_stride ];
    -          (void)jpeg_write_scanlines( &cinfo, row_pointer, 1 );
    -        }
    -
    -        jpeg_finish_compress( &cinfo );
    -        fclose( outfile );
    -
    -        jpeg_destroy_compress( &cinfo );
    -        fprintf( stdout, "done [ok]\n" );
    -        fflush( stdout );
    -
    -        free( buffer );
    -        return TCL_OK;
    -      }
    -    else
    -      {
    -        cout << "Snapshot to " << filename << " not supported" << endl;
    -        return TCL_ERROR;
    -      }
    -  }
    -
    -
     #endif
    
    @@ -5237,9 +5229,14 @@
     #else
         if (!nodisplay)
           {
    -   if (Togl_Init(interp) == TCL_ERROR) 
    -     return TCL_ERROR;
    -   
    +   /* 
    +    * Initialize Tcl and the Togl widget module.
    +    */
    +   if (Tcl_InitStubs(interp, "8.1", 0) == NULL
    +           || Togl_InitStubs(interp, "2.0", 0) == NULL) {
    +            return TCL_ERROR;
    +   }
    +
    
        Tcl_CreateObjCommand(interp, "init", init, NULL, NULL);
        Tcl_CreateObjCommand(interp, "zap", zap, NULL, NULL);
    @@ -5247,9 +5244,9 @@
        Tcl_CreateObjCommand(interp, "reshape", reshape, NULL, NULL);
    
        //   Togl_TimerFunc(  idle );
    -   // Togl_CreateCommand( (char*)"Ng_SnapShot", Ng_SnapShot);
    -   // Togl_CreateCommand( (char*)"Ng_VideoClip", Ng_VideoClip);
    -   //   Togl_CreateCommand("position",position);
    +   Tcl_CreateObjCommand(interp, "Ng_SnapShot", Ng_SnapShot, NULL, NULL);
    +   Tcl_CreateObjCommand(interp, "Ng_VideoClip", Ng_VideoClip, NULL, NULL);
    +   //   Tcl_CreateObjCommand(interp, "position",position, NULL, NULL);
           }
    
     #endif
    @@ -5308,7 +5305,7 @@
           cerr << "problem with starting acis faceter" << endl;
     #endif
    
    -
    +    cout << "Ng init\n" << flush;
         return TCL_OK;
       }
    
    Index: netgen-4.9.13.dfsg/ng/drawing.tcl
    ===================================================================
    --- netgen-4.9.13.dfsg.orig/ng/drawing.tcl  2010-08-19 12:09:32.000000000 +0200
    +++ netgen-4.9.13.dfsg/ng/drawing.tcl   2010-08-19 12:09:32.000000000 +0200
    @@ -5,6 +5,8 @@
     #
      Creates a drawing frame, and binds mouse events
     #
    +puts "Parsing drawing.tcl"
    +
     set oldmousex 0
     set oldmousey 0
     #
    @@ -13,29 +15,30 @@
    
     # use this one for Togl 2.0
    
    -# if {[catch {togl .ndraw -width 400 -height 300  -rgba true -double true -depth true -privatecmap false -stereo false -indirect true -create init  -display draw -reshape reshape  }] } {
    -
    -# changed -indirect true/false !!!
    -if {[catch {togl .ndraw -width 400 -height 300  -rgba true -double true -depth true -privatecmap false -stereo false -indirect true }] } {    
    -
    -    puts "no OpenGL" 
    +if { [ catch { togl .ndraw -width 400 -height 300 -rgba true -stereo false -double true -depth true -privatecmap false -indirect true -create init  -display draw -reshape reshape } error] } {
    +    puts "no OpenGL"
    +    puts "error : $result"
     } {
         #
         pack .ndraw -expand true -fill both -padx 10 -pady 10
         #
         bind .ndraw <Button-1> {
    -   set oldmousex %x; set oldmousey %y;
    +   set oldmousex %x
    +   set oldmousey %y
         }
         bind .ndraw <Button-2> {
    -   set oldmousex %x; set oldmousey %y;
    +   set oldmousex %x
    +   set oldmousey %y
         }
         bind .ndraw <Button-3> {
    -   set oldmousex %x; set oldmousey %y;
    +   set oldmousex %x
    +   set oldmousey %y
         }
         bind .ndraw <B1-Motion> {
        Ng_MouseMove $oldmousex $oldmousey %x %y $drawmode
        .ndraw render
    -   set oldmousex %x; set oldmousey %y;
    +   set oldmousex %x
    +   set oldmousey %y
         }
    
         bind .ndraw <Double-1> {
    
     
  • Werner Macho
    Werner Macho
    2010-10-14

    I also have only togl2.0 installed on my computer and i guess there will be a lot others in the future..
    Some way to have togl2.0 support inside svn?
    and trophime - somehow I'm not able to copy the patch in a useable way out of this page .. do you have it somewhere else downloadable?

    thanks a lot