Using Aspect_GraphicCallbackProc to add additional 2D graphics

I'm interested in adding additional 2D elements ( primarily text ) to my view. I want to add this using standard windows GDI. However, if I draw this on my own time, I get a flicker between when OpenCascade renders its scene and when I redraw my elements.

I see that there is a version of V3d_View::SetWindow that takes a callback function to be called after OpenCascade render its scene and before it swaps buffers.

I think this is what I want, but when I try using this version of SetWindow, not only does my callback not get called, but my window never even renders.

Has anyone had success with this version of SetWindow? Anyone have thoughs on what I might be doing wrong? Anyone have another approach I could take?

Thanks!

EricThompson's picture

I've made some progress on this. Before I was passing in an empty Aspect_RenderingContext as the second parameter to SetWindow. If I instead pass in NULL, then my callback method gets called. However, I'm not sure how I'm supposed to draw my text once I'm in there.

I've tried using standard GDI calls using the device context contained in the Aspect_RenderingContext, but nothing shows in my window.

I've tried calling the DrawText method of my WNT_WDriver, but this only works if I surround the call with calls to BeginDraw and EndDraw, and I still end up with a worse flicker than the one I started out trying to solve.

Has anyone had any success with this, or know how this is supposed to be used?

Thanks in advance for any help!

EricThompson's picture

After more research, I've found that GDI calls don't work with double-buffered windows. If I want to draw during the graphic callback, I think it needs to be done using pure OpenGl calls.

Since all I want is a way to display text and lines without flicker, I think an overlay layer is my best bet.

Venugopal Gudimetla's picture

Hi Eric,

Which OS are you using? I am using Ubuntu 10. I tried to use overlays to display text. I was able to get overlays to show at the required places, but was unable to get the text working. So if you are using linux environment and get the text to display on overlays, would you be kind to show me how you did it?

Thanks,
Venu

EricThompson's picture

I'm on Windows XP.

Make sure you call mLayer->SetViewport and
mLayer->SetOrtho when you create your layer or resize your window, and call mLayer->SetTextAttributes and mLayer->SetColor before calling DrawText.

Venugopal Gudimetla's picture

Thanks Eric, will try that. Many got it working on Windows. But I will try what you suggested.

Venu