📄 maingame.cpp
字号:
/**************************************
* *
* Jeff Molofee's Picking Tutorial *
* nehe.gamedev.net *
* 2001 *
* *
**************************************/
#include <windows.h> // Header File For Windows
#include <gl\gl.h> // Header File For The OpenGL32 Library
#include <gl\glu.h> // Header File For The GLu32 Library
#include <gl\glaux.h> // Header File For The GLu32 Library
#include "MainNeHe.h" // Header File For NeHeGL
#include "Game.h"
#include "vectors.h"
#include "systemio.h"
#pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking
#ifndef CDS_FULLSCREEN // CDS_FULLSCREEN Is Not Defined By Some
#define CDS_FULLSCREEN 4 // Compilers. By Defining It This Way,
#endif // We Can Avoid Errors
GL_Window* g_window;
Keys* g_keys;
// User Defined Variables
float xRotation;
float yRotation;
float zRotation;
int rot1, rot2; // Counter Variables
long MyTimer;
long GlobalTime=0;
long FramesDrawn=0;
/*
GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 0.0f, 0.0f, 2.0f, 1.0f };
*/
GLfloat LightAmbient[] = { 0.2f, 0.2f, 0.2f}; // Ambient Light is 20% white
GLfloat LightDiffuse[] = { 1.0f, 1.0f, 1.0f}; // Diffuse Light is white
GLfloat LightPosition[] = { 0.0f, 0.0f, 2.0f}; // Position is somewhat in front of screen
GLuint fogMode[]= { GL_EXP, GL_EXP2, GL_LINEAR }; // Storage For Three Types Of Fog
GLuint fogfilter = 2; // Which Fog Mode To Use
//GLfloat fogColor[4] = {0.5f,0.5f,0.5f,1.0f}; // Fog Color
GLfloat fogColor[4] = {0.0f,0.0f,0.0f,0.5f}; // Fog Color
BOOL Initialize (GL_Window* window, Keys* keys) // Any GL Init Code & User Initialiazation Goes Here
{
g_window = window;
g_keys = keys;
mouse_klick=0;
MyTimer=0;
// Start Of User Initialization
xRotation = 0.0f;
yRotation = 0.0f;
zRotation = 0.0f;
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
/*
glDisable(GL_SCISSOR_TEST);
glDisable(GL_STENCIL_TEST);
*/
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); // Really Nice Perspective Calculations
glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST); // Really Nice Perspective Calculations
glHint(GL_POLYGON_SMOOTH_HINT, GL_FASTEST); // Really Nice Perspective Calculations
// glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
// glBlendFunc(GL_SRC_ALPHA, GL_ONE); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_CULL_FACE); // Remove Back Face
glEnable(GL_DEPTH_TEST); // Enables DePth Testing
glDisable(GL_NORMALIZE);
glDisable(GL_DITHER);
// glClearStencil(0);
/*
glFogi(GL_FOG_MODE, fogMode[fogfilter]); // Fog Mode
glFogfv(GL_FOG_COLOR, fogColor); // Set Fog Color
glFogf(GL_FOG_DENSITY, 0.3f); // How Dense Will The Fog Be
// glHint(GL_FOG_HINT, GL_NICEST); // Fog Hint Value
glHint(GL_FOG_HINT, GL_DONT_CARE); // Fog Hint Value
glFogf(GL_FOG_START, 100.0f); // Fog Start Depth
glFogf(GL_FOG_END, 300.0f); // Fog End Depth
//glFogCoordf
*/
MyTimer=0;
return TRUE; // Return TRUE (Initialization Successful)
}
void Deinitialize (void) // Any User DeInitialization Goes Here
{
#ifdef Music_On
UnloadMusic();
DoneMusic();
#endif
DeInit_Engine();
}
void MainLoop(HWND WindowHandle)
{
long FpS=50;
long I,FramesToDo;
MainWindow=WindowHandle;
if(mouse_klick<0) mouse_klick=0;
for(I=0;I<200;I++)
KeyAction(I,g_keys->keyDown[I]);
FramesToDo=MyTimer/(1000/FpS);
MyTimer-=FramesToDo*(1000/FpS);
if(FramesToDo>0) CalcAllStuff(FramesToDo);
}
void Update (DWORD milliseconds) // Perform Motion Updates Here
{
// if (g_keys->keyDown [VK_F12] == TRUE) // Is ESC Being Pressed?
if(QuitGameBool)
{
TerminateApplication (g_window); // Terminate The Program
}
/*
if (g_keys->keyDown [VK_ESCAPE] == TRUE) // Is ESC Being Pressed?
{
TerminateApplication (g_window); // Terminate The Program
}
if (g_keys->keyDown [VK_F1] == TRUE) // Is F1 Being Pressed?
{
ToggleFullscreen (g_window); // Toggle Fullscreen Mode
}
*/
xRotation += (float)(milliseconds) / 10.0f;
yRotation += (float)(milliseconds) / 7.0f;
zRotation += (float)(milliseconds) / 5.0f;
if((GlobalTime/1000)!=((GlobalTime+milliseconds)/1000))
{
FramesPS=FramesDrawn;
FramesDrawn=0;
}
GlobalTime+=milliseconds;
if(MyTimer!=0) {MyTimer+=milliseconds;} else {MyTimer+=1;}
MainLoop(g_window->hWnd);
}
void Draw (void)
{
// glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
DrawScene();
FramesDrawn++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -