Partly transparent wxGLCanvas Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
danielpi
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Nov 30, 2022 6:24 pm

Partly transparent wxGLCanvas

Post by danielpi »

Hello!

I'm writing a visualization application which will have multiple wxGLCanvases in a window, and the wxGLCanvases are draggable using the mouse. I can raise and lower them to control the z order, and that works fine. But I want the corners of the to be rounded, and this works fine against the background of the window, because I draw the rounded corners in OpenGL for every little wxGLCanvases to have the same color as the window background color. However, when the wxGLCanvases overlap, this little corner is of course visible. An image to illustrate:
Screenshot 2022-11-30 at 19.29.58.png
So the corners of "p_view_0" are nicely blended against the background, but the corners of "p_view_1" and "p_view_2" are clearly visible as red little slivers when they overlap another wxGLCanvases. (If that wasn't clear, "p_view_0", "p_view_1" and "p_view_2" are all separate wxGLCanvases)

Is there anyway to simply make the whole wxGLCanvas transparent, and then only draw in the portions that I need? I.e. to have the same "transparent corner" effect that I have over the window, also for other wxGLCanvases.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Partly transparent wxGLCanvas

Post by doublemax »

There is no easy way to do this.

Easiest way (but with some limitations). Put each wxGLCanvas into a separate borderless wxFrame. Then you can use wxNonOwnedWindow::SetShape() to define the shape of the window. Limitation is that these are totally independent toplevel windows, that could be dragged everywhere, lie on top or below windows from other applications, etc. Except you catch and handle these situtations.

Second option: Whenever you draw a wxGLCanvas, for each of the corners, you check which window is below it, and "ask" the bottom window for its content at a given area (the area covered by the corner of the upper window). E.g. it could return that as a wxBitmap. For OpenGL this should be possible with "glReadPixels". Then you use that content to draw your corner. But there will be some edge cases (literally), when there is more than one window visible under one corner. But if get the first part working, it should be possible to solve that, too.

IMHO it's not worth the effort for just having rounded corners, but YMMV.
Use the source, Luke!
danielpi
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Nov 30, 2022 6:24 pm

Re: Partly transparent wxGLCanvas

Post by danielpi »

Hmm well I figured that any solution would be complex... I had already had some thoughts along your 2nd suggestion, but like you say it's probably not worth it.

Thanks you so much for taking the time! Also nice to finally have asked a question that was answered by the great doublemax ;) Read many threads with your answers, your work is much appreciated!
Post Reply