Click here to Skip to main content
13,048,805 members (71,315 online)
Rate this:
Please Sign up or sign in to vote.
Hi friends

i have created an opengl application(moving color triangle) and runs perfectly(using glut).

i wanted to pack the opengl application code into dll.

another NEW win32 application will load the dll and create a new blank window, now i want to run the code from the dll into the blank window created by the win32 application.

___my problem is:
the opengl application already runs in its window(using glut). i somehow want it to run in the win32 application window and not default(glut) window.
Posted 24-Apr-12 0:39am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


I did something like this a while back. The source is longish and it's midnight here - I'm too tired to compile a list of the steps needed to free yourself from GLUT - or more importantly, draw with openGL into your own window.

You may wish to look over the files in this zip: Drawing with openGL without using glut[^]

The following things are worth noting:

1) the HDC is a global since it is used when setting up the window ready for GL, it's also used in the call to SwapBuffers within DrawGLSLScene
2) phong.frag and phong.vert need to be in the same folder as the exe file
3) EnableOpenGL is the function that tells openGL where to do it's drawing
4) It's a Code::Blocks project (haven't tried it with VS yet - dunno if it would compile)
5) I never imagined I'd share it, it was done simply to put a openGL scene on a dialog complete with controls to manipulate the cube - sliders for rotation and check-boxes to toggle both (a) lights and (b) shaders


6) The floor is always drawn using a shader - regardless of the state of the check-box

01.mandar 26-Apr-12 7:30am
i have opengl win32 code.
i modified the above code to make dll and the main function(hinst,hprevinst,NULL,NULL) to

which i pass handle of loadlibrary
now it shows 2 windows
1. my Application MDI window(which one i want to embed with)
2. its own (as i am calling complete main code)

the problem is
i can create a window in my application and pass handle to new main but while registering i have given different wnd proc how can i change that;
enhzflep 26-Apr-12 7:42am
I can't be 100% certain without seeing your code, though I will do my best.

I would try creating another function in your DLL, let's call it myDllMain.
I would make it take 1 var instead of 4. This would be a HWND. I would use this HWND as the target window. That is to say, I wouldn't create a new window in this function, but rather use the one that was passed.

I imagine that this would work:

int myDllMain(HWND renderTarget)
MSG exitCode;

EnableOpenGL(renderTarget, &hDC, &hRC);
if (hRC != NULL)
exitCode = doWindowsMainLoop(myIdleFunc);
DisableOpenGL(tgt, hDC, hRC);
return exitCode.wParam;
01.mandar 29-Apr-12 10:05am
thank enhzflep i have use different method but i dont know how much better performance it would give
what i am doing in my win32 application is creating a window and its wndproc i am catching events and performing relevant function from dll


i feel that my solution is not efficient..
searching for better solution :)
01.mandar 5-May-12 3:37am
above solution worked i am able to create opengl window and keep code in library.
application is working wonderfully.
(note: if anyone is trying to do same, i want to tell them it can be done but i have not used SL yet but i will try to do it and post whatever happens)
enhzflep 5-May-12 3:39am
Fantastic! Glad I could reinforce that which I'd learned by passing it on. Cheers!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Apr 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100