Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GLuint l_PixelFormat = 0;
- // some pixel format descriptor that I generally use:
- static PIXELFORMATDESCRIPTOR l_Pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1,
- PFD_DRAW_TO_WINDOW + PFD_SUPPORT_OPENGL + PFD_DOUBLEBUFFER,
- PFD_TYPE_RGBA, m_BitsPerPixel, 0, 0, 0, 0, 0, 0,
- 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0};
- if(!(l_PixelFormat = ChoosePixelFormat(m_hDC, &l_Pfd))){
- throw std::runtime_error("No matching pixel format descriptor");
- }
- if(!SetPixelFormat(m_hDC, l_PixelFormat, &l_Pfd)){
- throw std::runtime_error("Can't set the pixel format");
- }
- if(!(m_hRC = wglCreateContext(m_hDC))){
- throw std::runtime_error("Can't create rendering context");
- }
- wglMakeCurrent(m_hDC, m_hRC);
- HDC hDC = GetDC( hWnd ); /* get the device context for a particular window */
- /* snip */
- HGLRC hRC;
- hRC = wglCreateContext( hDC ); /* get a render context for the same window */
- /* repeat with hDC2 and hRC2 with another window handle*/
- wglMakeCurrent( hDC, hRC );
- /* GL calls for first window */
- wglMakeCurrent( NULL, NULL);
- wglMakeCurrent( hDC2, hRC2 );
- /* GL calls for second window */
- wglMakeCurrent( NULL, NULL);
- void COpenGLControl::UpdateCamera()
- {
- CSaveRestoreRC c(hdc, hrc);
- // Map the OpenGL device coordinates.
- glViewport(0, 0, renderingWindow.Width(), renderingWindow.Height());
- // Do your other OpenGL stuff here
- // ...
- // the CSaveRestoreRC destructor will automatically put the correct render context back,
- // even if you call other functions. Of course, put another CSaveRestoreRC there too.
- }
Add Comment
Please, Sign In to add comment