ClippingPlane Hatching not working (SetCappingHatch)

Hello Friends,
I want to use clipping planes with hatching. Capping works but hatching style is not applied, only solid capping is rendered no matter what I set to SetCappingHatch.

Code:

Handle(Graphic3d_ClipPlane) plane = new Graphic3d_ClipPlane();
plane->SetCapping(true);
plane->SetCappingHatchOn();
plane->SetCappingHatch(Aspect_HS_GRID_DIAGONAL); //<--- No matter what I pass here, nothing changes. See image.
plane->SetCappingColor(Quantity_NOC_CYAN3);
plane->SetEquation({a, b, c, 0});
plane->SetOn(true);
view->AddClipPlane(plane);

Thank you for your help.

Attachments: 
Kirill Gavrilov's picture

Which OpenGL setup are you using?

pload MODELING VISUALIZATION
vinit View1
box b1 0 0 0 10 10 10
box b2 30 0 0 10 40 10
box b3 -30 0 0 20 20 20
vsetdispmode 1
vdisplay b1 b2 b3
vfit

vclipplane create pln2
vclipplane change pln2 equation -0.707 0.707 0 -25
vclipplane change pln2 capping on
vclipplane change pln2 capping color 0.5 0.5 0.9
vclipplane change pln2 capping hatch on
vclipplane set pln2 object b3

Attachments: 
Frank Martinez's picture

Hi Kirill, Thank you for your answer. It works in DRAW, but it doesn't in my simple code

    Handle(Graphic3d_ClipPlane) plane = new Graphic3d_ClipPlane();
    plane->SetCapping(true);
    plane->SetCappingHatchOn();
    plane->SetCappingHatch(Aspect_HS_GRID_DIAGONAL);
    plane->SetCappingColor(Quantity_NOC_BLACK);
    plane->SetEquation({a, b, c, 0});
    plane->SetOn(true);
    view->AddClipPlane(plane);

I have no "special" opengl setup:

    Handle(Aspect_DisplayConnection) dispConnection = new Aspect_DisplayConnection();
    graphicDriver = new OpenGl_GraphicDriver(dispConnection, false);
    graphicDriver->SetBuffersNoSwap(true);       
    glContext = new OpenGl_Context();
    glContext->Init(glfwGetX11Window(window), glfwGetX11Display(), glfwGetGLXContext(window));

But I am using Dear ImGui, maybe the ImGui backend changed some opengl parameter? In that case, what should I search for?

Another strange thing is that colors appear too light, for example Quantity_NOC_BLACK is rendered as gray.

Snapshot

Thank you.

Attachments: 
Kirill Gavrilov's picture

As I can see, you are wrapping OpenGL context created by GLFW. Could you please share a portion of code used for GLFW creation?

Frank Martinez's picture

Sure, for glfw init:

void Init()
{
    glfwSetErrorCallback(&T::onError);
    if (glfwInit() != GLFW_TRUE)
    {
        std::cerr << "GLFW Initialization Error" << std::endl;
        std::terminate();
    }

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_MAXIMIZED, GL_TRUE);
    glfwWindowHint(GLFW_SAMPLES, 4);
    glfwWindow = glfwCreateWindow(800, 600, "Untitled", NULL, NULL);
    if (glfwWindow == NULL)
    {
        std::cerr << "GLFW Window Creation Error" << std::endl;
        glfwTerminate();
        std::terminate();
    }

    // Bind application
    glfwSetWindowUserPointer(glfwWindow, applicationWindow);

    // Set callbacks
    glfwSetWindowSizeCallback(glfwWindow, onWindowResized);
    glfwSetMouseButtonCallback(glfwWindow, onMouseButton);
    glfwSetScrollCallback(glfwWindow, onScroll);
    glfwSetCursorPosCallback(glfwWindow, onMouseMove);
    glfwMakeContextCurrent(glfwWindow);

    // Enable VSync
    glfwSwapInterval(1); 
}

And for Occt:

void Init()
{
    Handle(Aspect_DisplayConnection) dispConnection = new Aspect_DisplayConnection();
    graphicDriver = new OpenGl_GraphicDriver(dispConnection, false);
    graphicDriver->SetBuffersNoSwap(true);       
    glContext = new OpenGl_Context();
    auto nativeWindow = applicationWindow->NativeWindow();
    if (!glContext->Init(glfwGetX11Window(nativeWindow), glfwGetX11Display(), glfwGetGLXContext(nativeWindow)))
    {
        T::onError(9999, "OpenCascade Initialization Error");
        std::terminate();
    }
}

