📄 ionteam.cpp
字号:
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// 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.5 ; website: http://www.fmod.org
/////////////////////////////////////////////////////////////////////////////////////////////////////////
#define PI 3.1415926535897932384626433832795
#define NUMBER_OF_FLAGS 12
#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 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;
float TickCount;
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_PFAC3,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 what BPP was choosed
if(IsDlgButtonChecked(hDlg,ID_PFAC1)) ParticleFraction = 0.0f;
else if(IsDlgButtonChecked(hDlg,ID_PFAC2)) ParticleFraction = 0.5f;
else if(IsDlgButtonChecked(hDlg,ID_PFAC3)) ParticleFraction = 1.0f;
else if(IsDlgButtonChecked(hDlg,ID_PFAC4)) ParticleFraction = 2.0f;
//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;
glViewport(0,0,width,height); // Reset The Current Viewport
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
{
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CW);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_COLOR);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.7f);
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
ShowCursor(FALSE); //hide cursor
LightManager.Enable(GL_LIGHT1);
FreeImage_Initialise();
fpvCam.Start(-10.0f,0,0,10,0,0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
Loading.Init(hDC);
Standart.Init("Data/Images/font.bmp",14);
SM.NewScene(100000.0f,&ShireSceneInit,&ShireSceneDeInit,&ShireSceneRenderNextFrame);
SM.NewScene(68000.0f,&BagEndInit,&BagEndDeInit,&BagEndRenderNextFrame);
SM.NewScene(75000.0f,&MordorSceneInit,&MordorSceneDeInit,&MordorSceneRenderNextFrame);
SM.NewScene(123000.0f,&CastleSceneInit,&CastleSceneDeInit,&CastleSceneRenderNextFrame);
//SM.NewScene(20000.0f,&ScrollInit,&ScrollEnd,&ScrollDraw);
Loading.RestoreMatrix();
SM.InitScenes();
TickCount=timeGetTime();
LightManager.EnableLights();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CW);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_COLOR);
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER,0.7f);
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
ShowCursor(FALSE); //hide cursor
return TRUE; // Initialization Went OK
}
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing and, alas, updating
{
static float temptime, TotalTime=0.0f;
float Milliseconds;
Milliseconds=TickCount;
TickCount=(float)timeGetTime();
Milliseconds=TickCount-Milliseconds;
TotalTime+=Milliseconds;
/// DRAWING
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
SM.NextFrame(Milliseconds);
//***********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);
}
hRC=NULL; // Set RC To NULL
}
if (hDC && !ReleaseDC(hWnd,hDC)) // Are We Able To Release The DC
{
MessageBox(NULL,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hDC=NULL; // Set DC To NULL
}
if (hWnd && !DestroyWindow(hWnd)) // Are We Able To Destroy The Window?
{
MessageBox(NULL,"Could Not Release hWnd.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hWnd=NULL; // Set hWnd To NULL
}
if (!UnregisterClass("OpenGL",hInstance)) // Are We Able To Unregister Class
{
MessageBox(NULL,"Could Not Unregister Class.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION);
hInstance=NULL; // Set hInstance To NULL
}
}
////////////////////////////////////////////////////////////////////////
//standard NeHE code
///////////////////////////
/* This Code Creates Our OpenGL Window. Parameters Are: *
* title - Title To Appear At The Top Of The Window *
* width - Width Of The GL Window Or Fullscreen Mode *
* height - Height Of The GL Window Or Fullscreen Mode *
* bits - Number Of Bits To Use For Color (8/16/24/32) *
* fullscreenflag - Use Fullscreen Mode (TRUE) Or Windowed Mode (FALSE) */
BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
GLuint PixelFormat; // Holds The Results After Searching For A Match
WNDCLASS wc; // Windows Class Structure
DWORD dwExStyle; // Window Extended Style
DWORD dwStyle; // Window Style
RECT WindowRect; // Grabs Rectangle Upper Left / Lower Right Values
WindowRect.left=(long)0; // Set Left Value To 0
WindowRect.right=(long)width; // Set Right Value To Requested Width
WindowRect.top=(long)0; // Set Top Value To 0
WindowRect.bottom=(long)height; // Set Bottom Value To Requested Height
fullscreen=fullscreenflag; // Set The Global Fullscreen Flag
hInstance = GetModuleHandle(NULL); // Grab An Instance For Our Window
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; // Redraw On Size, And Own DC For Window.
wc.lpfnWndProc = (WNDPROC) WndProc; // WndProc Handles Messages
wc.cbClsExtra = 0; // No Extra Window Data
wc.cbWndExtra = 0; // No Extra Window Data
wc.hInstance = hInstance; // Set The Instance
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -