OpenGL two different 3d rendering picture control on single MFC dialog not working

前端 未结 1 680
日久生厌
日久生厌 2020-12-18 17:04

I am making an application using VC++ MFC where i have two different opengl windows. I have followed the tutorial of enter link description here

I am able to succes

相关标签:
1条回答
  • 2020-12-18 17:53

    OpenGL is a thread global context state machine. That means, that you must switch the OpenGL context of the current thread to the right window so that drawing commands end up where you want them.

    In every member function in which you make OpenGL calls put at the beginning

    wglMakeCurrent(hdc, hrc);
    

    and before you leave the function (i.e. at the end, or before a return)

    wglMakeCurrent(NULL, NULL);
    

    BTW: You can use a single OpenGL context for any number of windows, as long as they share the same visual properties, i.e. if you called SetPixelFormatDescriptor with the same PFD for each window you want the context to use with.

    Last but not least, all of the code found in OnSize and all of the "Basic Setup" found in onInitialize should be put into the drawing code. Your OnDraw is not very useful either.

    0 讨论(0)
提交回复
热议问题