Thank you for your help.

Kirill Gavrilov's picture

As far as I understand hint

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

implicitly tells GLWF to create a Core Profile, at least on Linux platform where Mesa implementation usually provides Core Profile of higher versions than Compatible Profiles.

You may print OpenGL context information using the following code snippet:

Handle(V3d_View) theView;
TCollection_AsciiString aGlInfo;
TColStd_IndexedDataMapOfStringString aRendInfo;
theView->DiagnosticInformation (aRendInfo, Graphic3d_DiagnosticInfo_Basic);
for (TColStd_IndexedDataMapOfStringString::Iterator aValueIter (aRendInfo); aValueIter.More(); aValueIter.Next())
{
  if (!aGlInfo.IsEmpty()) { aGlInfo += "\n"; }
  aGlInfo += TCollection_AsciiString("  ") + aValueIter.Key() + ": " + aValueIter.Value();
}
Message::DefaultMessenger()->Send (TCollection_AsciiString("OpenGL info:\n") + aGlInfo, Message_Info);

Hatching presentation in OCCT currently relies on obsolete OpenGL functionality, which is unavailable in Core Profile. You have the following options:

  • Use textures for capping instead of hatching.
  • Create Compatible Profile by commenting out above mentioned glfwWindowHint() lines.
  • Patch OCCT / contact Open Cascade support to implement hatching feature working in Core Profile (e.g. using GLSL programs).
Frank Martinez's picture

Thank you very much Kirill,

deactivating those lines make it work.

// glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
// glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);

One question, the hatch makes the cross section semitransparent, is there a way to make it not transparent?

snapshot

Attachments: 
Kirill Gavrilov's picture

the hatch makes the cross section semitransparent, is there a way to make it not transparent?

But this is the whole point of hatching ;). What do you expect instead?

If you need a usual opaque capping - consider using textures, like the one coming with "Dimensions" Draw Harness sample.

set aHatch  [locate_data_file images/hatch_1.png]
vclipplane pa -set a -equation 0 0 1 0 -capping on -color GRAY90 -texName $aHatch -texScale 0.05 -0.05

Attachments: 
Jerome Monaco's picture

Hello, I just tried the capping example in Draw and the hatch are displayed so small that they are visible only by zooming a lot.
I am on OCC 7.5.0, windows 10.
Any idea ?
Best regards.
Jerome.

Kirill Gavrilov's picture

Hello Jerome, are you running Linux under virtualization on Windows (which one then?), or you are testing a native Windows build? What shows OpenGL info for your setup?

Jerome Monaco's picture

Hi Kirill and thanks for your answer.
I am on a native windows x64 build with VS2019 and with a 'old' nvidia quadro K2200.
Open GL extensions viewer tells I am OK for OpenGL 4.6 but maybe you need more/other info ?
Jerome.

Kirill Gavrilov's picture

This is strange that you observe this behavior with Dimensions sample in Draw Harness on such configuration. I've seen similar effect only when using Angle library (OpenGL ES implementation over Direct3D) instead of a desktop OpenGL. You may call "vglinfo" in Draw Harness at the end of script to see actual OpenGL configuration.

Jerome Monaco's picture

What I do not understand is that I am sure it worked in previous OCC version as I remember found this example very nice (maybe 7.3.0).

Here are the vglinfo you asked for:

OpenGL info:
GLvendor: NVIDIA Corporation
GLdevice: Quadro K2200/PCIe/SSE2
GLversion: 4.6.0 NVIDIA 391.25
GLSLversion: 4.60 NVIDIA
Max texture size: 16384
Max FBO dump size: 16384x16384
Max combined texture units: 192
Max MSAA samples: 64
Viewport: 768x768
GPU free memory: 3546 MiB
GPU memory: 4096 MiB
ResolutionRatio: 1

Thanks.

Jerome Monaco's picture

Kirill, I finally rebuilt OCC and it works... only the edges of the clip shapes are not visible but I suppose it is related to a drawer in clip plane or in clipped shape...
Thanks for your time.
Best regards.