首页 > 其他分享 >opentk第0章 chapter0

opentk第0章 chapter0

时间:2022-11-07 16:36:33浏览次数:32  
标签:code methods chapter0 will Step OpenTK opentk OnRenderFrame

Chapter 0: Learn OpenTK in 15' 第0章:在15年学习OpenTK So, you have downloaded the latest version of OpenTK - what now? 所以,现在你已经下载了最新版本的OpenTK - 接下来该怎么办? This is a short tutorial that will help you get started with OpenTK in 3 simple steps. 这是一个简短的教程,帮助你在简单的3步之内上手OpenTK。 [Step 1: Installation] 第一步:安装 Open the zip you downloaded and extract it to a folder of your choosing. I usually create a 'Projects' folder on my desktop or in my documents but any folder will do. [Step 2: Use OpenTK] Open the folder you just extracted. Inside, you will find three solutions: OpenTK.sln, Generator.sln and QuickStart.sln. The first two contain the OpenTK source code - no need to worry about them right now. The QuickStart solution is what we are interested in. Double-click QuickStart.sln. This will launch your .Net IDE (don't have a .Net IDE? Check out MonoDevelop or Visual Studio Express). Take a few moments to take in the contents of the QuickStart project:  Game.cs: this contains the code for the game. Scroll to the bottom: the Main() method is where everything begins.  References: click on the '+' sign to view the project references. The 'OpenTK' reference is the only one you need in order to use OpenTK. Now, press F5 to run the project. A window with a colored triangle will show up - not very interesting, is it? Press escape to close it. [Step 3: Play] Now it's time to start playing with the code. This is a great way to learn OpenGL and OpenTK at the same time. Every OpenTK game will contain 4 basic methods: 1. onl oad: this is the place to load resources from disk, like images or music. 2. OnUpdateFrame: this is a suitable place to handle input, update object positions, run physics or AI calculations. 3. OnRenderFrame: this contains the code that renders your graphics. It typically begins with a call to GL.Clear() and ends with a call to SwapBuffers. 4. OnResize: this method is called automatically whenever your game window changes size. Fullscreen applications will typically call it only once. Windowed applications may call it more often. In most circumstances, you can simply copy & paste the code from Game.cs. Why don't you try modifying a few things? Here are a few suggestions:1. Change the colors of the triangle or the window background (OnLoad and OnRenderFrame methods). 2. Make the triangle change colors when you press a key (OnUpdateFrame and OnRenderFrame methods). 3. Make the triangle move across the screen. Use the arrow keys or the mouse to control its position (OnUpdateFrame and OnRenderFrame methods). 4. Use a for-loop to render many triangles arranged on a plane (OnRenderFrame method). 5. Rotate the camera so that the plane above acts as ground (OnRenderFrame method). 6. Use the keyboard and mouse to walk on the ground. Make sure you can't fall through it! (OnUpdateFrame and OnRenderFrame methods). Some things you might find useful: Vector2, Vector3, Vector4 and Matrix4 classes for camera manipulations. Mouse and Keyboard properties for interaction with the mouse and keyboard, respectively. Joysticks property for interaction with joystick devices. Don't be afraid to try things and see the results. OpenTK lends itself to explorative programming - even if something breaks, the library will help you pinpoint the cause of the error. [Step: next] There's a lot of functionality that is not visible at first glance: audio, advanced opengl, display devices, support for GUIs through GLControl... Then there's the subject of proper engine and game design, which could cover a whole book by itself. Hopefully, you'll have gained a feel of the library by now and you'll be able to accomplish more complex tasks. You might wish to consult the complete documentation for the more advanced aspects of OpenTK and, of course, don't hesitate to post at the forums if you hit any roadblocks! 设置启动程序:

 

 

 

 

参考:

 

标签:code,methods,chapter0,will,Step,OpenTK,opentk,OnRenderFrame
From: https://www.cnblogs.com/2008nmj/p/16866403.html

相关文章