GL Screen over some Component

nobody wrote on Saturday, May 13, 2006:


I am a Newbie of glfw.

It seems to me, all examples for glfw are only on one Window-frame.

But i just want to create a GL-View Screen not on the Windows but on some Panel in Window.

is it possible?

how can i do it?

elmindreda wrote on Tuesday, May 16, 2006:

No, it’s not currently possible, as GLFW currently doesn’t allow integration with any UI toolkit.

Depending on the toolkit you use, you may need to set up OpenGL by hand, or use an available OpenGL-capable widget.

drew_benton wrote on Tuesday, May 16, 2006:

As elmindreda has said, it is not currently possible, but adding in that functionality for what you need is pretty easy. I’ve gone ahead and made a custom modded GLFW that should give you what you need.

Everything is the same, except you will use another function to create the window - glfwOpenWindowFrom. This function is the same as the glfwOpenWindow function in usage, except you have to pass in the HWND of the component you wish to use as the ‘control’.

Now, for what’s in the package - - The modified GLFW source code (naturally, just Win32 is modified) that allows you to specify a HWND to use as the window GLFW uses.

example/glfw_mfc (run first).exe - A MFC test app that just shows of how GLFW can now be used how you are talking about. Run the app to open up the window:
<a href="" target="_blank"><img src="" border="0" alt="Free Image Hosting at" /></a>

example/glfw_add (run second).exe - This is just a bare minimal Win32 program that finds the window of the MFC app to add GLFW to. When you run this after the mfc app is open, you will get GLFW on the MFC app:
<a href="" target="_blank"><img src="" border="0" alt="Free Image Hosting at" /></a>

example/ - THe source code for both the MFC and Win32 driver app.

<a href=“”>Modified GLFW Package</a>
Now, that was just an example that shows that it really works. ideally, you will know the HWND so you won’t have to use FindWindow and all of that. I’ve tested out my code in a few different examples and it has worked fine, so it should be solid.

Now as for what I did in the GLFW source to do all of this.

1 - Added "_glfwPlatformOpenWindowFrom" based on "_glfwPlatformOpenWindow". The code is similar, except rather than create a new HWND, it uses the users. It also tracks the WNDPROC for BOTH glfw and the old WNDPROC for the HWND to make sure event processing is properly done.

2 - Added "glfwOpenWindowFrom" which is pretty much the same as "glfwOpenWindow" except it now calls "glfwPlatformOpenWindowFrom" instead of "glfwPlatformOpenWindow".

3 - In the “_glfwWindowCallback” function, I call the users stored WNDPROC function if there is one. As for handling the results, that is something you might have to work with, right now it just stores the result from the WNDPROC, but does not handle it. It is up to you to figure out the specific actions based on messages if that’s a problem. It all depends on what you are doing.

And that’s about it! I added the new functions to the proper header files, and added in a preprocessor def so it won’t interfere with other platforms.

Just remember that using it now is the same as you would have before, make sure you call GLFW_Init, set up the opengl window viewport, etc… The *only* thing different is that you call "glfwOpenWindowFrom" with the same parameters as "glfwOpenWindow", except you have to pass in the HWND first, then everything else is the same.

No other behavior of GLFW was [intentionally] changed, so everything else should work the same. You could probabally do some more customizing and stuff if needed, this was just a 1-2 hour endevor.

I hope this helps! I’m around so feel free to ask anything if you run into problems.

- Drew Benton

drew_benton wrote on Wednesday, May 24, 2006:

The links obviously came out wrong, so the file is: