亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? direct.html

?? 非常好的在win32下用c++sdk開發的工具書
?? HTML
?? 第 1 頁 / 共 2 頁
字號:
<html>
<head>
<title>Direct Draw Tutorial</title>
<meta  name="description" content="Reliable software Win32 Tutorial">
<meta name="keywords" content="bitmap, bitblt, windows, cplusplus">
</head>

<body background="../images/grid.gif" bgcolor="white" text="black">
<script language="JAVASCRIPT">
<!--
if (navigator.onLine){
document.write("<!-- Spidersoft WebZIP Ad Banner Insert -->");
document.write("<TABLE width=100% border=0 cellpadding=0 cellspacing=0>");
document.write("<TR>");
document.write("<TD>");
document.write("<ILAYER id=ad1 visibility=hidden height=60></ILAYER>");
document.write("<NOLAYER>");
document.write("<IFRAME SRC='http://www.spidersoft.com/ads/bwz468_60.htm' width=100% height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></IFRAME>");
document.write("</NOLAYER>");
document.write("</TD>");
document.write("</TR>");
document.write("</TABLE>");
document.write("<!-- End of Spidersoft WebZIP Ad Banner Insert-->");
}
 //-->
</script>

<table cellpadding=10 width=100%>
<tr>
   <td width=100 align="center" valign="middle">
      <a href="../index.htm">
      <img src="../images/rsbullet.gif" alt="RS" border=0 width=39 height=39>
      <p>Home</a>
   </td>
   <td><font face="arial" color="#00a080">
       <h1 align=center>Direct Draw</h1>
       </font>
   </td>
   </tr>
</table>


<table width=100%><!-- main table -->
<tr>
   <td width=10> <!-- Left margin -->&nbsp;</td>
   <td> <!-- Middle column, there is also the right margin at the end -->

   <table cellpadding=10 cellspacing=0 width=500>
   <tr>
   <td bgcolor=white>
   <font face="Arial" size=2>
<hr>
<img src="images/brace.gif" width=16 height=16 border=0 alt="">As usual, you can <a href="source/direct.zip">download</a> the complete source code of the application that is used in this example.
<hr>
<h2>Direct Draw App</h2>

