Click here to Skip to main content
15,868,016 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 483.7K   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.
// App.h: interface for the CApp class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(APP_H_INCLUDED)
#define APP_H_INCLUDED

#pragma once

#define FRAME_INTERVAL 1000     // Interval between FPS updates (ms)
#define FPS_TIMER_ID 0xFFFFFFFF // ID for FPS timer

/////////////////////////////////////////////////////////////////////////////
// CApp
// Application base class

class CApp
{
private:
	BOOL m_bFPSTimer; // Flag to indicate if FPS timer is active
	UINT m_nFrames;   // Number of frames since last FPS update

protected:
	HINSTANCE m_hInstance;// Handle to application instance
	HACCEL m_hAccelTable;	// Accelerator table
	HWND m_hWnd;			// Handle to window

	HDC m_hDC;				// Handle to DC
[!if CHK_OPENGL]
	HGLRC m_hRC;		  // Handle to RC

	//Viewport info
	GLfloat m_fFovy;  // Field-of-view
  GLfloat m_fZNear; // Near clipping plane
  GLfloat m_fZFar;  // Far clipping plane	

[!endif]

	void OnIdle();
[!if CHK_OPENGL]
	virtual void DrawScene() = 0;
	virtual void KillScene() = 0;
	virtual void InitScene() = 0;
	virtual BOOL Tick() { return TRUE; }
[!else]
	virtual BOOL Tick() { return FALSE; }
[!endif]

	void SetFPSTimer(BOOL bStart);
	BOOL GetFPSTimer();
	virtual void OnUpdateFPS(float fFPS){}

	virtual BOOL OnCommand(int nCmdID, int nEvent);	
	void OnCreate();
	void OnDestroy();
	void OnSize(int cx, int cy);
	virtual void OnPaint(HDC hDC);
[!if CHK_OPENGL]
	void FireDrawScene();
	void SetViewPort(float fFovy, float fZNear, float fZFar, BOOL bApply = TRUE);
[!endif]
	virtual void PreCreateWindow(WNDCLASSEX &wcex, DWORD &dwStyle, DWORD &dwExStyle, int &x, int &y, int &cx, int &cy);
[!if CHK_OPENGL]
	virtual void PreCreateRC(PIXELFORMATDESCRIPTOR &pfd);
[!endif]
	virtual BOOL InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine);
	virtual void ExitInstance();

[!if CHK_ABOUT]
	int ShowAboutDialog();
	static LRESULT CALLBACK AboutProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

[!endif]
public:
	static CApp* m_pAppInstance;

	int Run(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine);
	virtual LRESULT WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

	CApp();
	virtual ~CApp();
};
[!if CHK_OPENGL]

void GLCube(GLfloat x1, GLfloat y1, GLfloat z1, GLfloat x2, GLfloat y2, GLfloat z2);
[!endif]

#endif // !defined(APP_H_INCLUDED)

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