Fct_Draw_OpenGL

 

The array of functions pointed to by Fct_Draw_OpenGL[]()are used to draw in the OpenGL step of the drawing process.

 

You can add your own callback to the array (you need to get an index in the array with the "Get_Callback_ID()" function).  As an example, the "Measure" mode use the Fct_Draw_OpenGL callback to draw the measuring tools on the frames.

 

This callback add OpenGL drawings on top of the base. 

 

The OpenGL callbacks from the array are called in increasing value starting at 0.  So the highest index (the latest installed callback) will be on top of the other OpenGL drawings.

 

Syntax

 

int  (*Fct_Draw_OpenGL[CALLBACK_NB_OPENGL])(

          SliceO_Class *pt,

          UInt64 flag,

          SliceO_Window *window

)

 

 

Parameters

 

pt

Pointer to the class calling the function.

 

flag

Value of the Redraw_Flag.

 

window

Pointer to the window where the class is drawn.

 

 

Return value

 

This function return "1" if successful.

 

 

Remarks

 

 

Requirements

 

Header:

          sliceO_include.hpp

 

Library:

          sliceO_Structures.lib

 

 

Example

 

Using Draw_OpenGL in the Measure mode

 

// --- Callback ID assign at startup with Get_Callback_ID() ---

static          unsigned short          Local_Callback_ID ;

 

// ----------------------------------------------------------------------------

//

//          Function:          Get_Callback_ID

//

//          Parameters:          id (unsigned short)          // callback id assigned to the DLL

//          Returns:          (void)

//

//          SliceOmatic will use this function at start-up to assign a unique

//          ID number to your DLL.

//

// ----------------------------------------------------------------------------

extern "C" __declspec(dllexport) unsigned short Get_Callback_ID( unsigned short *id )

{

          Local_Callback_ID = id[CALLBACK_DRAW_OPENGL] ;

          return( 1 << CALLBACK_DRAW_OPENGL ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Measure_Callback_Register

//

//          Parameters:          (void)

//          Returns:          (int)                    0 for errors

//

//          This function will assign the "Measure_Draw_Tool" fct to the Fct_Draw_OpenGL

//          of each frames in the database.

//

//          This function is called when the mode is activated and when the database

//          is modified while the mode is activated

//

// ----------------------------------------------------------------------------

int          Measure_Callback_Register( void )

{

          Measure_Callback_Reset() ;

 

          // --- for all frames ---

          Iterator_Init( ITERATOR_2, "Measure_Callback_Register" ) ;

          while( SliceO_Frame *frame = (SliceO_Frame *) Iterator_Class( ITERATOR_2, CLASS_ID_FRAME ) ) {

              frame->Fct_Draw_OpenGL[Local_Callback_ID] = Measure_Draw_Tool ;

          }

          Iterator_End( ITERATOR_2 ) ;

          return( 1 ) ;

}

 

// ----------------------------------------------------------------------------

//

//          Function:          Measure_Callback_Reset

//

//          Parameters:          (void)

//          Returns:          (int)                    0 for errors

//

//          This function will assign reset the pointers of the Fct_Draw_OpenGL

//          of each frames in the database.

//

//          This function is called when the mode is exited

//

// ----------------------------------------------------------------------------

int          Measure_Callback_Reset( void )

{

          // --- for all frames ---

          Iterator_Init( ITERATOR_2, "Measure_Callback_Reset" ) ;

          while( SliceO_Frame *frame = (SliceO_Frame *) Iterator_Class( ITERATOR_2, CLASS_ID_FRAME ) ) {

              frame->Fct_Draw_OpenGL[Local_Callback_ID] = NULL ;

          }

          Iterator_End( ITERATOR_2 ) ;

          return( 1 ) ;

}

 

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

// ============================================================================

 

// ----------------------------------------------------------------------------

//

//          Measure_Draw_Tool

//

//          draw the 2D measurement tools

//

//          Param:          (int) cur_window

//                    (SliceO_Image *) ima

//

//          Return:          (int)                    

//

// ----------------------------------------------------------------------------

int          Measure_Draw_Tool( SliceO_Class *pt, UInt64 flag, SliceO_Window *window )

{

          // --- only draw lines to windows in Measure mode ---

          if ( window->Module_Get() != Ctrl_Query() )

              return( 1 ) ;

 

          SliceO_Frame *frame = (SliceO_Frame *) pt ;

 

          // --- critical reagion: make sure we are not interrupted ---

          Access_Init( "Measure_Draw_Tool" ) ;

 

          if ( ! Database_Viewport( window, frame ) )

              return( 1 ) ;

 

          // --- Make sure we stay in the window ---

          glEnable( GL_SCISSOR_TEST ) ;

 

          // --- look, among all the 2D tools, if any should be drawn for this frame ---

          for ( int i=Measure_Active_Nb-1; i >= 0; i-- ) {

 

              // --- wrong frame ? ---

              if ( (! (Measure_Active_List[i]->m_mode & MEASURE_FLAG_GLOBAL))

                && Measure_Active_List[i]->frame != frame )

                    continue ;

 

              // --- wrong group ? ---

              if ( (Measure_Active_List[i]->m_mode & MEASURE_FLAG_GLOBAL)

                && Measure_Active_List[i]->frame->Parent_Get_Pt() != frame->Parent_Get_Pt() )

                    continue ;

 

              Measure_Active_List[i]->Draw( window, frame ) ;

          }

 

          glDisable( GL_SCISSOR_TEST ) ;

 

          // --- release the critical region ---

          Access_End( "Measure_Draw_Tool" ) ;

 

          return( 1 ) ;

}

 

See also