<p>If you want fast animation (games!), you have to use DirectX. Try filling the screen by drawing each pixel separately using GDI. Compare it with DirectX, which gives you practically direct access to the screen buffer. There's no competition!
<hr>
<p>The bad news is that DirectX involves dealing with COM interfaces. The good news is that you can encapsulate them nicely inside C++ classes. Let me show you first how to use these classes to write a simple application that displays an animated, rotating, bitmap. We'll use Windows timer to drive the animation. We'll have to:
<ul>
<li>Initialize the program, including the DirectX subsystem
<li>Respond to timer messages
<li>Respond to window resizing (we'll use the window mode, rather than full screen)
<li>Respond to paint messages
</ul>

<p>Let's start with the WM_PAINT message. This message is sent to us when Windows needs to repaint our window. We have to stash somewhere a complete animation frame, so that we can quickly blit it to screen in response to WM_PAINT. The storage for this frame will be called the <b>back surface</b>.

<p>Upon receiving the timer message, we have to paint a new frame on the back surface. Once we're done, we'll invalidate our window, so that WM_PAINT message will be sent to us.

<p>Upon resizing the window, we have to create a new back surface, corresponding to the new window size. Than we'll draw on it and invalidate the window.

<hr>
<p>The initialization involves creating the timer, creating the World (that's where we keep our bitmap and drive the animation), creating the View, and setting the first timer countdown.
<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>void Controller::Create (CREATESTRUCT * create)
{
    _timer.Create (_h, 1);
    _world = new World (create-&gt;hInstance, IDB_RS);
    _view.Create (_h, _world);
    _timer.Set (10);
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->
<hr>
<p>Here's our response to WM_SIZE. We let the View know about the new size (it will create a new back surface), we call it's Update method which draws the animation frame, and we invalidate the window.
<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>bool Controller::Size (int width, int height)
{
    _view.Size (_h, width, height);
    _view.Update ();
    // force repaint
    _h.Invalidate (false);
    return true;
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->
<hr>
<p>In response to WM_PAINT, we let the View do the painting (blit the back surface to the screen). We also have to tell Windows that the painting is done--validate the uncovered area. This is done simply by constructing the PaintCanvas object.
<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>bool Controller::Paint (HDC hdc)
{
    _view.Paint (_h);
    // validate painted area
    PaintCanvas canvas (_h);
    return true;
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<hr>
<p>In response to WM_TIMER, we kill the timer, tell the World to move one frame ahead, let the View repaint the frame on the back surface, invalidate the window (so that Paint is called) and set the timeout again.
<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>bool Controller::Timer (int id, TIMERPROC * proc)
{
    _timer.Kill ();
    _world-&gt;Step ();

    _view.Update ();
    // force repaint
    _h.Invalidate (false);
    _timer.Set (10);
    return true;
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<hr>
<p>There is one more thing. DirectX doesn't like when a screen saver kicks in, so we have to preempt it.
<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>bool Controller::SysCommand (int cmd)
{
    // disable screen savers
    if (cmd == SC_SCREENSAVE || cmd == SC_MONITORPOWER)
        return true;
    return false;
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->
<p>By the way, this is how SysCommand is called from the window procedure:

<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>    case WM_SYSCOMMAND:
        if (pCtrl-&gt;SysCommand (wParam &amp; 0xfff0))
            return 0;
        break;
</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<hr>
<p>Let's now have a closer look at View, which is the class dealing with output to screen. Notice two important data members, the Direct::Draw object and the Direct::Surface object.

<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>class View
{
public:
    View ();
    void Create (HWND h, World * world);
    void Size (HWND h, int width, int height);
    void Update ();
    void Paint (HWND h);
private:
    <b>Direct::Draw</b>    _draw;
    <b>Direct::Surface</b> _backSurface;

    World * _world;
    int        _dx;
    int        _dy;
};</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->
<p>I have encapsulated all DirectX classes inside the namespace <b>Direct</b>. This trick enforces a very nice naming convention, namely, you have to prefix all DirectX classes with the prefix <b>Direct::</b> . 
<p>The Direct::Draw object's duty is to initialize the DirectX subsystem. It does it in it's constructor, so any time View is constructed (once per program instatiation), DirectX is ready to use. It's destructor, by the way, frees the resources used by DirectX. 
<p>Direct::Surface _backSurface will be used by View to draw the animation upon it.


<hr>
<p>The initialization of DirectX also involves setting up the collaboration level with Windows. Here, we are telling it to work nicely with other windows, rather then taking over in the full-screen mode.

<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>void View::Create (HWND h, World * world)
{
    _world = world;
    // Set coopration with Windows
    _draw.<b>SetCoopNormal</b> (h);
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<hr>
<p>Back surface is created (and re-created) in response to WM_SIZE message. Surfaces are implemented in such a way that regular assignment operation does the right thing. It deallocates the previous surface and initializes a new one. Notice that the constructor of an OffScreenSurface takes the Direct::Draw object and the dimensions of the surface in pixels.

<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>void View::Size (HWND h, int width, int height)
{
    _dx = width;
    _dy = height;
    if (_dx == 0 || _dy == 0)
        return;
    _backSurface = <b>Direct::OffScreenSurface</b> (_draw, _dx, _dy);
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<hr>
<p>Painting is slightly tricky. We have to get access to the primary drawing surface, which is the whole screen buffer. But since we are not using the full-screen mode, we want to draw only inside the rectangular area of our window. That's why we create a Direct::Clipper, to clip anything that would fall outside of that area. The clipper figures out the correct area using the handle to the window that we are passing to it.
<p>Next, we create the primary surface and pass it the clipper. Now we can blit the image directly from our back surface to the screen. Again, since the primary surface represents the whole screen, we have to offset our blit by specifying the target rectangle. The auxillary class Direct::WinRect retrieves the coordinates of that rectangle.


<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>void View::Paint (HWND h)
{
    if (_dx == 0 || _dy == 0)
        return;
    // Clip to window
    <b>Direct::Clipper</b> clipper (_draw);
    clipper.SetHWnd (h);
    // Screen surface
    <b>Direct::PrimarySurface</b> surf (_draw);
    surf.SetClipper (clipper);
    <b>Direct::WinRect</b> rect (h);
    // Blit from back surface to screen
    surf.<b>BltFrom</b> (_backSurface, &amp;rect);
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<hr>
<p>Finally, the actual drawing is done using direct access to the back surface buffer. But first, we flood the back surface with white background. Then we construct the Direct::SurfaceBuf. This is the object that let's us set pixels directly into the buffer's memory (depending on implementation, it might be your video card memory or a chunk of your system memory). The details of our drawing algorithm are inessential here. Suffice it to say that the work of setting the pixel is done in the SetPixel method.

<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>void View::Update ()
{
    if (_dx == 0 || _dy == 0)
        return;
    try
    {
        // white background
        _backSurface.<b>Fill</b> (RGB (255, 255, 255));

        {
            // Get direct access to back surface
            <b>Direct::SurfaceBuf</b> buf (_backSurface);
            // draw bitmap within a centered square
            int side = 100;
            if (_dx &lt; side)
                side = _dx;
            if (_dy &lt; side)
                side = _dy;
            int xOff = (_dx - side) / 2;
            int yOff = (_dy - side) / 2;
            assert (xOff &gt;= 0);
            assert (yOff &gt;= 0);
            double dxInv = 1.0 / side;
            double dyInv = 1.0 / side;
            for (int i = 0; i &lt; side; ++i)
            {
                for (int j = 0; j &lt; side; ++j)
                {
                    double u = dxInv * i;
                    double v = dyInv * j;
                    COLORREF color = _world-&gt;GetTexel (u, v);
                    // draw pixel directly
                    buf.<b>SetPixel</b> (xOff + i, yOff + j, color);
                }
            }
        }
        // Paint will blit the image to screen
    }
    catch (char const * msg)
    {
        ::MessageBox (0, msg, "Viewer error", 
                      MB_OK | MB_ICONERROR);
        throw;
    }
    catch (...)
    {
        ::MessageBox (0, "Unknown error", 
                         "Viewer error", 
                         MB_OK | MB_ICONERROR);
        throw;
    }
}</pre><!--End Code--></font>
                       </td>
                       <td width=20>&nbsp;</td>
        </tr>
        </table>
<!--End of yellow background-->

<p>Besides being able to set individual pixels quickly, DirectX also provides ways to efficiently blit bitmaps or even use GDI functions to write to a surface.

<hr>
<h2>Implementation</h2>
<p>As mentioned before, all DirectDraw objects are enclosed in the Direct namespace. The fundamental object, Direct::Draw, is responsible for the initialization and the release of the DirectDraw subsystem. It can also be used to set up the cooperation level with Windows. It's easy to add more methods and options to this class, as the need arises.

<!--Yellow background-->       <table cellpadding=10 cellspacing=0 width=100%>
                <tr>
                      <td width=20>&nbsp;</td>
                      <td bgcolor="#e0e080"><font color="black">
<pre>namespace Direct
{
    // Direct Draw object

    class Draw
    {
    public:
        Draw ();
        ~Draw ()
        {
            _pDraw->Release ();

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
99久久综合精品| 精品剧情在线观看| 欧美日韩免费高清一区色橹橹| 91精品国产综合久久香蕉麻豆| 精品国产乱码久久久久久浪潮| 国产精品久久777777| 久久久国产精品午夜一区ai换脸| 一区二区三区高清在线| 美国毛片一区二区| 91福利小视频| 国产精品另类一区| 日韩av电影免费观看高清完整版在线观看 | 麻豆精品新av中文字幕| 成人美女视频在线观看| 日韩精品最新网址| 亚洲精品高清视频在线观看| 国产一本一道久久香蕉| 欧美一级高清大全免费观看| 国产精品超碰97尤物18| 日韩免费性生活视频播放| 91麻豆精品国产| 精品福利在线导航| 亚洲影院在线观看| 国产成人小视频| 日韩欧美激情在线| 日韩成人一区二区| 色婷婷久久99综合精品jk白丝| 日韩精品中文字幕一区二区三区 | 国产一区在线精品| 欧美一级黄色片| 午夜不卡在线视频| 国产精品影视天天线| 91久久国产最好的精华液| 亚洲精品一二三| thepron国产精品| 欧美激情综合五月色丁香 | 久久综合综合久久综合| 欧美一卡二卡在线| 爽爽淫人综合网网站| 91成人在线免费观看| 国产三级一区二区三区| 国产一区二区91| 久久久久久电影| 狠狠色狠狠色综合日日91app| 久久嫩草精品久久久精品一| 麻豆国产精品官网| 欧美大片国产精品| 日韩**一区毛片| 337p粉嫩大胆色噜噜噜噜亚洲| 麻豆精品在线播放| 日韩免费成人网| 成人精品免费网站| 中文字幕中文字幕一区| 色噜噜偷拍精品综合在线| 亚洲已满18点击进入久久| 在线免费亚洲电影| 亚洲国产精品久久久久婷婷884| 在线区一区二视频| 久久精品免费看| 久久久久88色偷偷免费| 国产suv精品一区二区883| 欧美精品一区男女天堂| 91视频在线观看免费| 亚洲欧美一区二区久久| 欧美揉bbbbb揉bbbbb| 国产剧情av麻豆香蕉精品| 国产欧美综合在线观看第十页| 国产成人在线免费观看| 中文字幕av一区二区三区| 在线视频你懂得一区二区三区| 日韩avvvv在线播放| 国产亚洲综合在线| 欧美色电影在线| 精品一区二区久久久| 国产精品入口麻豆九色| 欧美在线一区二区三区| 亚洲影院理伦片| 国产欧美日韩激情| 欧美午夜精品一区二区蜜桃| 美女视频第一区二区三区免费观看网站 | 久久久青草青青国产亚洲免观| 成人看片黄a免费看在线| 性做久久久久久免费观看| 日韩美女视频在线| 欧美日韩色综合| 国产成人在线视频免费播放| 亚洲激情欧美激情| 欧美激情一区二区三区蜜桃视频 | 欧美成人综合网站| 日本高清视频一区二区| 国产麻豆精品一区二区| 亚洲一区二区三区国产| 国产免费成人在线视频| 欧美日韩国产一级二级| 成人免费va视频| 美女在线观看视频一区二区| 综合激情成人伊人| 久久综合色鬼综合色| 欧美专区亚洲专区| 粉嫩av亚洲一区二区图片| 麻豆精品视频在线观看| 一区二区三区产品免费精品久久75| 日韩写真欧美这视频| 国产成都精品91一区二区三| 狠狠色狠狠色综合系列| 午夜精品影院在线观看| 中文字幕一区二区三区不卡| 国产欧美一区二区三区在线老狼 | 亚洲国产精品久久不卡毛片 | 麻豆成人在线观看| 亚洲欧美区自拍先锋| 久久午夜色播影院免费高清| 91精品一区二区三区在线观看| 91蜜桃免费观看视频| 精品一区免费av| 国产自产v一区二区三区c| 日本中文在线一区| 一区二区三区欧美视频| 亚洲一区二区三区视频在线播放| 日本一区二区动态图| 精品乱码亚洲一区二区不卡| 欧美日韩国产精选| 在线成人免费视频| 欧美体内she精高潮| 色哟哟一区二区三区| 色嗨嗨av一区二区三区| 99re热这里只有精品视频| 国产麻豆精品一区二区| 日韩精品电影一区亚洲| 亚洲成人免费电影| 香蕉久久夜色精品国产使用方法 | 欧美一区二区视频免费观看| 欧美高清视频一二三区| 欧美又粗又大又爽| 欧美另类高清zo欧美| 欧美在线观看一区| 欧美午夜寂寞影院| 欧美人与性动xxxx| 精品国产青草久久久久福利| 久久色视频免费观看| 国产精品国产三级国产aⅴ入口 | 欧美国产在线观看| 一二三四区精品视频| 日韩精品福利网| 国产成a人亚洲| 一本一本大道香蕉久在线精品| 欧美日韩精品免费| 国产清纯白嫩初高生在线观看91 | 秋霞午夜鲁丝一区二区老狼| 国产丶欧美丶日本不卡视频| 91蜜桃视频在线| 欧美成人a∨高清免费观看| 中文字幕中文乱码欧美一区二区 | 欧美一区二区三区电影| 久久久久久亚洲综合| 一区二区三区色| 国产一区999| 51精品国自产在线| 国产精品传媒视频| 蜜臀av性久久久久蜜臀aⅴ流畅| 99在线精品视频| 欧美r级电影在线观看| 一区二区三区高清不卡| 国产成人高清在线| 日韩欧美在线不卡| 亚洲男人天堂av网| 国产成人精品三级| 欧美精品在欧美一区二区少妇| 国产精品久久久99| 狠狠色狠狠色合久久伊人| 欧美亚洲一区二区在线| 国产精品毛片久久久久久久| 日韩vs国产vs欧美| 欧美视频日韩视频在线观看| 国产精品免费aⅴ片在线观看| 美腿丝袜亚洲色图| 欧美日本在线一区| 樱花草国产18久久久久| 国产成人高清视频| 久久天天做天天爱综合色| 日本成人在线视频网站| 在线观看亚洲专区| 亚洲欧美日韩国产中文在线| 东方欧美亚洲色图在线| 精品国产91洋老外米糕| 捆绑调教美女网站视频一区| 欧美日韩国产区一| 亚洲国产一二三| 97久久久精品综合88久久| 国产精品午夜免费| 成人午夜看片网址| 中文字幕欧美日韩一区| 成人一区二区在线观看| 国产精品丝袜一区| 国产精品1024久久| 中文字幕二三区不卡| 成人黄色a**站在线观看| 中文字幕av一区二区三区| 成人精品在线视频观看| 国产精品电影一区二区三区|