| 
				 int pixelformat; 
    //选择设备的像素显示格式,返回像素格式的索引值 
    if ( (pixelformat = ChoosePixelFormat(hdc, &pfd)) == 0 ) 
        return FALSE; 
    //利用返回的索引值,设置设备的像素显示格式 
    if (SetPixelFormat(hdc, pixelformat, &pfd) == FALSE) 
        return FALSE; 
    //创建一个与设备关联的OpenGL渲染上下文环境 
    m_hrc = wglCreateContext(hdc); 
    //指定此OpenGL渲染环境为当前渲染环境 
wglMakeCurrent(hdc, m_hrc); 
  
接着,需要设置OpenGL的视窗大小,投影变换。这里的有些参数可以根据实际需要作相应的调整: 
    glClearDepth(1.0f); 
    glEnable(GL_DEPTH_TEST); //打开深度检测 
  
    //设置视窗大小 
   ::glViewport(0, 0, rc.right - rc.left, rc.bottom - rc.top ); 
    glMatrixMode(GL_PROJECTION); //指定投影矩阵为当前矩阵 
    glLoadIdentity(); 
  
    float x,y,x1,y1; 
    x = rc.left; 
    y = rc.top; 
    x1 = rc.right; 
    y1 = rc.bottom; 
     
    float xRatio = (x1 - x) / (float)( rc.right - rc.left );     float yRatio = (y1 - y) / (float)( rc.bottom - rc.top ); 			
				 |