OpenGL question

Hello,

My app has its own OpenGL context and objects are typically drawn by calling their   DrawOpenGL   method that typically looks like this :

DrawOpenGL_3D( void ) const
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glEnableClientState(GL_NORMAL_ARRAY);
        glVertexPointer( 3, GL_FLOAT,  6*sizeof( GLfloat),    LeftSurface_VerticesNormals );
        glNormalPointer( GL_FLOAT,     6*sizeof( GLfloat),    LeftSurface_VerticesNormals+3 );
        glDrawArrays( GL_POLYGON, 0, OpenGL_CircularAperture_PointNb   );
    glDisableClientState(GL_VERTEX_ARRAY);
    glDisableClientState(GL_NORMAL_ARRAY);
...
}

Is it also possible to call some kind of    DrawOpenGL   method for OCCT objects (TopoDS_Shape ??)  so that I could display them in my own OpenGL context ?

Thanks for your help,

John

Kirill Gavrilov's picture

OCCT does not provide OpenGL routines drawing TopoDS_Shape or something like this - OCCT Viewer provides a high-level API  Application Interactive Services (AIS package) with an abstraction level of graphic primitives (Graphic3d_ArrayOfPrimitives and others) passed to low-level graphic driver (OpenGl_GraphicDriver implementing Graphic3d_GraphicDriver interface via OpenGL or OpenGL ES graphics APIs).

If you have some existing OpenGL rendering code, then User Draw interface is usually most optimal way for integrating it into OCCT 3D Viewer. The usage sample defining a custom subclass of AIS_InteractiveObject and performing object rendering using OpenGL calls could be found in src/ViewerTest_OpenGlCommands.cxx. Combination of several full-scale graphic engines is more involving as rendering has a complex logic of off-screen buffers, camera definition, material/light source setup and a lot of other nuances. It seems that your code relies on obsolete fixed-function pipeline OpenGL functionality, which modern applications should avoid when possible (OCCT 3D Viewer uses GLSL programs by default).

Alternatively, you may prepare triangulation of TopoDS_Shape and display it on your own.

John Whitaker's picture

Hey Kirill,
Thanks for your anwser.
You're right, my OpenGL codedates back, huum, more than 10 years ago...

Still I'm not sure to understand what you mean  by  "prepare triangulation of TopoDS_Shape"  ?
Would you have some link on that topic ?

BR
John

Kirill Gavrilov's picture

Still I'm not sure to understand what you mean by "prepare triangulation of TopoDS_Shape" ?

That mean to call BRep_IncrementalMesh on your TopoDS_Shape and retrieve tessellation from Poly_Triangulation/Poly_Polygon3D/Poly_PolygonOnTriangulation into application-specific data structures to perform OpenGL drawing on your own.