changing background in v3dview

Hello,
I have the following problem: I want to change the background color in my viewing widget, but any call to
this->v3dview->SetBackgroundColor(Quantity_NOC_BLACK);
has no effect at all.
Neither does
this->v3dview->SetBackgroundImage("C:\\viewer_background.bmp", Aspect_FM_STRETCH, true);

the background is still the default gradient color background from black to grey.
I have only one view defined.

Am I missing something obvious here or why does this not work?

countersubject's picture

In case you need more code, here is the complete init function for the viewing classes.
There is nothing else done with the ais/v3d classes. Changing the background should be straightforward but it isn't. I tried calling various update/redraw functions from the v3dview, and setting default backgrounds with the various functions from the v3dviewer, and absolutely nothing changes.

Aspect_RenderingContext renderingContext = 0;
TCollection_ExtendedString name("Visual3D");
//init v3dviewer
if(this->v3dviewer.IsNull())
{
this->v3dviewer = this->create_viewer("DISPLAY", name.ToExtString(), "", 1000.0);
this->v3dviewer->Init();
this->v3dviewer->SetZBufferManagment(Standard_False);
v3dviewer->SetDefaultTypeOfView(V3d_ORTHOGRAPHIC); //V3d_PERSPECTIVE also possible
this->v3dviewer->SetDefaultViewProj(V3d_Zpos); // Top view
this->v3dviewer->SetUpdateMode(V3d_WAIT);
}
if(this->ais_context.IsNull())
{
this->ais_context = new AIS_InteractiveContext(this->v3dviewer);
this->ais_context->SetHilightColor(Quantity_NOC_WHITE);
}
if(this->v3dview.IsNull())
{
this->v3dview = this->v3dviewer->CreateView();
this->v3dview->SetZClippingType(V3d_OFF);
}

//window
WId id = this->winId();
dfts::integer windowHandle = *reinterpret_cast(&id);
boost::int16_t lo = static_cast(windowHandle);
boost::int16_t hi = static_cast(windowHandle >> 16);
#ifdef WNT
window = new WNT_Window(Handle_Graphic3d_WNTGraphicDevice::DownCast(this->ais_context->CurrentViewer()->Device()),
static_cast(hi), static_cast(lo));
//turn off background erasing in occ window
window->SetFlags(WDF_NOERASEBKGRND);
#else
window = new Xw_Window(Handle_Graphic3d_GraphicDevice::DownCast(this->ais_context->CurrentViewer()->Device()) ,
static_cast(hi), static_cast(lo),
Xw_WQ_SAMEQUALITY, Quantity_NOC_BLACK);
#endif // WNT

if(this->is_null()) { return; }
// set hwnd into the OCC view
this->v3dview->SetWindow(this->window, renderingContext, this->paint_callback, this);
this->v3dview->TriedronDisplay(Aspect_TOTP_LEFT_LOWER, Quantity_NOC_WHITE, 0.1, V3d_ZBUFFER);
this->v3dview->SetScale(viewer_scale);
//
//relevant code for changing background
//
//
this->v3dview->SetBackgroundColor(Quantity_NOC_BLACK);
//
//
//
//
//this->v3dview->SetBgGradientColors (Quantity_Color(0.8,0.8,0.898,Quantity_TOC_RGB), Quantity_Color(0.0,0.0,0.0,Quantity_TOC_RGB), Aspect_GFM_HOR, Standard_False);
if (this->window->IsMapped() == false) { window->Map(); }
this->rubber_band = new QRubberBand(QRubberBand::Rectangle, this);
this->rubber_band->setStyle(new QPlastiqueStyle());

Hannes Kröger's picture

I came across the same problem (using OCE 0.18 aka OCC 6.9.1).

Did you find a solution for this issue?

Hannes Kröger's picture

BTW: I use Ubuntu Linux (16.04 LTS)

Hannes Kröger's picture

Ok, I found the problem.

I had based my application on some Qt example. The example used a paintCallBack function (Aspect_GraphicCallbackProc). Inside this function, the background was overridden. After removing it, everything works as expected now.