OpenGL display

can I display the opengl primitives (gl_line, gl_triangle, etc) in opencascade based application. currently, all elements are displayed as follows:
----------
myAISContext.Display(...);
----------
So, how can I display the triangles using the opengl way, like:
----------
gl_begin(gl_triangles);
...
gl_end();
----------

THanks!

EricThompson's picture

In order for OpenCascade to show a view, you have to tell the view what window it is to display in. This is done by calling mView->SetWindow(). If you have a working OpenCascade app, you are already doing this. There is a varient of the SetWindow method that takes a callback function as one of its parameters. Use this method, and do your OpenGL drawing within that callback. The callback will be called every time the view gets refreshed, and the OpenGL context will already be set when you get into that function. A couple of things to note: 1) Unlike mAIScontext.Display(), items added directly in OpenGL are not persistant. Anything that you add will be used for that refresh and then forgotten, so if you want them to keep displaying then you must redraw them everytime the callback gets called. 2) Be careful of any OpenGL settings that you change during the callback, and change them back when you are done. If you don't you might screw up OpenCascade's drawing of it's features. In particular I've seen this happen with the text labels on the trihedron.

b00611024_155209's picture

I don't really get how to do openGl within callback. Could I get more details about how to use opengl functions to draw in v3d_view ? (like a sample code using glVertex3f to draw a simple triangle on v3d_view)

Thanks!

Kirill Gavrilov's picture

glVertex3f() has been deprecated in OpenGL more than decade ago. If you would like to use this functionality mixed with OCCT GLSL programs - you better don't.

Concerning the basic sample using OpenGL functions within OCCT 3D Viewer - it is in source code of vuserdraw command in Draw Harness

b00611024_155209's picture

Thanks for answering! I have another question about Open CASCADE. When I use the function StlAPI_Reader::Read to read STL file, then I get the TopoDS_Shape, but taking too long time. Compared to FreeCAD, which is also developed by using Open CASCADE, the same file is read more efficiently and spends very little time in FreeCAD. Is there any method to improve the efficiency of reading STL by Open CASCADE?

Hope getting your reply! Thanks!

Best Regards,

Si An Chen

Kirill Gavrilov's picture

StlAPI_Reader class exists for backward-compatible API, you can try more efficient RWStl::ReadFile() instead.

pload XDE VISUALIZATION
readstl m [locate_data_file bearing.stl]
vinit View1
vdisplay -dispMode 1 m
vfit