270 likes | 470 Views
Windows Programming Basic & OpengGL Under Win32. 戴明仁 200 40517. 要學會 Windows 程式設計,最快需要花上六個月的時間 -- Charles Petzold (author of Programming Windows). Win32 API Programming. An event driven system model Only requires basic skills of C language programming
E N D
Windows Programming Basic &OpengGL Under Win32 戴明仁 20040517
要學會Windows程式設計,最快需要花上六個月的時間要學會Windows程式設計,最快需要花上六個月的時間 -- Charles Petzold (author of Programming Windows)
Win32 API Programming • An event driven system model • Only requires basic skills of C language programming • The bottom layer of MFC ,VCL…etc. Let’s begin Win32 programming using MSVC6.0!
Step 2 : Set Project Properties 3.Enter project name 2.Specify project location 1.choose “Win32 Application”
Step 3 : Choose Project Template We choose this in our tutorial Then choose Finish and OK….A new project has been created!
Step 4 : VC 6.0 IDE Overview Toolbars Code Edit Window Fileview Resourceview Classview Debug and other window
Step 5 : The WinMain() Function • The entry point of a Win32 program , such as main() in a console mode program. • Do windows initializations here. • A message loop is in the function , grabbing messages and send it to message dispatcher -- WndProc( Window Procedure )
Step 6 : Message Dispatcher– WndProc() • Every Windows message comes to here • We write codes here to perform some tasks to achieve our goals. • For Example : • If user presses a key , then a WM_KEYDOWN message will be received. • Check references to see more details about win32 programming.
References • Programming Windows 5th edition by Charles Petzold. Microsoft Press. • Windows 程式設計實務 by 施威銘 旗標
Using OpenGL under Windows-1 • Install OpenGL library Check OpenGL website for latest version of OpenGL library,download and install it. http://www.opengl.org/documentation/implementations.html
Using OpenGL under Windows-2 • Setup VC environment.
Using OpenGL under Windows-3 • Link your program with OpenGL libraries. Congratulations!You now can write OpenGL programs!
Reference • Official OpenGL website http://www.opengl.org • NeHe -- Very good OpenGL tutorials http://nehe.gamedev.net/ • NeHe Chinese version http://www.geocities.com/SiliconValley/Vista/8177/tutorial/nehe.htm • OpenGL Programming Guide 3th edition • OpenGL 超級手冊(碁峰)
Why use Win32 instead of GLUT • Win32 applications is faster. • Win32 is the base of GLUT. • Under Win32,user can manipulate any messages very easily and efficiently. • We can integrate other useful stuff (such as DirectX ) into Win32 applications.
What is kglApp? • A framework for Win32 and OpenGL • A simplest kglApp contains these files: Double click the workspace file to open kglApp project
What’s in kglApp? 1)Open kglWinGL.h 2)Some configurations that user can modify 3)The main rendering function that user must override itself.
OpenGL Initial Function Put OpenGL initialization code here.
OpenGL Resize Function • Called when user resize the window.
Keyboard Message Manipulate • Place code here to do some thing when some key is pressed
Windows Virtual Key Codes • In the above example, VK_F1 is virtual key code defined in Win32 API which represents the F1 key in the keyboard. • You can check MSDN ( http://msdn.microsoft.com ) for more information about Win32 virtual key codes.
Custom Setup Function • Put any initialize code other then OpenGL here
The Main Rendering Loop 2)The rendering loop.Draw anything you like here. 1)Open main.cpp
Hope there will be another Quake 3 from you... Goodbye….XD!