if ( glIsEnabled( GL_DEPTH_TEST ) )
glDisable( GL_DEPTH_TEST ); //push GL_ENABLE_BIT
- // drawing bg image if defined
- if ( myBgTexture.TexId != 0 )
- {
- GLfloat texX_range = 1.F; // texture <s> coordinate
- GLfloat texY_range = 1.F; // texture <t> coordinate
-
- // Set up for stretching or tiling
- GLfloat x_offset, y_offset;
- if ( myBgTexture.Style == Aspect_FM_CENTERED )
- {
- x_offset = (GLfloat)myBgTexture.Width / (GLfloat)aViewWidth;
- y_offset = (GLfloat)myBgTexture.Height / (GLfloat)aViewHeight;
- }
- else
- {
- x_offset = 1.F;
- y_offset = 1.F;
- if ( myBgTexture.Style == Aspect_FM_TILED )
- {
- texX_range = (GLfloat)aViewWidth / (GLfloat)myBgTexture.Width;
- texY_range = (GLfloat)aViewHeight / (GLfloat)myBgTexture.Height;
- }
- }
-
- glEnable( GL_TEXTURE_2D ); //push GL_ENABLE_BIT
- glBindTexture( GL_TEXTURE_2D, myBgTexture.TexId ); //push GL_TEXTURE_BIT
-
- glDisable( GL_BLEND ); //push GL_ENABLE_BIT
-
- glColor3fv( AWorkspace->BackgroundColor().rgb );
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //push GL_TEXTURE_BIT
-
- glBegin( GL_QUADS );
- glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -y_offset );
- glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -y_offset );
- glTexCoord2f(texX_range, texY_range); glVertex2f( x_offset, y_offset );
- glTexCoord2f(0.F, texY_range); glVertex2f( -x_offset, y_offset );
- glEnd();
- }
- else //if( myBgGradient.type != Aspect_GFM_NONE )
+ // drawing bg gradient if:
+ // - gradient fill type is not Aspect_GFM_NONE and
+ // - either background texture is no specified or it is drawn in Aspect_FM_CENTERED mode
+ if ( ( myBgGradient.type != Aspect_GFM_NONE ) &&
+ ( myBgTexture.TexId == 0 || myBgTexture.Style == Aspect_FM_CENTERED ||
+ myBgTexture.Style == Aspect_FM_NONE ) )
{
Tfloat* corner1 = 0;/* -1,-1*/
Tfloat* corner2 = 0;/* 1,-1*/
switch( myBgGradient.type )
{
case Aspect_GFM_HOR:
- corner1 = myBgGradient.color2.rgb;
+ corner1 = myBgGradient.color1.rgb;
corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color1.rgb;
+ corner3 = myBgGradient.color2.rgb;
corner4 = myBgGradient.color1.rgb;
break;
case Aspect_GFM_VER:
corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color1.rgb;
+ corner2 = myBgGradient.color2.rgb;
corner3 = myBgGradient.color1.rgb;
- corner4 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color1.rgb;
break;
case Aspect_GFM_DIAG1:
corner2 = myBgGradient.color2.rgb;
corner4 = dcorner2;
break;
case Aspect_GFM_CORNER1:
- corner1 = myBgGradient.color1.rgb;
+ corner1 = myBgGradient.color2.rgb;
corner2 = myBgGradient.color2.rgb;
corner3 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color2.rgb;
+ corner4 = myBgGradient.color1.rgb;
break;
case Aspect_GFM_CORNER2:
corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color1.rgb;
- corner3 = myBgGradient.color2.rgb;
+ corner2 = myBgGradient.color2.rgb;
+ corner3 = myBgGradient.color1.rgb;
corner4 = myBgGradient.color2.rgb;
break;
case Aspect_GFM_CORNER3:
corner1 = myBgGradient.color2.rgb;
- corner2 = myBgGradient.color2.rgb;
- corner3 = myBgGradient.color1.rgb;
+ corner2 = myBgGradient.color1.rgb;
+ corner3 = myBgGradient.color2.rgb;
corner4 = myBgGradient.color2.rgb;
break;
case Aspect_GFM_CORNER4:
- corner1 = myBgGradient.color2.rgb;
+ corner1 = myBgGradient.color1.rgb;
corner2 = myBgGradient.color2.rgb;
corner3 = myBgGradient.color2.rgb;
- corner4 = myBgGradient.color1.rgb;
+ corner4 = myBgGradient.color2.rgb;
break;
default:
//printf("gradient background type not right\n");
glShadeModel( GL_SMOOTH ); //push GL_LIGHTING_BIT
glBegin(GL_TRIANGLE_FAN);
- if( myBgGradient.type != Aspect_GFM_CORNER2 && myBgGradient.type != Aspect_GFM_CORNER4 )
+ if( myBgGradient.type != Aspect_GFM_CORNER1 && myBgGradient.type != Aspect_GFM_CORNER3 )
{
glColor3f(corner1[0],corner1[1],corner1[2]); glVertex2f(-1.,-1.);
glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
glColor3f(corner4[0],corner4[1],corner4[2]); glVertex2f(-1., 1.);
}
- else //if ( myBgGradient.type == Aspect_GFM_CORNER2 || myBgGradient.type == Aspect_GFM_CORNER4 )
+ else //if ( myBgGradient.type == Aspect_GFM_CORNER1 || myBgGradient.type == Aspect_GFM_CORNER3 )
{
glColor3f(corner2[0],corner2[1],corner2[2]); glVertex2f( 1.,-1.);
glColor3f(corner3[0],corner3[1],corner3[2]); glVertex2f( 1., 1.);
if ( curSM != GL_SMOOTH )
glShadeModel( curSM );
}
+ // drawing bg image if:
+ // - it is defined and
+ // - fill type is not Aspect_FM_NONE
+ if ( myBgTexture.TexId != 0 && myBgTexture.Style != Aspect_FM_NONE )
+ {
+ GLfloat texX_range = 1.F; // texture <s> coordinate
+ GLfloat texY_range = 1.F; // texture <t> coordinate
+
+ // Set up for stretching or tiling
+ GLfloat x_offset, y_offset;
+ if ( myBgTexture.Style == Aspect_FM_CENTERED )
+ {
+ x_offset = (GLfloat)myBgTexture.Width / (GLfloat)aViewWidth;
+ y_offset = (GLfloat)myBgTexture.Height / (GLfloat)aViewHeight;
+ }
+ else
+ {
+ x_offset = 1.F;
+ y_offset = 1.F;
+ if ( myBgTexture.Style == Aspect_FM_TILED )
+ {
+ texX_range = (GLfloat)aViewWidth / (GLfloat)myBgTexture.Width;
+ texY_range = (GLfloat)aViewHeight / (GLfloat)myBgTexture.Height;
+ }
+ }
+
+ glEnable( GL_TEXTURE_2D ); //push GL_ENABLE_BIT
+ glBindTexture( GL_TEXTURE_2D, myBgTexture.TexId ); //push GL_TEXTURE_BIT
+
+ glDisable( GL_BLEND ); //push GL_ENABLE_BIT
+
+ glColor3fv( AWorkspace->BackgroundColor().rgb );
+ glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //push GL_TEXTURE_BIT
+
+ glBegin( GL_QUADS );
+ glTexCoord2f(0.F, 0.F); glVertex2f( -x_offset, -y_offset );
+ glTexCoord2f(texX_range, 0.F); glVertex2f( x_offset, -y_offset );
+ glTexCoord2f(texX_range, texY_range); glVertex2f( x_offset, y_offset );
+ glTexCoord2f(0.F, texY_range); glVertex2f( -x_offset, y_offset );
+ glEnd();
+ }
glPopMatrix();
glMatrixMode( GL_PROJECTION );
myBgTexture.TexId = texture;
myBgTexture.Width = width;
myBgTexture.Height = height;
- switch ( AFillStyle )
- {
- case Aspect_FM_NONE :
- myBgTexture.Style = Aspect_FM_CENTERED;
- break;
- default :
- myBgTexture.Style = AFillStyle;
- break;
- }
+ myBgTexture.Style = AFillStyle;
}
}
//call_togl_set_bg_texture_style
void OpenGl_View::SetBackgroundTextureStyle (const Aspect_FillMethod AFillStyle)
{
- /* check if background texture is already created */
- if ( myBgTexture.TexId != 0 )
- {
- switch ( AFillStyle )
- {
- case Aspect_FM_NONE :
- myBgTexture.Style = Aspect_FM_CENTERED;
- break;
- default :
- myBgTexture.Style = AFillStyle;
- break;
- }
- }
+ myBgTexture.Style = AFillStyle;
}
/*----------------------------------------------------------------------*/
//call_togl_set_gradient_type
void OpenGl_View::SetBackgroundGradientType (const Aspect_GradientFillMethod AType)
{
- // check if gradient background is already created
- if ( myBgGradient.type != Aspect_GFM_NONE )
- myBgGradient.type = AType;
+ myBgGradient.type = AType;
}
/*----------------------------------------------------------------------*/
if (argc < 2 || argc > 3)
{
di << "Usage : " << argv[0] << " imagefile [filltype] : Load image as background" << "\n";
+ di << "filltype can be one of CENTERED, TILED, STRETCH, NONE" << "\n";
return 1;
}
return 0;
}
+//==============================================================================
+//function : VSetBgMode
+//purpose : Change background image fill type
+//==============================================================================
+
+static int VSetBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ if (argc != 2)
+ {
+ di << "Usage : " << argv[0] << " filltype : Change background image mode" << "\n";
+ di << "filltype must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
+ if(AISContext.IsNull())
+ {
+ di << "use 'vinit' command before " << argv[0] << "\n";
+ return 1;
+ }
+
+ Aspect_FillMethod aFillType;
+ if (argc == 2)
+ {
+ const char* szType = argv[1];
+ if (strcmp(szType, "NONE" ) == 0) aFillType = Aspect_FM_NONE;
+ else if (strcmp(szType, "CENTERED") == 0) aFillType = Aspect_FM_CENTERED;
+ else if (strcmp(szType, "TILED" ) == 0) aFillType = Aspect_FM_TILED;
+ else if (strcmp(szType, "STRETCH" ) == 0) aFillType = Aspect_FM_STRETCH;
+ else
+ {
+ di << "Wrong fill type : " << szType << "\n";
+ di << "Must be one of CENTERED, TILED, STRETCH, NONE" << "\n";
+ return 1;
+ }
+ }
+
+ Handle(V3d_View) V3dView = ViewerTest::CurrentView();
+ V3dView->SetBgImageStyle(aFillType, Standard_True);
+
+ return 0;
+}
+
//==============================================================================
//function : VSetGradientBg
//purpose : Mount gradient background
return 0;
}
+//==============================================================================
+//function : VSetGradientBgMode
+//purpose : Change gradient background fill style
+//==============================================================================
+static int VSetGradientBgMode(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ if (argc != 2 )
+ {
+ di << "Usage : " << argv[0] << " Type : Change gradient background fill type" << "\n";
+ di << "Type must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
+ di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
+ if(AISContext.IsNull())
+ {
+ di << "use 'vinit' command before " << argv[0] << "\n";
+ return 1;
+ }
+ if (argc == 2)
+ {
+ int aType = atoi(argv[1]);
+ if( aType < 0 || aType > 8 )
+ {
+ di << "Wrong fill type " << "\n";
+ di << "Must be one of 0 = NONE, 1 = HOR, 2 = VER, 3 = DIAG1, 4 = DIAG2" << "\n";
+ di << " 5 = CORNER1, 6 = CORNER2, 7 = CORNER3, 8 = CORNER4" << "\n";
+ return 1;
+ }
+
+ Aspect_GradientFillMethod aMethod = Aspect_GradientFillMethod(aType);
+
+ Handle(V3d_View) V3dView = ViewerTest::CurrentView();
+ V3dView->SetBgGradientStyle( aMethod, 1 );
+ }
+
+ return 0;
+}
+
+//==============================================================================
+//function : VSetColorBg
+//purpose : Set color background
+//==============================================================================
+static int VSetColorBg(Draw_Interpretor& di, Standard_Integer argc, const char** argv)
+{
+ if (argc != 4 )
+ {
+ di << "Usage : " << argv[0] << " R G B : Set color background" << "\n";
+ di << "R,G,B = [0..255]" << "\n";
+ return 1;
+ }
+
+ Handle(AIS_InteractiveContext) AISContext = ViewerTest::GetAISContext();
+ if(AISContext.IsNull())
+ {
+ di << "use 'vinit' command before " << argv[0] << "\n";
+ return 1;
+ }
+ if (argc == 4)
+ {
+
+ Standard_Real R = atof(argv[1])/255.;
+ Standard_Real G = atof(argv[2])/255.;
+ Standard_Real B = atof(argv[3])/255.;
+ Quantity_Color aColor(R,G,B,Quantity_TOC_RGB);
+
+ Handle(V3d_View) V3dView = ViewerTest::CurrentView();
+ V3dView->SetBackgroundColor( aColor );
+ V3dView->Update();
+ }
+
+ return 0;
+}
+
//==============================================================================
//function : VScale
//purpose : View Scaling
theCommands.Add("vsetbg",
"vsetbg : vsetbg imagefile [filltype] : Load image as background",
__FILE__,VSetBg,group);
+ theCommands.Add("vsetbgmode",
+ "vsetbgmode : vsetbgmode filltype : Change background image fill type",
+ __FILE__,VSetBgMode,group);
theCommands.Add("vsetgradientbg",
- "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
+ "vsetgradientbg : vsetgradientbg r1 g1 b1 r2 g2 b2 filltype : Mount gradient background",
__FILE__,VSetGradientBg,group);
+ theCommands.Add("vsetgrbgmode",
+ "vsetgrbgmode : vsetgrbgmode filltype : Change gradient background fill type",
+ __FILE__,VSetGradientBgMode,group);
+ theCommands.Add("vsetcolorbg",
+ "vsetcolorbg : vsetcolorbg r g b : Set background color",
+ __FILE__,VSetColorBg,group);
theCommands.Add("vscale",
"vscale : vscale X Y Z",
__FILE__,VScale,group);