⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0507003.htm

📁 VC知识库5_chm_decompile_20040520_210715
💻 HTM
📖 第 1 页 / 共 2 页
字号:
      <br> 
        PFD_DRAW_TO_WINDOW |            // support window<br> 
      <br> 
        PFD_SUPPORT_OPENGL |            // support OpenGL<br> 
      <br> 
        PFD_TYPE_RGBA,                  // RGBA 模 式, 不 用 调 色 板<br> 
      <br> 
        16,                             // 程 序 在16 位 色 彩 下 运 行<br> 
      <br> 
        0, 0, 0, 0, 0, 0,               // color bits ignored<br> 
      <br> 
        0,                              // no alpha buffer<br> 
      <br> 
        0,                              // shift bit ignored<br> 
      <br> 
        0,                              // no accumulation buffer<br> 
      <br> 
        0, 0, 0, 0,                     // accum bits ignored<br> 
      <br> 
        32,                             // 32-bit z-buffer<br> 
      <br> 
        0,                              // no stencil buffer<br> 
      <br> 
        0,                              // no auxiliary buffer<br> 
      <br> 
        PFD_MAIN_PLANE,                 // main layer<br> 
      <br> 
        0,                              // reserved<br> 
      <br> 
        0, 0, 0                         // layer masks ignored<br> 
      <br> 
    };<br> 
      <br> 
      <br> 
      <br> 
      <br> 
      <br> 
    if ( (pixelformat = ChoosePixelFormat(m_pDC->GetSafeHdc(), &amp;pfd)) == 0 )<br> 
      <br> 
    {<br> 
      <br> 
        MessageBox(" 在 该DC 上 找 不 到 与PFD 接 近 的 位 图 结 构");<br> 
      <br> 
        return -1;<br> 
      <br> 
    }<br> 
      <br> 
      <br> 
      <br> 
    if (SetPixelFormat(m_pDC->GetSafeHdc(), pixelformat, &amp;pfd) == FALSE)<br> 
      <br> 
    {<br> 
      <br> 
        MessageBox(" 无 法 在 该DC 上 设 置 位 图 结 构");<br> 
      <br> 
        return -1;<br> 
      <br> 
    }<br> 
      <br> 
    m_hrc = wglCreateContext(m_pDC->GetSafeHdc());<br> 
      <br> 
    wglMakeCurrent(m_pDC->GetSafeHdc(), m_hrc);<br> 
      <br> 
      <br> 
      <br> 
    glClearDepth(1.0f);<br> 
      <br> 
    glEnable(GL_DEPTH_TEST);<br> 
      <br> 
      <br> 
      <br> 
      <br> 
      <br> 
    glMatrixMode(GL_PROJECTION);<br> 
      <br> 
    glLoadIdentity();<br> 
      <br> 
    glMatrixMode(GL_MODELVIEW);<br> 
      <br> 
      <br> 
      <br> 
	return 0;//OpenGL 窗 口 构 造 成 功<br> 
      <br> 
      }<br> 
      <br> 
      <br> 
      <br> 
      void COpenGLWnd::OnSize(UINT nType, int cx, int cy)&nbsp;<br>
      <br>
      {<br>
      <br>
	CFrameWnd::OnSize(nType, cx, cy);<br> 
      <br> 
      <br> 
      <br> 
	// TODO: Add your message handler code here<br> 
      <br> 
    if(cy > 0)<br> 
      <br> 
    {&nbsp;<br>
      <br>
        glViewport(0, 0, cx, cy);<br> 
      <br> 
        glMatrixMode(GL_PROJECTION);<br> 
      <br> 
        glLoadIdentity();<br> 
      <br> 
		if (cx &lt;= cy) glOrtho(-3.0,3.0,-3.0 * (GLfloat)cx/(GLfloat)cy, 3.0 * (GLfloat)cx/(GLfloat)cy,-3.0,3.0); else glOrtho(-3.0,3.0,-3.0 * (GLfloat)cy/(GLfloat)cx, 3.0 * (GLfloat)cy/(GLfloat)cx,-3.0,3.0); glMatrixMode(GL_MODELVIEW); } } void COpenGLWnd::OnDestroy() { CFrameWnd::OnDestroy(); ::wglMakeCurrent(NULL, NULL); if (m_hrc) ::wglDeleteContext(m_hrc); if (m_pDC) delete m_pDC; // TODO: Add your message handler code here } BOOL COpenGLWnd::OnEraseBkgnd(CDC* pDC) { // TODO: Add your message handler code here and/or call default return TRUE; //return CFrameWnd::OnEraseBkgnd(pDC); } void COpenGLWnd::OnPaint() { CPaintDC dc(this); // device context for painting GLfloat light_position[]="{2.0f,0.0f,4.0f,0.0f};" // TODO: Add your message handler code here glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0f, 0.0f, 2.0f); glLightfv(GL_LIGHT0,GL_POSITION,light_position); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); auxSolidSphere(1.0); glPopMatrix(); glFinish(); // Do not call CFrameWnd::OnPaint() for painting messages } 应 用 程 序 类 的 定 义(SimpleGLApp.h): #if !defined(AFX_SIMPLEGLAPP_H__3FB1AB29 _0E70_11D2_9ACA_48543300E17D__INCLUDED_) #define AFX_SIMPLEGLAPP_H__3FB1AB29_0E70_11D2 _9ACA_48543300E17D__INCLUDED_ #if _MSC_VER>= 1000<br> 
      <br> 
      #pragma once<br> 
      <br> 
      #endif // _MSC_VER >= 1000<br> 
      <br> 
      // SimpleGLApp.h : header file<br> 
      <br> 
      //<br> 
      <br> 
      #include&nbsp;<br>
      <br>
      #include "OpenGLWnd.h"<br> 
      <br> 
      #include "resource.h"<br> 
      <br> 
      <br> 
      <br> 
      /////////////////////////////////////////////////////////////////////////////<br> 
      <br> 
      // CSimpleGLApp thread<br> 
      <br> 
      <br> 
      <br> 
      class CSimpleGLApp : public CWinApp<br> 
      <br> 
      {<br> 
      <br> 
	DECLARE_DYNCREATE(CSimpleGLApp)<br> 
      <br> 
      public:<br> 
      <br> 
	CSimpleGLApp();  // protected constructor used by dynamic creation<br> 
      <br> 
      <br> 
      <br> 
      // Attributes<br> 
      <br> 
      public:<br> 
      <br> 
      <br> 
      <br> 
      // Operations<br> 
      <br> 
      public:<br> 
      <br> 
      <br> 
      <br> 
      // Overrides<br> 
      <br> 
	// ClassWizard generated virtual function overrides<br> 
      <br> 
	//{{AFX_VIRTUAL(CSimpleGLApp)<br> 
      <br> 
	public:<br> 
      <br> 
	virtual BOOL InitInstance();<br> 
      <br> 
	virtual int ExitInstance();<br> 
      <br> 
	//}}AFX_VIRTUAL<br> 
      <br> 
      <br> 
      <br> 
      // Implementation<br> 
      <br> 
      public:<br> 
      <br> 
	virtual ~CSimpleGLApp();<br> 
      <br> 
      <br> 
      <br> 
	// Generated message map functions<br> 
      <br> 
	//{{AFX_MSG(CSimpleGLApp)<br> 
      <br> 
	afx_msg void OnAppExit();<br> 
      <br> 
	//}}AFX_MSG<br> 
      <br> 
      <br> 
      <br> 
	DECLARE_MESSAGE_MAP()<br> 
      <br> 
      };<br> 
      <br> 
      <br> 
      <br> 
      /////////////////////////////////////////////////////////////////////////////<br> 
      <br> 
      <br> 
      <br> 
      //{{AFX_INSERT_LOCATION}}<br> 
      <br> 
      // Microsoft Developer Studio will insert additional&nbsp;<br>
      <br>
      declarations immediately before the previous line.<br> 
      <br> 
      <br> 
      <br> 
      #endif // !defined(AFX_SIMPLEGLAPP_H__3FB1AB29_0E70_11D2_9ACA_48543300E17D__INCLUDED_)<br> 
      <br> 
 应 用 程 序 类 的 实 现(SimpleGLApp.cpp):<br> 
      <br> 
      // SimpleGLApp.cpp : implementation file<br> 
      <br> 
      //<br> 
      <br> 
      <br> 
      <br> 
      #include "stdafx.h"<br> 
      <br> 
      #include "SimpleGLApp.h"<br> 
      <br> 
      #include "OpenGLWnd.h"<br> 
      <br> 
      <br> 
      <br> 
      #ifdef _DEBUG<br> 
      <br> 
      #define new DEBUG_NEW<br> 
      <br> 
      #undef THIS_FILE<br> 
      <br> 
      static char THIS_FILE[] = __FILE__;<br> 
      <br> 
      #endif<br> 
      <br> 
      <br> 
      <br> 
      /////////////////////////////////////////////////////////////////////////////<br> 
      <br> 
      // CSimpleGLApp<br> 
      <br> 
      <br> 
      <br> 
      IMPLEMENT_DYNCREATE(CSimpleGLApp, CWinApp)<br> 
      <br> 
      <br> 
      <br> 
      CSimpleGLApp::CSimpleGLApp()<br> 
      <br> 
      {<br> 
      <br> 
      }<br> 
      <br> 
      <br> 
      <br> 
      CSimpleGLApp::~CSimpleGLApp()<br> 
      <br> 
      {<br> 
      <br> 
      }<br> 
      <br> 
      <br> 
      <br> 
      BOOL CSimpleGLApp::InitInstance()<br> 
      <br> 
      {<br> 
      <br> 
	// TODO:  perform and per-thread initialization here<br> 
      <br> 
	m_pMainWnd = new COpenGLWnd();<br> 
      <br> 
	m_pMainWnd->ShowWindow(m_nCmdShow);<br> 
      <br> 
	m_pMainWnd->UpdateWindow();<br> 
      <br> 
	return TRUE;<br> 
      <br> 
      }<br> 
      <br> 
      <br> 
      <br> 
      int CSimpleGLApp::ExitInstance()<br> 
      <br> 
      {<br> 
      <br> 
	return CWinApp::ExitInstance();<br> 
      <br> 
      }<br> 
      <br> 
      <br> 
      <br> 
      BEGIN_MESSAGE_MAP(CSimpleGLApp, CWinApp)<br> 
      <br> 
	//{{AFX_MSG_MAP(CSimpleGLApp)<br> 
      <br> 
	ON_COMMAND(ID_APP_EXIT, OnAppExit)<br> 
      <br> 
	//}}AFX_MSG_MAP<br> 
      <br> 
      END_MESSAGE_MAP()<br> 
      <br> 
      <br> 
      <br> 
      /////////////////////////////////////////////////////////////////////////////<br> 
      <br> 
      // CSimpleGLApp message handlers<br> 
      <br> 
      void CSimpleGLApp::OnAppExit()&nbsp;<br>
      <br>
      {<br>
      <br>
	// TODO: Add your command handler code here<br> 
      <br> 
	CWinApp::OnAppExit();<br> 
      <br> 
      }<br> 
      <br> 
      <br> 
      <br> 
      CSimpleGLApp SimpleGLApp;  
      </td>     
    </tr>    
    <tr> 
      <td width="100%" height="12" class="font" colspan="2">  
      </td>     
    </tr> 
    <tr> 
      <td width="100%" height="6" class="font" colspan="2">  
      </td>     
    </tr> 
    <tr> 
      <td width="100%" height="8" class="font" colspan="2">  
      </td>     
    </tr> 
    <tr>    
      <td width="100%" height="17" class="font" colspan="2"></td>     
    </tr>    
  </table>     
</div>     
     
</body>     
     
</html>     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -