Jump to content
  • Advertisement
Sign in to follow this  
Vamsee

OpenGL Barebone example of Hosting an Unmanaged C++ OpenGL Window in C# Winforms/WPF

This topic is 1264 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

 

Can anyone please share an example project where we can see a OpenGL Window running inside a Win32 Form/WPF using c#.

 

Till now i was using GLFW to create a window and render to that window. But, it would be awesome if i can render into a Winform, and create buttons,labels etc to use for creating visual debugging .....and hopefully some day into a full fledged WYSIWYG editor!

 

So, simply put, how can i get the hwnd from c# winform to a C++ opengl app.

I think below two replies address the above line.But, I needed more information than that, i need a complete example project/solution that i can compile and test, and learn from it, and develop on top of it.

 

Any useful links are also appreciated.

 

Thanks.

Edited by Vamsee

Share this post


Link to post
Share on other sites
Advertisement

One thing you can do is to just drop a panel control on the form, and then use the hWnd property of that panel to spool up a GL context as usual.

Edited by Promit

Share this post


Link to post
Share on other sites

In addition to what Promit said, WPF has a HwndHost control that can host a native window. There are some issues with clipping/overlapping and such, but if you stay with simple rectangular stuff you'll be fine smile.png

Edited by Nik02

Share this post


Link to post
Share on other sites

In addition to what Promit said, WPF has a HwndHost control that can host a native window. There are some issues with clipping/overlapping and such, but if you stay with simple rectangular stuff you'll be fine smile.png

 

 

One thing you can do is to just drop a panel control on the form, and then use the hWnd property of that panel to spool up a GL context as usual.

 

Thanks for the tips, but, since i'm a beginner im having a little hardtime, getting things up and running. I was hoping for a sample project that does the above.

i've modified the question a little to reflect my intention.

Share this post


Link to post
Share on other sites

In both Forms and WPF, the mentioned techniques are very simple. I (and I believe Promit too) assumed that you can create a native window to begin with.

 

Both approaches give you a window handle (a HWND) that you can use as a drawing area.

Share this post


Link to post
Share on other sites

In both Forms and WPF, the mentioned techniques are very simple. I (and I believe Promit too) assumed that you can create a native window to begin with.

 

Both approaches give you a window handle (a HWND) that you can use as a drawing area.

 

I think i will post back with a Sample app myself, and then you guys can have look at it for corrections, where i fail. 

p.s. it might take a while --- while i try :)

Share this post


Link to post
Share on other sites

 

I think i will post back with a Sample app myself, and then you guys can have look at it for corrections, where i fail. 

p.s. it might take a while --- while i try smile.png

You should google c++/CLI

Share this post


Link to post
Share on other sites

While we generally don't want to write complete samples just to reply to a topic, we can help you if you hit specific roadblocks. And yes, we can review your code if it is written concisely enough smile.png

 

Trying to code functionality yourself is the most effective way to learn.

 

To get you started though:

 

I checked the GLFW framework documentation last night, and that particular framework insists that it creates the rendering window for you. You will want to skip that, and as Promit said, create the OpenGL context manually against an existing window (which lives in your Forms or WPF app's control). This does not represent a huge amount of code anyway. Much of the rest of the code should be standard OpenGL stuff, regardless of which party created the window.

Edited by Nik02

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!