OpenGL Programming for Windows MFC


8. Fog

8.1 FogGL


GLint FogGL()
{
    GLfloat fog_color[] = {0.0, 0.0, 0.5, 1.0} ;

    glEnable(GL_FOG) ;
    glFogf (GL_FOG_DENSITY, 0.5) ;
    glFogfv(GL_FOG_COLOR  , fog_color) ;

    return (0) ;
}


8.2 OnCreateを以下のように変更

int CXXXView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
    if (CView::OnCreate(lpCreateStruct) == -1)
        return -1;
	
    m_pDC = new CClientDC(this) ;             // Get device context
    SetDCPixelFormat(m_pDC->m_hDC) ;          // Set OpenGL pixel format
    m_GLRC = wglCreateContext (m_pDC->m_hDC); // Create rendering context
    wglMakeCurrent (m_pDC->m_hDC, m_GLRC);    // Current context set
    InitGL() ;                                // Initalize OpenGL

    m_pRGBImage = auxDIBImageLoad("tiger.bmp"); // DIB Image load
    //m_pRGBImage = auxDIBImageLoad("cow.bmp");

    MatGL() ;                                  // Material setup
                                                // Texture setup
    TexGL(m_pRGBImage->sizeX, m_pRGBImage->sizeY, m_pRGBImage->data) ;

    Light1GL() ;                               // Light1 Setup

    FogGL() ;                                  // Fog Setup

    return 0;
}

OnCreate is changed as mentioned above.

8.3 Build and Execute



prev next