|
...
#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 ) ;
}
...
|