資源簡介
Name: ReadDepth
Desc: 通過讀取Z Buffer深度值將屏幕2D坐標轉化為場景3D坐標
操作:點擊鼠標左鍵,在標題欄上會顯示深度值和轉化后的場景3D坐標

代碼片段和文件信息
/*
???????written?by?SM3Dbase?on?NeHe‘s?simple?basecode.
???welcome?to?visit?my?website:http://sm3d.126.com
*/
/*
?* This?Code?Was?Created?By?Jeff?Molofee?2000
?* A?HUGE?Thanks?To?Fredric?Echols?For?Cleaning?Up
?* And?Optimizing?This?Code?Making?It?More?Flexible!
?* If?You‘ve?Found?This?Code?Useful?Please?Let?Me?Know.
?* Visit?My?Site?At?nehe.gamedev.net
?*/
#include? //?Header?File?For?Windows
#include?
#include? //?Header?File?For?The?OpenGL32?Library
#include? //?Header?File?For?The?GLu32?Library
#include? //?Header?File?For?The?Glaux?Library
#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?“glaux.lib“?) //?Search?For?GLaux.lib?While?linking
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
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
GLint?viewport[4];
GLdouble?modelview[16];
GLdouble?projection[16];
GLfloat?winXwinYwinZ;
GLdouble?object_xobject_yobject_z;
int?mouse_xmouse_y;
char?str[80];
LRESULT CALLBACK?WndProc(HWND?UINT?WPARAM?LPARAM); //?Declaration?For?WndProc
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
}
glViewport(00widthheight); //?Reset?The?Current?Viewport
glMatrixMode(GL_PROJECTION); //?Select?The?Projection?Matrix
glLoadIdentity(); //?Reset?The?Projection?Matrix
//?Calculate?The?Aspect?Ratio?Of?The?Window
gluPerspective(45.0f(GLfloat)width/(GLfloat)height0.1f100.0f);
glMatrixMode(GL_MODELVIEW); //?Select?The?Modelview?Matrix
glLoadIdentity(); //?Reset?The?Modelview?Matrix
}
int?InitGL(GLvoid) //?All?Setup?For?OpenGL?Goes?Here
{
glShadeModel(GL_SMOOTH); //?Enable?Smooth?Shading
glClearColor(0.0f?0.0f?0.0f?0.0f); //?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_LIGHTING);
glEnable(GL_LIGHT0);
return?TRUE; //?Initialization?Went?OK
}
int?DrawGLScene(GLvoid) //?Here‘s?Where?We?Do?All?The?Drawing
{
glClear(GL_COLOR_BUFFER_BIT?|?GL_DEPTH_BUFFER_BIT); //?Clear?Screen?And?Depth?Buffer
glLoadIdentity();???????????????????????????????????//?Reset?T
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????53760??2005-10-16?21:47??ReadDepth\ReadDepth.opt
?????文件????????520??2004-12-17?15:22??ReadDepth\ReadDepth.dsw
?????文件??????50176??2005-10-16?21:47??ReadDepth\ReadDepth.ncb
?????文件???????1164??2005-10-16?17:54??ReadDepth\ReadDepth.plg
?????文件???????3945??2004-12-19?17:12??ReadDepth\ReadDepth.dsp
?????文件??????16891??2005-10-16?17:53??ReadDepth\main.cpp
?????文件?????221282??2005-10-16?17:54??ReadDepth\ReadDepth.exe
?????文件????????243??2005-10-16?21:51??ReadDepth\readme.txt
?????目錄??????????0??2005-10-16?21:47??ReadDepth
-----------?---------??----------?-----??----
???????????????348199????????????????????10
- 上一篇:240128液晶源程序
- 下一篇:51單片機作為i2c從設備加密芯片+紅外+串口
評論
共有 條評論