Using GLFW to create your window and context is painless. However there is no obvious way to get your window's context from GLFW once it's made. In my case, I needed the context for an OpenGL OpenCL interop.
To get the window handle and device context you can go right after your glfwInit() and glfwOpenWindow(...) and call...
HWND *ptr_hwnd = GetForegroundWindow(); HDC ptr_dc = GetDC( *ptr_hwnd );
And that should do it! No pain, some gain. So long window setup code hello actually doing wtf you wanted to make the window for.
Hey, just found out this post.
ReplyDeleteI've tried using GetForegroundWindow() but I get an "undefined identifier" error.
Any idea what's the name of the function on GLFW 2.7?
Thanks
Ok so after looking up some GLFW results on the issue I'm pretty sure the "GetForegroundWindow()" function is there in 2.7.
DeleteIf your project is small enough could you pastebin the start up code where you call "glfwInit()" and what not.
Undefined identifier sounds like a library thing where the function isn't being defined (declaration or definition). If that's the case your GLFW library isn't being fond or linked for use. Does the project find/use the rest of the GLFW functions? Like, does a baseline GLFW "hello world triangle" work for you?