C++ (Qt)
#ifndef OCTEST_H
#define OCTEST_H
#include <V3d_View.hxx>
#include <QtGui>
#include <QtOpenGL\QtOpenGL>
#include <AIS_InteractiveContext.hxx>
#include <Graphic3d_WNTGraphicDevice.hxx>
#include <Graphic3d_GraphicDevice.hxx>
#include <Graphic3d_NameOfMaterial.hxx>
#include <AIS_InteractiveContext.hxx>
#include <AIS_Shape.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
#include <BRepPrimAPI_MakeSphere.hxx>
//
#include <WNT_Window.hxx>
#include <iostream>
#include "stdlib.h" //'getenv'
class OCtest : public QWidget
{
Q_OBJECT
public:
OCtest(QWidget*, Qt::WFlags);
OCtest(const Handle(AIS_InteractiveContext)&, QWidget*, Qt::WFlags);
~OCtest();
private:
Handle(AIS_InteractiveContext) myContext;
Graphic3d_WNTGraphicDevice* WindowsGraphicDevice;
Handle(WNT_Window) aWNTWindow;
Handle(V3d_Viewer) viewer;
Handle(V3d_View) view;
Handle(V3d_Viewer) Viewer( const Standard_CString aDisplay,
const Standard_ExtString aName,
const Standard_CString aDomain,
const Standard_Real ViewSize,
const V3d_TypeOfOrientation ViewProj,
const Standard_Boolean ComputedMode,
const Standard_Boolean aDefaultComputedMode );
bool flag;
protected:
void Initialize(void);
virtual void paintEvent(QPaintEvent* e);
};
#endif // OCTEST_H
C++ (Qt)
#include "octest.h"
OCtest::OCtest( QWidget *parent=0, Qt::WFlags flags=0)
: QWidget(parent, flags)
{
flag=true;
setAutoFillBackground (false);
}
OCtest::OCtest(const Handle(AIS_InteractiveContext)& context, QWidget* parent=0, Qt::WFlags flags=0)
: QWidget(parent, flags)
{
}
OCtest::~OCtest()
{
}
void OCtest::Initialize(void)
{
WindowsGraphicDevice=new Graphic3d_WNTGraphicDevice();
aWNTWindow = new WNT_Window(WindowsGraphicDevice, (HWND*)this->winId());
viewer =new V3d_Viewer(WindowsGraphicDevice, (short* const)"viewer");
viewer->Init();//Viewer( getenv("DISPLAY"), (short* const)"", "", 1000.0,V3d_XposYnegZpos, Standard_True, Standard_True )
view= viewer->CreateView();
if ( !aWNTWindow->IsMapped() )
aWNTWindow->Map();
view->SetWindow(aWNTWindow);
myContext = new AIS_InteractiveContext(viewer);
viewer->SetDefaultLights();
viewer->SetLightOn();
view->SetBackgroundColor(Quantity_NOC_BLACK);
view->MustBeResized();
////code a simple primitive for display
BRepPrimAPI_MakeSphere S(gp_Pnt(200.,300.,200.), 100.);
Handle(AIS_Shape) anAISShape = new AIS_Shape(S.Shape());
myContext->SetColor(anAISShape,Quantity_NOC_AZURE);
myContext->SetMaterial(anAISShape,Graphic3d_NOM_PLASTIC);
myContext->SetDisplayMode(anAISShape,1);
myContext->Display(anAISShape);
}
void OCtest::paintEvent(QPaintEvent* e)
{
// QApplication::syncX();
//this->setUpdatesEnabled(!true);
if( flag )
{
Initialize();
flag = false;
}
view->Update();
//this->setUpdatesEnabled(false);
}
Handle(V3d_Viewer) OCtest::Viewer( const Standard_CString aDisplay,
const Standard_ExtString aName,
const Standard_CString aDomain,
const Standard_Real ViewSize,
const V3d_TypeOfOrientation ViewProj,
const Standard_Boolean ComputedMode,
const Standard_Boolean aDefaultComputedMode )
{
#ifndef WNT
static Handle(Graphic3d_GraphicDevice) defaultdevice;
if( defaultdevice.IsNull() )
defaultdevice = new Graphic3d_GraphicDevice( aDisplay );
return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
#else
static Handle(Graphic3d_WNTGraphicDevice) defaultdevice;
if( defaultdevice.IsNull() )
defaultdevice = new Graphic3d_WNTGraphicDevice();
return new V3d_Viewer(defaultdevice,aName,aDomain,ViewSize,ViewProj,
Quantity_NOC_GRAY30,V3d_ZBUFFER,V3d_GOURAUD,V3d_WAIT,
ComputedMode,aDefaultComputedMode,V3d_TEX_NONE);
#endif
}
сам Open cascade
http://www.opencascade.org/