Click here to Skip to main content
15,886,806 members
Articles / Multimedia / OpenGL

OpenGL Win32 AppWizard

Rate me:
Please Sign up or sign in to vote.
4.97/5 (45 votes)
19 May 20033 min read 487.1K   22.7K   115  
This Custom AppWizard for VC++ 6.0 or VC++.NET creates an OpenGL enabled Win32 application suitable for demos and simple games.
// cstm1dlg.cpp : implementation file
//

#include "stdafx.h"
#include "OGLWiz.h"
#include "cstm1dlg.h"
#include "OGLWizaw.h"

#ifdef _PSEUDO_DEBUG
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CCustom1Dlg dialog


CCustom1Dlg::CCustom1Dlg()
	: CAppWizStepDlg(CCustom1Dlg::IDD)
{
	//{{AFX_DATA_INIT(CCustom1Dlg)
	m_bAbout = FALSE;
	m_bAccel = FALSE;
	m_bFPS = FALSE;
	m_bMenu = FALSE;
	m_bSample = FALSE;
	m_bUseOgl = FALSE;
	m_bDblBuf = FALSE;
	//}}AFX_DATA_INIT
	m_clBack = RGB(0,0,0);
}


void CCustom1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CAppWizStepDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CCustom1Dlg)
	DDX_Control(pDX, IDC_DEPTHBITS, m_cboDepthBits);
	DDX_Control(pDX, IDC_COLORBITS, m_cboColorBits);
	DDX_Control(pDX, IDC_BGCOLOR, m_wndBgColor);
	DDX_Check(pDX, IDC_CHK_ABOUT, m_bAbout);
	DDX_Check(pDX, IDC_CHK_ACCEL, m_bAccel);
	DDX_Check(pDX, IDC_CHK_FPS, m_bFPS);
	DDX_Check(pDX, IDC_CHK_MENU, m_bMenu);
	DDX_Check(pDX, IDC_CHK_SAMPLE, m_bSample);
	DDX_Check(pDX, IDC_CHK_USEOGL, m_bUseOgl);
	DDX_Check(pDX, IDC_CHK_DBLBUF, m_bDblBuf);
	//}}AFX_DATA_MAP
}

// This is called whenever the user presses Next, Back, or Finish with this step
//  present.  Do all validation & data exchange from the dialog in this function.
BOOL CCustom1Dlg::OnDismiss()
{
	if (!UpdateData(TRUE))
		return FALSE;

	CString sUp = OGLWizaw.m_Dictionary["Root"];
	sUp.MakeUpper();
	OGLWizaw.m_Dictionary["Root_up"] = sUp;

	#define SETKEY(sKey, bVal) if(bVal)OGLWizaw.m_Dictionary[sKey]="*";else OGLWizaw.m_Dictionary.RemoveKey(sKey);
	SETKEY("menu", m_bMenu);
	SETKEY("accel", m_bAccel);
	SETKEY("about", m_bAbout);
	SETKEY("window", ((CButton*)GetDlgItem(IDC_OPT_WINDOW))->GetCheck());
	SETKEY("fullscreen", ((CButton*)GetDlgItem(IDC_OPT_FULL))->GetCheck());
	SETKEY("winfull", ((CButton*)GetDlgItem(IDC_OPT_FULLWND))->GetCheck());
	SETKEY("opengl", m_bUseOgl);
	SETKEY("sample", m_bSample);
	SETKEY("fps", m_bFPS && GetDlgItem(IDC_CHK_FPS)->IsWindowEnabled());
	SETKEY("dblbuf", m_bDblBuf);
	#undef SETKEY

	CString sTmp;
	sTmp.Format("%.3f", (float)(GetRValue(m_clBack))/255.0f); sTmp.Replace(",", ".");
	OGLWizaw.m_Dictionary["back_r"] = sTmp;
	sTmp.Format("%.3f", (float)(GetGValue(m_clBack))/255.0f); sTmp.Replace(",", ".");
	OGLWizaw.m_Dictionary["back_g"] = sTmp;
	sTmp.Format("%.3f", (float)(GetBValue(m_clBack))/255.0f); sTmp.Replace(",", ".");
	OGLWizaw.m_Dictionary["back_b"] = sTmp;

	m_cboColorBits.GetWindowText(sTmp);
	OGLWizaw.m_Dictionary["colorbits"] = sTmp;

	m_cboDepthBits.GetWindowText(sTmp);
	OGLWizaw.m_Dictionary["depthbits"] = sTmp;

	return TRUE;	// return FALSE if the dialog shouldn't be dismissed
}


BEGIN_MESSAGE_MAP(CCustom1Dlg, CAppWizStepDlg)
	//{{AFX_MSG_MAP(CCustom1Dlg)
	ON_BN_CLICKED(IDC_CHK_USEOGL, OnChkUseogl)
	ON_BN_CLICKED(IDC_OPT_FULL, OnOptionClick)
	ON_BN_CLICKED(IDC_BTNCOLOR, OnBtncolor)
	ON_BN_CLICKED(IDC_OPT_WINDOW, OnOptionClick)
	ON_BN_CLICKED(IDC_OPT_FULLWND, OnOptionClick)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CCustom1Dlg message handlers

BOOL CCustom1Dlg::OnInitDialog() 
{
	CAppWizStepDlg::OnInitDialog();

	m_bAbout = FALSE;
	m_bAccel = FALSE;
	m_bFPS = FALSE;
	m_bMenu = FALSE;
	m_bSample = TRUE;
	m_bUseOgl = TRUE;
	m_bDblBuf = TRUE;
	((CButton*)GetDlgItem(IDC_OPT_WINDOW))->SetCheck(TRUE);
	m_cboColorBits.SetCurSel(2);
	m_cboDepthBits.SetCurSel(1);

	UpdateData(FALSE);

	return TRUE;
}

void CCustom1Dlg::OnChkUseogl() 
{
	UpdateCmd();
}

void CCustom1Dlg::OnOptionClick() 
{
	UpdateCmd();
}

void CCustom1Dlg::UpdateCmd()
{
	BOOL bUseOgl = ((CButton*)GetDlgItem(IDC_CHK_USEOGL))->GetCheck();
	BOOL bShowFPS = bUseOgl && !((CButton*)GetDlgItem(IDC_OPT_FULL))->GetCheck();
	GetDlgItem(IDC_CHK_SAMPLE)->EnableWindow(bUseOgl);
	GetDlgItem(IDC_CHK_FPS)->EnableWindow(bShowFPS);	
	m_cboColorBits.EnableWindow(bUseOgl);
	m_cboDepthBits.EnableWindow(bUseOgl);
	((CButton*)GetDlgItem(IDC_CHK_DBLBUF))->EnableWindow(bUseOgl);
	((CButton*)GetDlgItem(IDC_BTNCOLOR))->EnableWindow(bUseOgl);	
}


void CCustom1Dlg::OnBtncolor() 
{
	CColorDialog dlg(m_clBack);
	if(dlg.DoModal() == IDOK)
	{
		m_clBack = dlg.GetColor();
		Invalidate(FALSE);
	}
}

void CCustom1Dlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	CRect	r;
	m_wndBgColor.GetWindowRect(&r);
	ScreenToClient(&r);
	r.InflateRect(-2,-2);
	dc.FillSolidRect(r, m_clBack);
	// Do not call CAppWizStepDlg::OnPaint() for painting messages
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Sweden Sweden
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions