OpenGL_Context_Off

 

Close a previously opened OpenGL context.

 

 

Syntax

 

int  OpenGL_Context_Off(

          HWND wnd,

          char flag

) ;

 

 

Parameters

 

wnd

Handle to the window where you want to do the OpenGL drawing.

 

flag

This flag must be the same as the one used to open the context:

 

CONTEXT_DOUBLE_BUFFER

 

The window is double buffered.  You will draw in a back-buffer, the buffers will automatically be swapped when you issue a call to the "OpenGL_Contect_Off" function.

 

CONTEXT_STENCIL_WRITE

 

The stencil buffer is enable for writing.

 

CONTEXT_STENCIL_USE

The stencil buffers are enabled. Regions that are protected by a stencil will not be written.

 

 

Return value

 

This function return "0" if an error has occurred.

 

 

Remarks

 

You must issue a "OpenGL_Context_Off" (with the same flag as the "OpenGL_Context_On") for each context you open.

 

 

Requirements

 

Header:

          sliceO_include.hpp

          sliceO_OpenGL.hpp

 

 

Library:

          sliceO_Structures.lib

 

 

Example

 

...

 

#include          "sliceO_include.hpp"

#include          "sliceO_OpenGL.hpp"

 

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

//

//          Tool_Color_Draw_Image

//

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

int          Tool_Color_Draw_Image( HWND wnd, Boxs *box, Valuators *val_a, Valuators *val_b )

{

int          i ;

int          vect[2] ;

          

          // -- We need the current GLI color table ---

          unsigned short  ColorMap_GLI_Size = (unsigned short) Fct_Variable_Value( "$COLORMAP_GLI_SIZE" ) ;

          unsigned short  ColorMap_GLI_Cur =  (unsigned short) Fct_Variable_Value( "$COLORMAP_GLI_CUR" ) ;

          Color         **ColorMap_GLI =      (Color **)       Fct_Variable_Value( "$COLORMAP_GLI_PT" ) ;

          if ( ! ColorMap_GLI )

              return( 0 ) ;

 

          Color *colormap = ColorMap_GLI[ColorMap_GLI_Cur] ;

 

          // --- prepare the OpenGL context ---

          int ret = OpenGL_Context_On( wnd, CONTEXT_DOUBLE_BUFFER ) ;

          if ( ! ret ) {

              Error_Fct( hwnd, ERROR_CODE_TRACE, "file:%s line:%d", __FILE__, __LINE__ ) ;

              Error_Fct( hwnd, ERROR_CODE_WARNING, "ERROR: in YGL_CONTEXT_RGB( box_image )" ) ;

              return( NULL ) ;

          }

 

          glViewport( 0, 0, box->Dim_X, box->Dim_Y ) ;

          YGL_ERROR("glViewport") ;

 

          glMatrixMode( GL_PROJECTION ) ;

          glPushMatrix() ;

          glLoadIdentity() ;

          glOrtho( 0.0f, (float) box->Dim_X,

                     0.0f, 1.0f,

                    -0.5f, 0.5f ) ;

          YGL_ERROR("glMatrix a") ;

 

          glMatrixMode( GL_MODELVIEW ) ;

          glPushMatrix() ;

          glLoadIdentity() ;

          YGL_ERROR("glMatrix b") ;

 

          float range = (float) (val_a->Max_Value - val_b->Min_Value) ;

          if ( range <= 0.0f )

              range = 1.0f ;

          float f_a = (val_a->Cur_Value - val_a->Min_Value) / range ;

          float f_b = (val_b->Cur_Value - val_b->Min_Value) / range ;

 

          // --- prevent zero divisions ---

          if ( f_b == f_a )

              f_b = f_a + (1.0f / range) ;

 

          float f = (float) (ColorMap_GLI_Size-1) / (float) box->Dim_X ;

 

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

          // we draw 1 polygon for each pixel of width. The color

          // of this polygon is taken from the active color table

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

          for ( i=0; i < box->Dim_X; i++ ) {

 

              float fact = (float) i / (float) box->Dim_X ;

              int c ;

 

              if ( val_a->Cur_Value < val_b->Cur_Value ) {

                    if ( fact < f_a )

                        c = 0 ;

                    else if ( fact > f_b )

                        c = ColorMap_GLI_Size-1 ;

                    else

                        c = (int) ((ColorMap_GLI_Size-1)

                          * ((fact - f_a) / (f_b - f_a))) ;

              } else {

                    if ( fact < f_b )

                        c = ColorMap_GLI_Size-1 ;

                    else if ( fact > f_a )

                        c = 0 ;

                    else

                        c = (int) ((ColorMap_GLI_Size-1)

                          * ((fact - f_a) / (f_b - f_a))) ;

              }

 

              glColor3ub( colormap[c].col.R,

                              colormap[c].col.G,

                              colormap[c].col.B ) ;

 

              glBegin( GL_POLYGON ) ;

                    vect[0] = i ;

                    vect[1] = 0 ;

                    glVertex2iv( vect ) ;

                    vect[1] = 1 ;

                    glVertex2iv( vect ) ;

                    vect[0] = i+1 ;

                    glVertex2iv( vect ) ;

                    vect[1] = 0 ;

                    glVertex2iv( vect ) ;

              glEnd() ;

          }

          YGL_ERROR("glBegin/End") ;

 

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

          // We draw a yellow line (on black background) for

          // the slider's values.

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

 

          // --- first slider ---

          vect[0] = (int) (f_a * box->Dim_X) ;

 

          // --- black background ---

          glColor3f( 0.0f, 0.0f, 0.0f ) ;

          glLineWidth( 3.0f ) ;

          glBegin( GL_LINES ) ;

              vect[1] = 0 ;

              glVertex2iv( vect ) ;

              vect[1] = 1 ;

              glVertex2iv( vect ) ;

          glEnd() ;

 

          // --- yellow line ---

          glLineWidth( 1.0f ) ;

          glColor3f( 1.0f, 1.0f, 0.0f ) ;

          glBegin( GL_LINES ) ;

              vect[1] = 0 ;

              glVertex2iv( vect ) ;

              vect[1] = 1 ;

              glVertex2iv( vect ) ;

          glEnd() ;

 

          // --- ligne jaune sur fond noir (on fait le fond !) ---

 

          // --- second slider ---

          vect[0] = (int) (f_b * box->Dim_X)  ;

 

          // --- black background ---

          glColor3f( 0.0f, 0.0f, 0.0f ) ;

          glLineWidth( 3.0f ) ;

          glBegin( GL_LINES ) ;

              vect[1] = 0 ;

              glVertex2iv( vect ) ;

              vect[1] = 1 ;

              glVertex2iv( vect ) ;

          glEnd() ;

 

          // --- yellow line ---

          glLineWidth( 1.0f ) ;

          glColor3f( 1.0f, 1.0f, 0.0f ) ;

          glBegin( GL_LINES ) ;

              vect[1] = 0 ;

              glVertex2iv( vect ) ;

              vect[1] = 1 ;

              glVertex2iv( vect ) ;

          glEnd() ;

          YGL_ERROR("glBegin/End") ;

 

 

          // --- reset the OpenGL stack ---

          glMatrixMode( GL_PROJECTION ) ;

          glPopMatrix() ;

          glMatrixMode( GL_MODELVIEW ) ;

          glPopMatrix() ;

          YGL_ERROR("glMatrix") ;

 

          // --- close and swap buffers ---

          OpenGL_Context_Off( wnd, CONTEXT_DOUBLE_BUFFER ) ;

 

          return( 1 ) ;

}

 

...

 

 

See also

 

OpenGL_Contect_On