// [!output PROJECT_NAME].cpp
//
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "[!output PROJECT_NAME].h"
#include <stdio.h>
/////////////////////////////////////////////////////////////////////////////
// Global [!output APP_CLASS_NAME] object
[!output APP_CLASS_NAME] gApp;
/////////////////////////////////////////////////////////////////////////////
// [!output APP_CLASS_NAME] construction/destruction
[!output APP_CLASS_NAME]::[!output APP_CLASS_NAME]()
{
[!if CHK_OPENGL]
[!if CHK_SAMPLE]
m_fAngle = 0;
[!endif]
[!endif]
}
[!output APP_CLASS_NAME]::~[!output APP_CLASS_NAME]()
{
}
//
// PreCreateWindow()
// Called before the main window is created. Override this function to change window creation params.
//
void [!output APP_CLASS_NAME]::PreCreateWindow(WNDCLASSEX &wcex, DWORD &dwStyle, DWORD &dwExStyle, int &x, int &y, int &cx, int &cy)
{
CApp::PreCreateWindow(wcex, dwStyle, dwExStyle, x, y, cx, cy);
[!if APP_FULLSCREEN]
// Create a fullscreen window
dwStyle = WS_POPUP | WS_SYSMENU;
dwExStyle = WS_EX_TOPMOST;
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
[!endif]
[!if APP_ASK_FULLSCREEN]
// Ask if window should be fullscreen
if(MessageBox(0, "Run in fullscreen window?", "[!output PROJECT_NAME]", MB_YESNO | MB_ICONQUESTION)==IDYES)
{
dwStyle = WS_POPUP | WS_SYSMENU;
dwExStyle = WS_EX_TOPMOST;
cx = GetSystemMetrics(SM_CXSCREEN);
cy = GetSystemMetrics(SM_CYSCREEN);
}
[!endif]
// TODO : Modify parameters to change default window style and/or size
}
[!if CHK_OPENGL]
//
// PreCreateRC()
// Called before the OpenGL rendering context is created.
//
void [!output APP_CLASS_NAME]::PreCreateRC(PIXELFORMATDESCRIPTOR &pfd)
{
CApp::PreCreateRC(pfd);
// TODO : Modify pfd to change RC settings
}
[!endif]
//
// OnUpdateFPS()
// Called on regular intervals to indicate current frame rate
//
void [!output APP_CLASS_NAME]::OnUpdateFPS(float fFPS)
{
[!if CHK_FPS]
static char szFPS[256];
sprintf(szFPS, "%.1f FPS", fFPS);
SetWindowText(m_hWnd, szFPS); // Show FPS in caption
[!endif]
}
//
// OnCommand()
// Override this function to handle WM_COMMAND messages sent to the main window.
//
BOOL [!output APP_CLASS_NAME]::OnCommand(int nCmdID, int nEvent)
{
switch (nCmdID)
{
case IDM_EXIT:
SendMessage(m_hWnd, WM_CLOSE, 0, 0);
break;
[!if CHK_ABOUT]
case IDM_ABOUT:
ShowAboutDialog();
break;
[!endif]
default:
return CApp::OnCommand(nCmdID, nEvent); // Call default handler
}
return TRUE;
}
//
// WindowProc()
// Override this function to handle messages sent to the main window.
//
LRESULT [!output APP_CLASS_NAME]::WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return CApp::WindowProc(hWnd, message, wParam, lParam); // Call default WindowProc
}
//
// Tick()
[!if CHK_OPENGL]
// The applications "heartbeat" function. Called before another frame needs to be drawn.
// Override this function to calculate new positions for objects in the scene, for instance.
[!else]
// The applications "heartbeat" function. Called when the message queue is empty.
[!endif]
//
BOOL [!output APP_CLASS_NAME]::Tick()
{
[!if CHK_OPENGL]
[!if CHK_SAMPLE]
m_fAngle+= 1; // Add some rotation to the cube
[!endif]
return TRUE; // Return FALSE if the scene should not be redrawn
[!else]
return FALSE; // Return TRUE if the client area should be invalidated
[!endif]
}
[!if CHK_OPENGL]
//
// InitScene()
// Called when the OpenGL RC has been created. Sets initial state for the OpenGL scene.
//
void [!output APP_CLASS_NAME]::InitScene()
{
glClearColor([!output TXT_BG_R], [!output TXT_BG_G], [!output TXT_BG_B], 1.0f); //Background color
[!if CHK_SAMPLE]
// TODO: Replace the following sample code with your initialization code.
// Activate depth test, lighting and a light source
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
// Light position
GLfloat glfLight0[] = {-4.0f, 4.0f, 4.0f, 0.0f};
glLightfv(GL_LIGHT0, GL_POSITION, glfLight0);
// Define material parameters
static GLfloat fSpec[]= {1.0f, 1.0f, 1.0f, 1.0f};
static GLfloat fShin = 128.0f;
// Set material parameters
glMaterialfv(GL_FRONT, GL_SPECULAR, fSpec);
glMaterialf(GL_FRONT, GL_SHININESS, fShin);
// Set color
glEnable(GL_COLOR_MATERIAL);
glColor3f(0.0f, 0.1f, 0.6f);
[!else]
// TODO: Add scene initialization code
[!endif]
}
//
// KillScene()
// Called when the OpenGL RC is about to be destroyed.
//
void [!output APP_CLASS_NAME]::KillScene()
{
// TODO: Use KillScene to free resources.
}
//
// DrawScene()
// Called each time the OpenGL scene has to be drawn.
//
void [!output APP_CLASS_NAME]::DrawScene()
{
[!if CHK_SAMPLE]
// TODO: Replace the following sample code with your code to draw the scene.
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear buffers
glLoadIdentity(); // Load identity matrix
// Position and rotate the camera
glTranslatef(0.0f, 0.0f, -5.0f);
glRotatef(30.0f, 1.0f, 0.0f, 0.0f);
glRotatef(m_fAngle, 0.0f, 1.0f, 0.0f);
// Draw a cube
static GLfloat r = .7f;
GLCube(-r, -r, -r, r, r, r);
glFlush();
[!else]
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear buffers
glLoadIdentity(); // Load identity matrix
// TODO: Render OpenGL scene
glFlush();
[!endif]
}
[!else]
//
// OnPaint()
// Handles WM_PAINT messages.
//
void [!output APP_CLASS_NAME]::OnPaint(HDC hDC)
{
// TODO: Draw client area
}
[!endif]