How to use multiple viewports in OpenGL?

前端 未结 6 935
说谎
说谎 2020-12-08 07:12

I need to show the same object in OpenGL in two different viewports, for instance, one using ortographic projection and the other using perspective. In order to do this, do

6条回答
  •  时光说笑
    2020-12-08 08:09

    Think of OpenGL as being nothing more than commands which prepare you to output to the window you're currently working with.

    There's two commands with OpenGL that even NEHE's tutorials don't tell you the importance of:

    wglCreateContext - which takes a window device context DC, can be obtained from ANY window - whether it's a user control, a windows form, a GL window, or another application window (like notepad). This creates an OpenGL device context - they refer to as a resource context - which you later use with ...

    wglMakeCurrent - which takes two parameters, the Device Context you're dealing with (the parameter passed in for the Windows Device Context in wglCreateContext) - and the Resource Context that returns.

    Leveraging ONLY these two things - here's my advice:

    NEHE's tutorial provides a solution that leverages the existing window ONLY and segments the screen for drawing. Here's the tutorial: http://nehe.gamedev.net/tutorial/multiple_viewports/20002/

    Leveraging glViewport you'll need to re-draw on every update.

    That's one method.

    But there's another - less graphically and processor intense method:

    Create a window for each view by leveraging a user control.

    Each window has it's own hWnd.

    Get the DC, process the wglcreatecontext, and then, on a timer (mine is 30 frames a second), if you detect state change, then select wglMakeCurrent for that view and redraw. Otherwise, just skip the section entirely.

    This conserves valuable processing power, and also reduces the code from having to manage the window and viewport calculations manually.

提交回复
热议问题