Click here to Skip to main content
15,886,030 members
Articles / Desktop Programming / MFC

OpenGL MFC AppWizard

Rate me:
Please Sign up or sign in to vote.
4.79/5 (10 votes)
15 Jan 2009GPL36 min read 155.1K   5.4K   68  
An article showing how to make a Custom AppWizard for OpenGL applications in Visual Studio .NET 2008
//  OGLView.cpp
//  Created by Dave Kerr, 20/04/2002 22:44:15

#include "stdafx.h"
#include "OpenGLView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

IMPLEMENT_DYNCREATE(COpenGLView, CView)

BEGIN_MESSAGE_MAP(COpenGLView, CView)
	ON_WM_ERASEBKGND()
	ON_WM_SIZE()
	ON_WM_DESTROY()
END_MESSAGE_MAP()

void COpenGLView::OnDraw(CDC* pDC)
{
	//	Make the OpenGL Surface current.
	m_openGLSurface.MakeCurrent();

	//	Do any opengl drawing.
	DoOpenGLDraw();

	//	Now blit the lot into the DC.
	m_openGLSurface.Draw(pDC, 0, 0);

	//	Deactivate the surface.
	m_openGLSurface.MakeNoneCurrent();
}

#ifdef _DEBUG
void COpenGLView::AssertValid() const
{
	CView::AssertValid();
}

void COpenGLView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}
#endif //_DEBUG

BOOL COpenGLView::OnEraseBkgnd(CDC* pDC) 
{
	//	The DIB Surface handles erasing the background.
	return TRUE;
}

void COpenGLView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);

	//	If size is silly (x=0 || y=0) don't create.
	if(cx == 0 || cy == 0)
		return;
	
	//	Recreate our DIB surface using the correct size.
	m_openGLSurface.Create(cx, cy, 24);

	//	Call the override - this'll handle the viewport projection.
	DoOpenGLResize(cx, cy);
}

void COpenGLView::OnDestroy() 
{
//	CView::OnDestroy();

	//	Destroy the surface.
	m_openGLSurface.Destroy();	
}

BOOL COpenGLView::PreCreateWindow(CREATESTRUCT& cs) 
{
	cs.style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

	if(cs.style&CS_PARENTDC)
		cs.style -= CS_PARENTDC;	
	
	return CView::PreCreateWindow(cs);
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer
United Kingdom United Kingdom
Follow my blog at www.dwmkerr.com and find out about my charity at www.childrenshomesnepal.org.

Comments and Discussions