occ 中绘制二维矩形

时间:2022-03-28 07:11:36

在屏幕上绘制一个二级矩形

#include <Visual3d_Layer.hxx>

#include <V3d_LayerMgr.hxx>

#include <Visual3d_ViewManager.hxx>

#include "FTFont.h"

#include "FTGLBitmapFont.h"

class V3d_TextItem : public Visual3d_LayerItem { public:

V3d_TextItem(const Handle(Visual3d_Layer)& theLayer);

void RedrawLayerPrs();

private:

Standard_Real            myX1;

Standard_Real            myY1;

TCollection_AsciiString  myText;

Standard_Real            myHeight;

Handle(Visual3d_Layer)   myLayer;

Quantity_Color           myColor;

Quantity_Color           mySubtitleColor;

Aspect_TypeOfDisplayText myType;

TCollection_AsciiString  myFontName;

};

V3d_TextItem::V3d_TextItem (const Handle(Visual3d_Layer)& theLayer) : myLayer(theLayer)

{

if (!myLayer.IsNull ())   myLayer->AddLayerItem (this);

}

void V3d_TextItem::RedrawLayerPrs ()

interactive_context_->CurrentViewer()->InitActiveViews();

Handle(V3d_View) v3d_view = interactive_context_->CurrentViewer()->ActiveView();

Handle(Visual3d_Layer) anOverlay = interactive_context_->CurrentViewer()->Viewer()->OverLayer();

if (anOverlay.IsNull ())

{

Handle(V3d_LayerMgr) aMgr = new V3d_LayerMgr (v3d_view);    anOverlay = aMgr->Overlay ();    v3d_view->SetLayerMgr (aMgr);

}

anOverlay->Begin();

anOverlay->DrawRectangle(0, 0, 100, 100);

anOverlay->End();

一个Visual3d_Layer关联一个v3d, 先编译到一个显示列表里面,然后再渲染。