Multiple windows in OpenGL?

前端 未结 5 1119
暗喜
暗喜 2021-02-06 02:53

Is it possible to have openGL in 2 windows? as in 2 different windows (lets say the first is 640x480 and the other is 1024x768) rendering different things (lets say one window i

5条回答
  •  青春惊慌失措
    2021-02-06 03:14

    Yes, this is possible. For each window you will need to create a unique device context and render context.

    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*/
    

    Before making GL calls to the window you must call wglMakeCurrent like this:

    wglMakeCurrent( hDC, hRC );
    /* GL calls for first window */
    wglMakeCurrent( NULL, NULL);
    
    wglMakeCurrent( hDC2, hRC2 );
    /* GL calls for second window */
    wglMakeCurrent( NULL, NULL);
    

提交回复
热议问题