📄 lesson32.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 "NeHeGL.h" // Header File For NeHeGL
#include "particlesys.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;
/*
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
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;
// glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
/* glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
glEnable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient); // Setup The Ambient Light
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse); // Setup The Diffuse Light
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition); // Position The Light
glEnable(GL_LIGHT1); // Enable Light One
glColor4f(1.0f, 1.0f, 1.0f, 0.5); // Full Brightness. 50% Alpha
glBlendFunc(GL_SRC_ALPHA,GL_ONE); // Set The Blending Function For Translucency
// glEnable(GL_LIGHTING); // Enable Lighting
/*
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glEnable(GL_LIGHT0); // Quick And Dirty Lighting (Assumes Light0 Is Set Up)
glEnable(GL_LIGHTING); // Enable Lighting
glEnable(GL_COLOR_MATERIAL); // Enable Material Coloring
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
*/
/*
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glDepthFunc(GL_LEQUAL); // Type Of Depth Testing
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND); // Enable Blending (disable alpha testing)
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_CULL_FACE); // Remove Back Face
*/
/*
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glDepthFunc(GL_LEQUAL); // Type Of Depth Testing
glEnable(GL_DEPTH_TEST); // Enable Depth Testing
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Enable Alpha Blending (disable alpha testing)
glEnable(GL_BLEND); // Enable Blending (disable alpha testing)
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_CULL_FACE); // Remove Back Face
//*/
/* 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
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);
glDisable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D); // Enable Texture Mapping
glEnable(GL_CULL_FACE); // Remove Back Face
*/
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
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
InitEngine();
#ifdef Music_On
InitMusic();
LoadMP3("music.mp3");
PlayMP3();
#endif
return TRUE; // Return TRUE (Initialization Successful)
}
void Deinitialize (void) // Any User DeInitialization Goes Here
{
#ifdef Music_On
UnloadMusic();
DoneMusic();
#endif
DeInitEngine();
}
void LoadPureModelWindows(HWND LB_Parent_Hwnd) // L鋎t ne .dat
{
OPENFILENAME ofn; /* common dialog box structure */
char szDirName[MAX_PATH]; /* directory string */
char szFile[4096]; /* filename string */
char szFileTitle[4096]; /* filename string */
/*
hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
*/
/*
Obtain the system directory name and store it in szDirName.
*/
GetSystemDirectory(szDirName, sizeof(szDirName));
/*
Place the terminating null character in the szFile.
*/
szFile[0] = '\0';
/*
Set the members of the OPENFILENAME structure.
*/
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = LB_Parent_Hwnd;
ofn.lpstrTitle = "Load Model File\0";
ofn.lpstrFilter = "B-Clopd3D Model Files (*.B3D)\0*.B3D\0All files (*.*)\0*.*\0\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 2048;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = 2048;
ofn.lpstrInitialDir = ".\0";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
/*
Display the Open dialog box.
*/
if (GetOpenFileName(&ofn))
{
char *path = ofn.lpstrFile;
char *fname = ofn.lpstrFile;
char *outp;
// LoadPureModel(fname);
LoadModelToObj(fname);
};
}
void SaveAnimationWindows(HWND LB_Parent_Hwnd) // Saved n Model
{
OPENFILENAME ofn; /* common dialog box structure */
char szDirName[MAX_PATH]; /* directory string */
char szFile[4096]; /* filename string */
char szFileTitle[4096]; /* filename string */
/*
hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
*/
/*
Obtain the system directory name and store it in szDirName.
*/
GetSystemDirectory(szDirName, sizeof(szDirName));
/*
Place the terminating null character in the szFile.
*/
szFile[0] = '\0';
/*
Set the members of the OPENFILENAME structure.
*/
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = LB_Parent_Hwnd;
ofn.lpstrTitle = "Save Animation File\0";
ofn.lpstrFilter = "B-Clopd3D Animation Files (*.ANI)\0*.ANI\0All files (*.*)\0*.*\0\0";
ofn.lpstrCustomFilter = NULL;
ofn.nFilterIndex = 1;
ofn.lpstrFile = szFile;
ofn.nMaxFile = 2048;
ofn.lpstrFileTitle = szFileTitle;
ofn.nMaxFileTitle = 2048;
ofn.lpstrInitialDir = ".\0";
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST /*| OFN_ALLOWMULTISELECT*/;
/*
Display the Open dialog box.
*/
if (GetSaveFileName(&ofn))
{
char *path = ofn.lpstrFile;
char *fname = ofn.lpstrFile;
char *outp;
SaveDaAnimation(fname);
};
}
void LoadAnimationWindows(HWND LB_Parent_Hwnd) // L鋎t ne .dat
{
OPENFILENAME ofn; /* common dialog box structure */
char szDirName[MAX_PATH]; /* directory string */
char szFile[4096]; /* filename string */
char szFileTitle[4096]; /* filename string */
/*
hinst = (HINSTANCE)GetWindowLong(hwnd, GWL_HINSTANCE);
*/
/*
Obtain the system directory name and store it in szDirName.
*/
GetSystemDirectory(szDirName, sizeof(szDirName));
/*
Place the terminating null character in the szFile.
*/
szFile[0] = '\0';
/*
Set the members of the OPENFILENAME structure.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -