0% found this document useful (0 votes)
20 views

3dframe (CPP)

This document contains C++ code for a C3dFrame class that manages OpenGL rendering contexts. The class constructor initializes member variables like window handles to null. The destructor cleans up the rendering context. The Create method sets up the pixel format, creates the rendering context, and returns a boolean. The Enable method makes the context current or releases it, allowing other contexts.

Uploaded by

bhslegion1498
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

3dframe (CPP)

This document contains C++ code for a C3dFrame class that manages OpenGL rendering contexts. The class constructor initializes member variables like window handles to null. The destructor cleans up the rendering context. The Create method sets up the pixel format, creates the rendering context, and returns a boolean. The Enable method makes the context current or releases it, allowing other contexts.

Uploaded by

bhslegion1498
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

// 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 failed\n");


return FALSE;
}
}
else
// Release the rendering context to allow other
// rendering contexts to co-exist
wglMakeCurrent(NULL, NULL);

return TRUE;
}

You might also like