📄 maingamelevel.cpp
字号:
/**************************************
* *
* Jeff Molofee's Picking Tutorial *
* nehe.gamedev.net *
* 2001 *
* *
**************************************/
#include <windows.h> // Header File For Windows
#include <stdio.h> // Header File For Standard Input / Output
#include <stdarg.h> // Header File For Variable Argument Routines
#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 <time.h> // For Random Seed
#include "MainNeHeLevel.h" // Header File For NeHeGL
#include "LevelEdit.h"
#include "vectors.h"
#include "maindefs.h"
#include "systemio.h"
#pragma comment( lib, "opengl32.lib" ) // Search For OpenGL32.lib While Linking
#pragma comment( lib, "glu32.lib" ) // Search For GLu32.lib While Linking
#pragma comment( lib, "winmm.lib" ) // Search For WinMM Library While Linking
//#define Music_On
#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.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
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
// glClearColor(0.9f, 0.9f, 0.9f, 0.5f); // Black Background
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
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // 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
Init_Engine(window);
#ifdef Music_On
InitMusic();
LoadMP3("music.mp3");
PlayMP3();
#endif
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,K,M,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,WindowHandle);
}
void Update (DWORD milliseconds) // Perform Motion Updates Here
{
long I,K,M,D;
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;
MyTimer+=milliseconds;
MainLoop(g_window->hWnd);
}
void Draw (void)
{
DrawScene();
glFlush (); // Flush The GL Rendering Pipeline
FramesDrawn++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -