Question about vuserdraw


i have read the source code of vuserdraw command in ViewerTest_OpenGlCommands.cxx.  I want to draw something using the Render() function, which means i need to create a OpenGl_Workspace as the parameter of the Render() function.  So i create a OpenGl_Workspace using a WNT_Window which is created by a dialog item in MFC. The problem is that i cannot see the view while the program runs successfully. Here is my code.


//create a window in a Dialog 


CWnd* cpwnd = GetDlgItem(IDC_STATIC_CP);

Handle(WNT_Window) cp_wnt_wnd = new WNT_Window(cpwnd->m_hWnd);

//create a OpenGl_Workspace

Handle(OpenGl_GraphicDriver) myglGraphicDriver = theApp.GetGraphicDriver();

Handle(OpenGl_Window) myglWindow = myglGraphicDriver->CreateRenderWindow(cp_wnt_wnd, (Aspect_RenderingContext)0);

Handle(OpenGl_Caps) myglCaps = &myglGraphicDriver->ChangeOptions();

Handle(Graphic3d_StructureManager) myG3dStructureCanager = new Graphic3d_StructureManager(myglGraphicDriver);

OpenGl_StateCounter* myglStateCounter = new OpenGl_StateCounter();

Handle(OpenGl_View) myglView = new OpenGl_View(myG3dStructureCanager, myglGraphicDriver, myglCaps, myglStateCounter);

Handle(OpenGl_Workspace) myglWorkSpace = new OpenGl_Workspace(myglView, myglWindow);

// the code below is the same as the code in Render().

Handle(OpenGl_Context) myglContext myglContext = myglWorkSpace->GetGlContext();

const OpenGl_AspectMarker* aMA = myglWorkSpace->AspectMarker();


const OpenGl_AspectText* aTA = myglWorkSpace->AspectText();


OpenGl_Vec4 aColor=myglWorkSpace->LineColor();

myglContext->ShaderManager()->BindLineProgram(Handle(OpenGl_TextureSet)(), Aspect_TOL_SOLID, Graphic3d_TOSM_UNLIT, Graphic3d_AlphaMode_Opaque, false, Handle(OpenGl_ShaderProgram)());


const OpenGl_Vec3 aVertArray[4] =



OpenGl_Vec3(10.0, 20.0, -30.0),

OpenGl_Vec3(10.0, 20.0, 30.0),



Handle(OpenGl_VertexBuffer) aVertBuffer = new OpenGl_VertexBuffer();

aVertBuffer->Init(myglContext, 3, 4, aVertArray[0].GetData());


aVertBuffer->BindAttribute(myglContext, Graphic3d_TOA_POS);

glDrawArrays(GL_LINE_LOOP, 0, aVertBuffer->GetElemsNb());

aVertBuffer->UnbindAttribute(myglContext, Graphic3d_TOA_POS);



Thanks in advance.

Kirill Gavrilov's picture

OpenGl_Window is a low-level interface. It is supposed to be created by V3d_View/V3d_Viewer, not manually.

924112424_150196's picture

Then how can i get the OpenGl_Window created by a V3d_View/V3d_Viewer?

I want to create a OpenGl_Workspace so that i can use the opengl commands to render just like the vuserdraw.

Thank you for your reply.

Kirill Gavrilov's picture

V3d_View::Redraw() does a lot more things than just calling OpenGl_Element::Render().
Either, follow suggested rendered path (like in case of vuserdraw, which creates a custom AIS_InteractiveObject and OpenGl_Element), or you have to dig deep into TKOpenGl, TKV3d, TKService classes to see how they work.