code_junkie

Multiple windows in OpenGL

Nov 13th, 2011
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. GLuint l_PixelFormat = 0;
  2.  
  3. // some pixel format descriptor that I generally use:
  4. static PIXELFORMATDESCRIPTOR l_Pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1,
  5. PFD_DRAW_TO_WINDOW + PFD_SUPPORT_OPENGL + PFD_DOUBLEBUFFER,
  6. PFD_TYPE_RGBA, m_BitsPerPixel, 0, 0, 0, 0, 0, 0,
  7. 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0};
  8.  
  9. if(!(l_PixelFormat = ChoosePixelFormat(m_hDC, &l_Pfd))){
  10. throw std::runtime_error("No matching pixel format descriptor");
  11. }
  12.  
  13. if(!SetPixelFormat(m_hDC, l_PixelFormat, &l_Pfd)){
  14. throw std::runtime_error("Can't set the pixel format");
  15. }
  16.  
  17. if(!(m_hRC = wglCreateContext(m_hDC))){
  18. throw std::runtime_error("Can't create rendering context");
  19. }
  20.  
  21. wglMakeCurrent(m_hDC, m_hRC);
  22.  
  23. HDC hDC = GetDC( hWnd ); /* get the device context for a particular window */
  24. /* snip */
  25. HGLRC hRC;
  26. hRC = wglCreateContext( hDC ); /* get a render context for the same window */
  27. /* repeat with hDC2 and hRC2 with another window handle*/
  28.  
  29. wglMakeCurrent( hDC, hRC );
  30. /* GL calls for first window */
  31. wglMakeCurrent( NULL, NULL);
  32.  
  33. wglMakeCurrent( hDC2, hRC2 );
  34. /* GL calls for second window */
  35. wglMakeCurrent( NULL, NULL);
  36.  
  37. void COpenGLControl::UpdateCamera()
  38. {
  39. CSaveRestoreRC c(hdc, hrc);
  40.  
  41. // Map the OpenGL device coordinates.
  42. glViewport(0, 0, renderingWindow.Width(), renderingWindow.Height());
  43.  
  44. // Do your other OpenGL stuff here
  45. // ...
  46.  
  47. // the CSaveRestoreRC destructor will automatically put the correct render context back,
  48. // even if you call other functions. Of course, put another CSaveRestoreRC there too.
  49. }
Add Comment
Please, Sign In to add comment