3dFrame.cpp
资源名称:gloop.zip [点击查看]
上传用户:shxiangxiu
上传日期:2007-01-03
资源大小:1101k
文件大小:2k
源码类别:
OpenGL
开发平台:
Visual C++
- // 3dFrame.cpp
- //
- // Copyright (c) Craig Fahrnbach 1997, 1998
- //
- // This program is freely distributable without licensing fees and is
- // provided without guarantee or warrantee expressed or implied. This
- // program is -not- in the public domain.
- //
- // This file should be included in your application's main
- // include file so that it is available to all modules that
- // need access the the OpenGL 3D classes
- //
- #include "stdafx.h"
- #include "3dPlus.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- //////////////////////////////////////////////////////////////////
- // C3dFrame
- IMPLEMENT_DYNAMIC(C3dFrame, CObject)
- /////////////////////////////////////////////////////////////////////////////
- // C3dFrame construction
- C3dFrame::C3dFrame()
- {
- // Assign Default values to member attributes
- m_hWnd = NULL;
- m_hDC = NULL;
- m_hRC = NULL;
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dFrame Destructor
- C3dFrame::~C3dFrame()
- {
- if(m_hRC)
- // Clean up rendering context stuff
- wglDeleteContext(m_hRC);
- }
- /////////////////////////////////////////////////////////////////////////////
- // C3dFrame Procedures
- BOOL C3dFrame::Create(DWORD dwFlags, CWnd* pParent)
- {
- // Ensure we have a valid window
- ASSERT(pParent);
- m_hWnd = pParent->m_hWnd;
- m_hDC = ::GetDC(pParent->m_hWnd);
- // Set an appropriate pixel format supported by a device context
- // to a given pixel format specification.
- if(!the3dEngine.SetWindowPixelFormat(m_hDC, dwFlags))
- return FALSE;
- // Create the rendering context
- m_hRC = wglCreateContext(m_hDC);
- if (!m_hRC)
- return FALSE;
- return TRUE;
- }
- BOOL C3dFrame::Enable(BOOL bEnable)
- {
- if(bEnable)
- {
- // Make the rendering context current
- if(!wglMakeCurrent(m_hDC, m_hRC))
- {
- LPVOID lpMsgBuf;
- FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- NULL,
- GetLastError(),
- MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
- (LPTSTR) &lpMsgBuf,
- 0,
- NULL);
- // Display the string.
- MessageBox( NULL, (LPTSTR)lpMsgBuf, "GetLastError", MB_OK|MB_ICONINFORMATION );
- // Free the buffer.
- LocalFree( lpMsgBuf );
- TRACE("C3dFrame::EnableFrame - wglMakeCurrent failedn");
- return FALSE;
- }
- }
- else
- // Release the rendering context to allow other
- // rendering contexts to co-exist
- wglMakeCurrent(NULL, NULL);
- return TRUE;
- }