www.pudn.com > 林海血原源代码.zip > 3dExplorer.cpp
// 3dExplorer.cpp : Defines the entry point for the application.
///////////////////////////////////////////////
//作者:吴雪平 2002-6-17日修改
//管理整个程序运行
#include "stdafx.h"
#include "CGL.h"
#include "heightmapscene.h"
///////////////////////////////////////////////
INPUT Input;
CGL cGL;
//CAudioPlay cAudioPlay; //need for dx8.0
CHeightmapScene m_cHeightmapScene;
///////////////////////////////////////////////
bool InitEngine()
{
/*f(!cAudioPlay.InitAudioPlay())
{
AudioOk=false;
MessageBox(0, "cAudioPlay error", "Error", MB_OK | MB_ICONERROR);
}
*/
if(!m_cHeightmapScene.InitHeightmapScene(&Input))
{
MessageBox(0, "cText error // 3dExplorer.cpp ", "Error", MB_OK | MB_ICONERROR);
return FALSE;
}
return true;
}
GLvoid DrawGLScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
////////////////////////////////
m_cHeightmapScene.RenderHeightmapScene();
////////////////////////////
}
LRESULT CALLBACK WndProc( HWND hWnd,
UINT message,
WPARAM wParam,
LPARAM lParam)
{
// Used later on to get the size of the window
// Tells Windows we want to check the message
switch (message)
{
case WM_CREATE: // Window creation
if (!cGL.InitGL(800,600,1,hWnd))
{ // Init failed
cGL.DestroyGL(); // Shutdown GL
PostQuitMessage(0); // Exit programm
}
ShowCursor(FALSE); // Hide mouse
break;
case WM_DESTROY: // Windows being destroyed
case WM_CLOSE: // Windows being closed
cGL.DestroyGL(); // Shutown GL
ShowCursor(TRUE); // Show mouse
PostQuitMessage(0); // Quit the program
break;
case WM_KEYDOWN: // Key Being Held Down
Input.keys[wParam] = true;
break;
case WM_KEYUP: // Key Is Released
Input.keys[wParam] = false;
break;
case WM_LBUTTONDOWN: // Left mouse button is pressed
Input.mouseButtons[0]=true;
break;
case WM_LBUTTONUP: // Left mouse button is pressed
Input.mouseButtons[0]=false;
break;
case WM_RBUTTONDOWN:
// Right mouse button is pressed
// cGL.ChangeFOVAngle(1);
Input.mouseButtons[1]=true;
break;
case WM_RBUTTONUP:
cGL.ChangeFOVAngle(0);
// Right mouse button is pressed
Input.mouseButtons[1]=false;
break;
case WM_MOUSEMOVE:
Input.mousePos.x = LOWORD(lParam); // Position of the cursor
Input.mousePos.y = HIWORD(lParam);
break;
case WM_SIZE: // Resizing the screen
cGL.Resize(LOWORD(lParam),HIWORD(lParam));
break;
default:
// Pass windows messages
return (DefWindowProc(hWnd, message, wParam, lParam));
}
return (0);
}
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg; // Windows message structure
WNDCLASS wc; // Windows class structure used to set up the type of window
HWND hWnd; // Storage for window handle
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC) WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = NULL;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = "3dExplorer";
if(!RegisterClass(&wc))
{
MessageBox(0, "Failed to register the window class", "Error", MB_OK | MB_ICONERROR);
return FALSE;
}
hWnd = CreateWindow(
"3dExplorer",
"Exploring in 3D world !", // Title appearing at the top of the window
WS_POPUP |
WS_CLIPCHILDREN |
WS_CLIPSIBLINGS,
0, // The position of the window on the screen
0,
800, // The width and height of the window
600,
NULL,
NULL,
hInstance,
NULL);
if (!hWnd)
{
MessageBox(0, "Window creation error", "Error", MB_OK | MB_ICONERROR);
return FALSE;
}
ShowWindow(hWnd, SW_SHOW);
UpdateWindow(hWnd);
SetFocus(hWnd);
if(!InitEngine())
{
MessageBox(0, "InitEngine error", "Error", MB_OK | MB_ICONERROR);
return FALSE;
}
while (1)
{
// Process All Messages
while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE))
{
if (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
else
{
return TRUE;
}
}
DrawGLScene();
cGL.SwapBuffers();
//按鼠标右键放大
if(Input.mouseButtons[1])cGL.ChangeFOVAngle(1);
//按ESC键退出
if (Input.keys[VK_ESCAPE]) SendMessage(hWnd, WM_CLOSE, 0, 0);
}
return 0;
}