📄 ionteam.cpp.orig
字号:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// This code has been based on NeHe's Tutorials base code
// Addicional code by P{u}ta and HiperBlaster
// Using FreeImage 2.3.0,an Open Source image library; website: http://www.6ixsoft.com
// Using FMOD v3.2 ; website: http://www.fmod.org
// Using tools from Stefan Hajnoczi in map systems; website : http://www.uio.no/~stefanha/
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//I hope this is enough :)
#define PI 3.1415926535897932384626433832795
#include "Dependencies.h"
#include "resource.h" //dialog box
HDC hDC=NULL; // Private GDI Device Context
HGLRC hRC=NULL; // Permanent Rendering Context
HWND hWnd=NULL; // Holds Our Window Handle
HINSTANCE hInstance; // Holds The Instance Of The Application
//timing related
DWORD time; //TEMP : fps limiter
char GFramesPerSecond[50];
int fps=0; //used for timer
//nehe framework
bool Keys[256]; // Array Used For The Keyboard Routine
bool active=TRUE; // Window Active Flag Set To TRUE By Default
bool fullscreen=TRUE; // Fullscreen Flag Set To Fullscreen Mode By Default
//scrshot vars
int scrheight;
int scrwidth;
//filled by the start dialog
int ResolutionX = 640;
int ResolutionY = 480;
int BPP = 16;
bool Music = TRUE;
bool ShowFPS = TRUE;
CCamera fpvCam;
BezCam BCam(0.01f,0.75f);
CSkyBox SkyBox;
CMap Map;
CLightMan LightManager;
Md2Model HobbitResting;
Vector3d MapScale(1.0f,1.0f,1.0f),Md2Scale(0.1f,0.1f,0.1f);
POINT Mouse; //mouse handling, remove in the final release
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); // Declaration For WndProc
//timer callback
VOID CALLBACK TimerProc(HWND hWnd,UINT iMsg,UINT idEvent,DWORD dwTime);
////////////////////////////////////////////////////////////////////////
//This is the initial dialog procedure code
BOOL CALLBACK DialogProc(HWND hDlg, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch(iMsg)
{
case WM_INITDIALOG:
{
//Start DialogBox with some buttons checked
CheckDlgButton(hDlg,ID_RES1,BST_CHECKED);
CheckDlgButton(hDlg,ID_BPP1,BST_CHECKED);
CheckDlgButton(hDlg,ID_FULLSCREEN,BST_CHECKED);
CheckDlgButton(hDlg,ID_MUSIC,BST_CHECKED);
CheckDlgButton(hDlg,ID_FPS,BST_CHECKED);
SetFocus(GetDlgItem(hDlg,ID_OK));
return FALSE;
}
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case ID_OK: //If OK button is pressed
{
//Check what resolution was choosed
if(IsDlgButtonChecked(hDlg,ID_RES1))
{
ResolutionX = 640;
ResolutionY = 480;
}
else if(IsDlgButtonChecked(hDlg,ID_RES2))
{
ResolutionX = 800;
ResolutionY = 600;
}
else if(IsDlgButtonChecked(hDlg,ID_RES3))
{
ResolutionX = 1024;
ResolutionY = 768;
}
//Check what BPP was choosed
if(IsDlgButtonChecked(hDlg,ID_BPP1))
BPP = 16;
else if(IsDlgButtonChecked(hDlg,ID_BPP2))
BPP = 32;
//Check if fullscreen is enable
if(IsDlgButtonChecked(hDlg,ID_FULLSCREEN))
fullscreen = TRUE;
else
fullscreen = FALSE;
//Check if music is enable
if(IsDlgButtonChecked(hDlg,ID_MUSIC))
Music = TRUE;
else
Music = FALSE;
//Check if FPS is enable
if(IsDlgButtonChecked(hDlg,ID_FPS))
ShowFPS = TRUE;
else
ShowFPS = FALSE;
EndDialog(hDlg,TRUE);
return 0;
}
case ID_CANCEL: // If cancel button is pressed
{
EndDialog(hDlg,FALSE);
return 0;
}
}
break;
}
}
return FALSE;
}
GLvoid ReSizeGLScene(GLsizei width, GLsizei height) // Resize And Initialize The GL Window
{
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
//save for scrshot
scrheight=height;
scrwidth=width;
//gives errors when using mesa, so don't touch the window :)
#ifndef MESA
glViewport(0,0,width,height); // Reset The Current Viewport
#endif
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
gluPerspective(90.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
}
void ScrShot()
{
FIBITMAP *image=FreeImage_Allocate(scrwidth,scrheight,32);
unsigned char *data = FreeImage_GetBits(image);
//using BGRA, maybe some problems with old cards ?
glReadPixels(0,0,scrwidth,scrheight,GL_BGRA_EXT,GL_BYTE,(void*)data);
//
FILE *file;
int number=0;
char string[80];
for(;;)
{
sprintf(string,"ScrShot%i.bmp",number);
file = fopen(string,"r");
if(file==0)
break;
fclose(file);
number++;
}
//
FreeImage_SaveBMP(image,string);
FreeImage_Free(image);
}
int InitGL(GLvoid) // All Setup For OpenGL Goes Here
{
// glHint(GL_POLYGON_SMOOTH_HINT,GL_NICEST);
// Sound.Init(); //start sound sys
// int a = Sound.LoadMP3("D:/receive.mp3",1); //load mp3 and keep a reference
// Sound.PlayStream(a); //play the reference
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CW);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_COLOR);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f,0.0f,0.0f,0.0f); // We'll Clear To The Color Of The Fog
glClearDepth(1.0f); // Depth Buffer Setup
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
//timer
ShowCursor(FALSE); //hide cursor
LightManager.EnableLights();
LightManager.Enable(GL_LIGHT1);
LightManager.SetDiffuseColor(GL_LIGHT1,1,1,1,1);
//glFogf(GL_FOG_MODE,GL_LINEAR);
//glFogf(GL_FOG_DENSITY,0.01f);
//glEnable(GL_FOG);
FreeImage_Initialise();
Map.Init("Data/nshire12.cmf");
SkyBox.Init("Data/CSkyBox/TrainYard","jpg");
fpvCam.Start(-10.0f,0,0,10,0,0);
HobbitResting.Load("Data/ModelsAndSkins/Hobbit/Hobbit.md2","Data/ModelsAndSkins/Hobbit/Bilbo.jpg");
BCam.LoadFromFile("Data\\record.path");
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing and, alas, updating
{
static float TickCount, temptime;
static bool Record=true, DrawPath=true;
float Milliseconds;
Milliseconds=TickCount;
TickCount=(float)timeGetTime();
Milliseconds=TickCount-Milliseconds;
temptime+=Milliseconds;
if (Keys[VK_F5])ScrShot();
if(Keys[VK_NUMPAD4])
fpvCam.Strafe(-0.2f);
if(Keys[VK_NUMPAD6])
fpvCam.Strafe(0.2f);
if(Keys[VK_NUMPAD8])
fpvCam.Walk(0.2f);
if(Keys[VK_NUMPAD0])
fpvCam.Walk(-0.2f);
if(Keys[VK_NUMPAD3])
fpvCam.Fly(0.2f);
if(Keys[VK_RETURN])
fpvCam.Fly(-0.2f);
if(temptime>200.0f)
{
if(Keys[VK_INSERT])
fpvCam.StartRecord("Data\\record.path");
if (Keys[VK_HOME])
fpvCam.RecordFrame();
if(Keys[VK_DELETE])
fpvCam.EndRecord();
temptime=0.0f;
}
if (Keys[VK_END])
{
BCam.ClearCurves();
BCam.LoadFromFile("Data\\record.path");
}
if (Keys[VK_BACK])
{
BCam.CurrentObjectPoint=BCam.CurrentOriginPoint=0;
BCam.CurrentObjectPointCounter=BCam.CurrentOriginPointCounter=0.0f;
}
if (Keys[VK_CONTROL])
(Record==true) ? Record=false : Record=true;
if (Keys[VK_SPACE])
(DrawPath==true) ? DrawPath=false : DrawPath=true;
if (Record)
{
GetCursorPos(&Mouse); //grab mouse and use the values for cammera rotation
fpvCam.RotateY((float)((320-Mouse.x ))/20.0f);
fpvCam.RotateX((float)((240-Mouse.y ))/20.0f);
if(Mouse.x!=320)
SetCursorPos(320,240);
else if(Mouse.y!=240)
SetCursorPos(320,240);
}
/// DRAWING
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
if (Record)
{
fpvCam.PositionSkyBox();
SkyBox.Render();
glLoadIdentity();
fpvCam.Position();
}
else
{
BCam.LookAtNextPoint(Milliseconds*0.05);
BCam.PositionSkybox();
SkyBox.Render();
glLoadIdentity();
BCam.Position();
}
LightManager.SetPosition(GL_LIGHT1,-3.0f,54.0f,-16.0f);
Map.Draw();
glPushMatrix();
glTranslatef(20.0f,0.3f,1.1f);
glScalef(0.03f,0.03f,0.03f);
glRotatef(-90.0f,0,1,0);
glRotatef(20.0f,1,0,0);
HobbitResting.Draw(62);
glPopMatrix();
glPushMatrix();
glTranslatef(20.0f,0.3f,1.1f);
glScalef(0.03f,0.03f,0.03f);
glRotatef(-90.0f,0,1,0);
glRotatef(20.0f,1,0,0);
HobbitResting.Draw(62);
glPopMatrix();
if (DrawPath)
{
BCam.DrawCurves();
BCam.DrawPoints();
}
//***********Demo*Code*There****************************
glFlush ();
return TRUE; // Keep Going
}
GLvoid KillGLWindow(GLvoid) // Properly Kill The Window
{
if (fullscreen) // Are We In Fullscreen Mode?
{
ChangeDisplaySettings(NULL,0); // If So Switch Back To The Desktop
ShowCursor(TRUE); // Show Mouse Pointer
}
if (hRC) // Do We Have A Rendering Context?
{
if (!wglMakeCurrent(NULL,NULL)) // Are We Able To Release The DC And RC Contexts?
{
MessageBox(NULL,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
}
if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC?
{
MessageBox(NULL,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -