<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Game Loop Tutorial

      Game Loop Tutorial

      In this article I talk about the basic high-level structure of a typical Managed Direct3D application. Most Direct3D applications will have code that looks something like this.

      Let's face it: most people that are using Direct3D are probably doing it because they want to write a game. So it makes sense that the typical, top-level structure of a Managed Direct3D application would be called the "Game Loop". (I stole the term from the mediocre book The Zen of Direct3D Game Programming.) This code or a variant of it will appear in many Managed Direct3D applications, including the sample code that Microsoft ships with the DirectX SDK . The code looks something like this:

       using System.Drawing;
       using System.Windows.Forms;
       using Microsoft.DirectX; 
       using Microsoft.DirectX.Direct3D; 
       namespace Craig.Samples.Direct3D
       {
         public class Game : System.Windows.Forms.Form 
         { 
           static void Main() 
           { 
             Game app = new Game(); 
             app.InitializeGraphics(); 
             app.Show(); 
             while (app.Created) 
             { 
               app.Render(); 
               Application.DoEvents(); 
             } 
             app.DisposeGraphics(); 
           }
         }
       } 

      Straightaway you can see it's strikingly different from a "normal" WinForms application. It certainly blew me away to see a tight loop - the while (app.Created) bit - in a graphical application. I'm much more used to seeing the a call to Application.Run, which waits for events like mouse or keyboard activity to happen, calls any handlers I might have set up, and exits when my program goes away. Let's walk through the code.

       using System.Drawing;
       using System.Windows.Forms;
       using Microsoft.DirectX; 
       using Microsoft.DirectX.Direct3D; 

      This bit is fairly obvious. We're going to be using stuff from these namespaces, so let's save ourselves having to type them all the time. Note that what we don't see is that we have to have the DirectX SDK installed, and we have to have a reference to both Microsoft.DirectX.dll and Microsoft.DirectX.Direct3D.dll.

       namespace Craig.Samples.Direct3D 
       { 
         public class Game : System.Windows.Forms.Form 
         { 

      The preceding code is actually fairly interesting, because it shows that we're actually writing a class that derives from System.Windows.Forms.Form, just like all the other WinForms apps you've ever written. So all the stuff you know about Windows Forms still applies, we just have to learn how to integrate the Direct3D bits.

          static void Main() 
          { 
            Game app = new Game(); 
            app.InitializeGraphics(); 
            app.Show(); 

      Here's where we create a new instance of the form (remember, Main is static, so there's no instance yet), and then call InitializeGraphics, which is a method that we write. We'll look at it in a future article. The call to app.Show() just makes the form visible.

            while (app.Created) 
            { 
              app.Render(); 
              Application.DoEvents(); 
            } 

      This is the meat of the application, where it will spend most of its time. What we're doing here is checking to see if the form has been closed, and if not, calling our Render method. Render is where all the cool 3D drawing takes place, and I'll talk about it in detail in a later article (stay tuned!). The call to Application.DoEvents is to make sure that any pending Windows events get processed - like I said, we're writing a Windows Forms application, so we can't get away with not servicing the message pump.

      The reason that we do it this way, rather than - say - setting a timer and rendering when it goes off - is that our game probably wants as much CPU as it can get. So we do all our rendering in a tight loop rather than take the usual, "Oh, I'll only do something when a windows event happens" approach. But of course we still have to process messages from Windows.

            app.DisposeGraphics(); 

      Of course we need to clean up when we're done, so we provide a DisposeGraphics method to get called whenever someone shuts down our application. We'll talk about this more later, too.

      You can go ahead and compile this code - it should run just fine if you provide do-nothing InitializeGraphics, Render, and DisposeGraphics methods. Of course, it'll just be a blank form. To do anything interesting, we need a Direct3D Device, which we'll talk about next time.

       

      posted @ 2006-07-21 15:16  張志敏  閱讀(1403)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 久久精品国产99久久6| 一区二区三区午夜福利院| 国产一区二区三区导航| 强奷乱码中文字幕| 日产日韩亚洲欧美综合下载| 高清无码在线视频| 国产精品成人午夜久久| 一本加勒比hezyo无码人妻| 老男人久久青草av高清| 鲁一鲁一鲁一鲁一澡| 东北妇女精品bbwbbw| 男人的天堂av社区在线| 东方四虎在线观看av| 长寿区| 人人妻碰人人免费| 欧美老少配性行为| 阳城县| 在线观看无码av免费不卡网站 | 国产午夜三级一区二区三| 国产精品美女www爽爽爽视频| 不卡一区二区三区四区视频| 欧洲美女黑人粗性暴交视频 | 久久毛片少妇高潮| 汉阴县| h无码精品动漫在线观看| 真实国产乱啪福利露脸| 看免费的无码区特aa毛片| 欧美人成精品网站播放| 四虎永久播放地址免费| 欧美人与动牲交精品| 久久无码中文字幕免费影院蜜桃 | 国内精品视频一区二区三区八戒| 亚洲色大成网站WWW永久麻豆| 中文字幕人妻有码久视频| 内射少妇一区27p| 国产啪视频免费观看视频| 中文字幕日韩精品亚洲一区| 国产精品无遮挡又爽又黄| 亚洲人妻精品中文字幕| 国产丰满麻豆videossexhd| 国产乱人伦真实精品视频|