26.5 OpenGL in the Pop Framework

Look back at the code for CPopView::OnDraw(CDC* pDC) that we gave in Section 24.4: Graphics in the Pop Framework. Here is a bulleted list showing some of the corresponding OpenGL calls made by the _pgraphics member of CPopView if _pgraphics is of the type cGraphicsOpenGL*.

  • Wake up the graphics with

    _pgraphics->activate(). 

    This calls

    ::wglMakeCurrent( _pDC->GetSafeHdc(), _hRC ) 
  • Clear the graphics background with

    _pgraphics->clear(targetrect). 

    This calls

    ::glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 
  • Install the projection and view matrices with these lines.

    _pviewpointcritter->loadProjectionMatrix(); 
    _pviewpointcritter->loadViewMatrix(); 

    These in turn call:

    ::glMatrixMode(GL_MODELVIEW) 
    ::glLoadMatrixf(_pviewpointcritter->attitude().inverse()); 
    ::glMatrixMode(GL_PROJECTION) 
    ::gluPerspective (fieldofviewangleindegrees, xtoyaspectratio, 
        nearzclip, farzclip); //Values from _pviewpointcritter 
  • Draw your game world and then the critters with

    pgame()->drawCritters(_pgraphics, _drawflags). 

    This generates a variety of ::gl and ::glu calls like, in the case of polygons

    ::glEnableClientState(GL_VERTEX_ARRAY); 
    ::glVertexPointer(...); 
    ::glDrawArrays(...); 
  • Send the graphics to your video display with

    _pgraphics->display(this, pDC) 

    This calls

    ::glFinish();// Tell OpenGL to flush its pipeline 
    ::SwapBuffers( _pDC->GetSafeHdc() ); // Now Swap the buffers 


    Part I: Software Engineering and Computer Games
    Part II: Software Engineering and Computer Games Reference