Click here to Skip to main content
13,042,789 members (80,985 online)
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads

Stats

71.2K views
66 bookmarked
Posted 15 Jan 2009

OpenGL MFC AppWizard

, 15 Jan 2009
An article showing how to make a Custom AppWizard for OpenGL applictions in Visual Studio .NET 2008
// [!output PROJECT_NAME]View.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "[!output PROJECT_NAME].h"
#include "[!output PROJECT_NAME]View.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// C[!output PROJECT_NAME]View

C[!output PROJECT_NAME]View::C[!output PROJECT_NAME]View()
{
}

C[!output PROJECT_NAME]View::~C[!output PROJECT_NAME]View()
{
}


BEGIN_MESSAGE_MAP(C[!output PROJECT_NAME]View, COpenGLView)
END_MESSAGE_MAP()



// C[!output PROJECT_NAME]View message handlers

BOOL C[!output PROJECT_NAME]View::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void C[!output PROJECT_NAME]View::DoOpenGLDraw()
{
[!if CHECKBOX_EXAMPLE_RENDERING]
	//	Here we'll do a little bit of example rendering, by drawing a cube.
	
	//	Set the clear colour to black and clear the colour buffer.
	glClearColor(0, 0, 0, 1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	//	Look at the middle of the scene.
	glLoadIdentity();
	gluLookAt(-10, 10, 10, 0, 0, 0, 0, 1, 0);

	//	Set up some nice attributes for drawing the grid.
	glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT | GL_COLOR_BUFFER_BIT);
	glEnable(GL_LINE_SMOOTH);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable(GL_LIGHTING);
	glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
	glLineWidth(1.5f);

	//	Create the grid.

    glBegin(GL_LINES);
	
	for (int i = -10; i <= 10; i++)
    {
		glColor4f(0.2f, 0.2f, 0.2f, 0.8f);
        glVertex3f((float)i, 0, -10);
        glVertex3f((float)i, 0, 10);
        glVertex3f(-10, 0, (float)i);
        glVertex3f(10, 0, (float)i);
	}
	
	glEnd();

	//	Create the axies.
	glBegin(GL_LINES);

		glColor4f(1, 0, 0, 1);
		glVertex3f(0, 0, 0);
		glVertex3f(3, 0, 0);
		glColor4f(0, 1, 0, 1);
		glVertex3f(0, 0, 0);
		glVertex3f(0, 3, 0);
		glColor4f(0, 0, 1, 1);
		glVertex3f(0, 0, 0);
		glVertex3f(0, 0, 3);

	glEnd();

	glPopAttrib();

	glFlush();
[!else]
	//	Do your OpenGL drawing here. Don't forget to call glFlush at the end!
[!endif]
}

void C[!output PROJECT_NAME]View::DoOpenGLResize(int nWidth, int nHeight)
{
	//	Create the viewport.
	glViewport(0, 0, nWidth, nHeight);

	//	Load the identity projection matrix.
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	//	Create a perspective viewport transformation.
	gluPerspective(45.0f, (GLfloat)nWidth / (GLfloat)nHeight, 0.1f, 100.0f);

	//	Go back to the modelview matrix.
	glMatrixMode(GL_MODELVIEW);
}

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)

Share

About the Author

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

You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170713.1 | Last Updated 15 Jan 2009
Article Copyright 2009 by Dave Kerr
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid