Win32 rendering
you can set up opengl in windows mode. I suggest downloading glut as this will hide many of the complexities from you. makes it a snap.
google glut
google glut
You don't need GLUT. Just make a rendering context inside the client area as you normally would. I throw GL rendering contexts all over the place inside windows and dialogs and I never have to do anything 'complex'. It all works the same.
I'd suggest creating a sub-control (probably a frame of some sort, not sure exactly what the native windows widgets are since I mainly do GUIs in .NET) that has an HDC associated with it. You should be able to render OpenGL to it with the usual configuration after that.
I use OpenGLAPPanel with C++ Builder and I can just drop controls right on the window the OpenGL context is attached to. If you try just putting it on the window as you normally would, but it disappears look at how you're handling WM_ERASEBKGND.
Hi
thanks for the replys, but can anyone of you post some code on how you do it? And I will not use glut on this project.
Fredrik
thanks for the replys, but can anyone of you post some code on how you do it? And I will not use glut on this project.
Fredrik
Make a static control in the client area of the window, using GetClientRect to get the right size. I forget how to manually create one, because I use RESED for that, to make one in a dialog.
Now, I used this code to create my context. This is out of my class, but you should be able to modify it easy. If you need to see what's in SetupPixelFormat(), just look at the first nehe tutorial.
//init opengl in a premade controlint gl_video::MakeControl(HWND &hWnd){ //make sure the handle points to a valid control if (hWnd == NULL) { MessageBox(NULL, "ERROR: Could not find control handle.", m_AppTitle, MB_OK | MB_ICONERROR); return false; } m_WindowHandle = hWnd; //atempt to create a device context m_DeviceContext = GetDC(m_WindowHandle); if (m_DeviceContext == NULL) { MessageBox(NULL,"ERROR: Could not create device context.",m_AppTitle, MB_OK | MB_ICONERROR); return false; } //attempt to get a pixel format if (!SetupPixelFormat()) { MessageBox(NULL,"ERROR: Could not set pixel format.",m_AppTitle, MB_OK | MB_ICONERROR); return false; } //attempt to initialize the rendering context m_RenderContext = wglCreateContext(m_DeviceContext); if (m_RenderContext == NULL) { MessageBox(NULL,"ERROR: Could not create rendering context.",m_AppTitle, MB_OK | MB_ICONERROR); return false; } if (!wglMakeCurrent(m_DeviceContext, m_RenderContext)) { MessageBox(NULL,"ERROR: Could not activate rendering context.",m_AppTitle, MB_OK | MB_ICONERROR); return false; } //get the size of the control into a rect //and set the window size member variables RECT WindowRect; GetWindowRect(m_WindowHandle, &WindowRect); m_WindowWidth = WindowRect.right-WindowRect.left; m_WindowHeight = WindowRect.bottom-WindowRect.top; return true;}
Quote:Original post by fredrik90Do you plan to be constantly rendering? When I do that it's never a problem. If your only rendering after set events, then I don't know how to handle it.
I was thinking about, how do you do it with WM_PAINT and WM_ERRASBGND
All above is to much work :)
Forget it
Maybe forget the window all together and start thinking Dialog Boxes.
Just make a dialog box with the resource editor, specify an area for opengl en render in there (set de device context there etc using getClientRect)
This way you can create a window, with menu, just as a normal window, BUT you can also add buttons everywhere and all kinds of other crap (which you can do as simply in a normal window)
The best thing is, that it takes almost no code (especially comparing to a normal window set-up)
Another great advantage is that the area for opengl can be dragged and sized everywhere in the dialog with the editor.
One slight glitch here, is when you start to work with mouse-coords, they will be 0,0 at the top left of the dialog screen, instead of the window for openGL but this is also very easily fixed with 3 lines of code
about 10 lines MAX and you're good to go, with much more flexibility than the standard window
Forget it
Maybe forget the window all together and start thinking Dialog Boxes.
Just make a dialog box with the resource editor, specify an area for opengl en render in there (set de device context there etc using getClientRect)
This way you can create a window, with menu, just as a normal window, BUT you can also add buttons everywhere and all kinds of other crap (which you can do as simply in a normal window)
The best thing is, that it takes almost no code (especially comparing to a normal window set-up)
Another great advantage is that the area for opengl can be dragged and sized everywhere in the dialog with the editor.
One slight glitch here, is when you start to work with mouse-coords, they will be 0,0 at the top left of the dialog screen, instead of the window for openGL but this is also very easily fixed with 3 lines of code
about 10 lines MAX and you're good to go, with much more flexibility than the standard window
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement