0

I plan to embed an unmanaged C++ OpenGL viewer in WPF. The requirements are (apart from robustness and ease of development)

  • proper resizing
  • context menu for the OpenGL viewer area (only for viewer related actions)
  • events (e.g. triggered by selection of an object in the OpenGL viewer)
  • WPF dialogs should be drawn on top of the OpenGL space

So far I've found some blogs and discussions about using a hosted WinForm control (via C++/CLI wrapper), but it seems to be bit tricky (even a bit tinkery) to get all my above requirements done (if possible).

How about creating an ActiveX control? Despite having no experience with creating an ActiveX control, one advantage would already be that it runs in its own process.

Is it a good idea or would I run into even more tinkering?

EDIT: I should be clearer about the OpenGL viewer. It's an existing app based on an C++ 3D engine which only supports OpenGL. Porting to an DirectX capable engine is considered as last resort.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Knack
  • 1,044
  • 2
  • 12
  • 25

2 Answers2

1

Although I didn't use ActiveX, I've accomplished what I believe you are trying to achieve. Two pieces of information helped me down this road.

  1. Mixing Managed and Unmanaged code

    • It turns out, that managed C++ compiles completely differently than unmanaged C++, and data is stored on a completely different heap. Luckily you can mark sections of code as managed or unmanaged by using...

    #pragma managed
    #pragma unmanaged

  2. OpenGL context management

    • I followed a method similar to what's described in this article
    • wglMakeCurrent and wglShareLists will be your buddy if you need to manage multiple OpenGL windows

Good Luck!

1

Why you want an activex? There is some managed PInvoke based wrappers as SharpGL doing the job you need easyear. But also, since you are using WPF and you have a Viewport3d object,why don't use it? If you are familiar with 3d engines you will appreciate the semplicity ( even if there is some drawback in term of speed).

Another point, since as per this question here I was forced to abandon WPF 3d rendering in favor of OpenGl due to the fact that Opengl can render in session 0, by using pure software mode. This is a requirement if you are planning to render something in off-screen bitmaps from a service or an asp.net application.

Community
  • 1
  • 1
Felice Pollano
  • 32,832
  • 9
  • 75
  • 115
  • Thanks, good points. But unfortunately my question was not detailled enough regarding the viewer. See my EDIT. – Knack Mar 14 '13 at 07:18