• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            天行健 君子當自強而不息

            D3D中的紋理映射(4)

            該例程演示了如何設置紋理尋址模式。

            截圖:

            源程序:

             

            /**************************************************************************************
              Allows the user to switch between the different texture address modes to see what they do. 
              Use the following keys:
                       'W' - Switches to Wrap mode
                       'B' - Switches to Border mode
                       'C' - Switches to Clamp mode
                       'M' - Switches to Mirror mode  
             *************************************************************************************
            */

            #include 
            "d3dUtility.h"

            #pragma warning(disable : 
            4100)

            const int WIDTH  = 640;
            const int HEIGHT = 480;

            IDirect3DDevice9
            *        g_d3d_device;
            IDirect3DVertexBuffer9
            * g_quad_vb;
            IDirect3DTexture9
            *        g_d3d_texture;

            class cTextureVertex
            {
            public:
                
            float m_x,  m_y,  m_z;
                
            float m_nx, m_ny, m_nz;
                
            float m_u, m_v; // texture coordinates    

                cTextureVertex() { }

                cTextureVertex(
            float x,  float y,  float z,
                               
            float nx, float ny, float nz,
                               
            float u,  float v)
                {
                    m_x  
            = x;  m_y  = y;  m_z  = z;
                    m_nx 
            = nx; m_ny = ny; m_nz = nz;
                    m_u  
            = u;  m_v  = v;
                }    
            };

            const DWORD TEXTURE_VERTEX_FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;

            ////////////////////////////////////////////////////////////////////////////////////////////////////

            bool setup()
            {    
                
            // create the quad vertex buffer and fill it with the quad geometry
                g_d3d_device->CreateVertexBuffer(6 * sizeof(cTextureVertex), D3DUSAGE_WRITEONLY, TEXTURE_VERTEX_FVF,
                                                 D3DPOOL_MANAGED, 
            &g_quad_vb, NULL);

                cTextureVertex
            * vertices;

                g_quad_vb
            ->Lock(00, (void**)&vertices, 0);

                
            // quad built from two triangles, note texture coordinate.

                vertices[
            0= cTextureVertex(-1.0f-1.0f1.25f0.0f0.0f-1.0f0.0f3.0f);
                vertices[
            1= cTextureVertex(-1.0f,  1.0f1.25f0.0f0.0f-1.0f0.0f0.0f);
                vertices[
            2= cTextureVertex( 1.0f,  1.0f1.25f0.0f0.0f-1.0f3.0f0.0f);

                vertices[
            3= cTextureVertex(-1.0f-1.0f1.25f0.0f0.0f-1.0f0.0f3.0f);
                vertices[
            4= cTextureVertex( 1.0f,  1.0f1.25f0.0f0.0f-1.0f3.0f0.0f);
                vertices[
            5= cTextureVertex( 1.0f-1.0f1.25f0.0f0.0f-1.0f3.0f3.0f);

                g_quad_vb
            ->Unlock();

                
            // create the texture and set filters

                D3DXCreateTextureFromFile(g_d3d_device, 
            "dx5_logo.bmp"&g_d3d_texture);

                g_d3d_device
            ->SetTexture(0, g_d3d_texture);

                g_d3d_device
            ->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
                g_d3d_device
            ->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
                g_d3d_device
            ->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

                
            // don't use lighting for this sample
                g_d3d_device->SetRenderState(D3DRS_LIGHTING, FALSE);

                
            // set the projection matrix
                D3DXMATRIX proj;
                D3DXMatrixPerspectiveFovLH(
            &proj, D3DX_PI * 0.5f, (float)WIDTH/HEIGHT, 1.0f1000.0f);
                g_d3d_device
            ->SetTransform(D3DTS_PROJECTION, &proj);
                
                
            return true;
            }

            void cleanup()
            {    
                safe_release
            <IDirect3DVertexBuffer9*>(g_quad_vb);
                safe_release
            <IDirect3DTexture9*>(g_d3d_texture);
            }

            bool display(float time_delta)
            {
                
            // set wrap address mode
                if(GetAsyncKeyState('W'& 0x8000f)
                {
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);
                }

                
            // set border color address mode
                if(GetAsyncKeyState('B'& 0x8000f)
                {
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
                    g_d3d_device
            ->SetSamplerState(0,  D3DSAMP_BORDERCOLOR, 0x000000ff);
                }

                
            // set clamp address mode
                if(GetAsyncKeyState('C'& 0x8000f)
                {
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
                }

                
            // set mirror address mode
                if(GetAsyncKeyState('M'& 0x8000f)
                {
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_MIRROR);
                    g_d3d_device
            ->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_MIRROR);
                }    

                
            // draw the scene

                g_d3d_device
            ->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff1.0f0);

                g_d3d_device
            ->BeginScene();

                g_d3d_device
            ->SetStreamSource(0, g_quad_vb, 0sizeof(cTextureVertex));
                g_d3d_device
            ->SetFVF(TEXTURE_VERTEX_FVF);
                g_d3d_device
            ->DrawPrimitive(D3DPT_TRIANGLELIST, 02);
                
                g_d3d_device
            ->EndScene();

                g_d3d_device
            ->Present(NULL, NULL, NULL, NULL);

                
            return true;
            }

            LRESULT CALLBACK wnd_proc(HWND hwnd, UINT msg, WPARAM word_param, LPARAM long_param)
            {
                
            switch(msg)
                {
                
            case WM_DESTROY:
                    PostQuitMessage(
            0);
                    
            break;

                
            case WM_KEYDOWN:
                    
            if(word_param == VK_ESCAPE)
                        DestroyWindow(hwnd);
                    
            break;
                }

                
            return DefWindowProc(hwnd, msg, word_param, long_param);
            }

            int WINAPI WinMain(HINSTANCE inst, HINSTANCE, PSTR cmd_line, int cmd_show)
            {
                
            if(! init_d3d(inst, WIDTH, HEIGHT, true, D3DDEVTYPE_HAL, &g_d3d_device))
                {
                    MessageBox(NULL, 
            "init_d3d() - failed."0, MB_OK);
                    
            return 0;
                }

                
            if(! setup())
                {
                    MessageBox(NULL, 
            "Steup() - failed."0, MB_OK);
                    
            return 0;
                }

                enter_msg_loop(display);

                cleanup();
                g_d3d_device
            ->Release();

                
            return 0;
            }

             

            下載源程序


            posted on 2008-03-17 17:49 lovedday 閱讀(638) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            亚洲人AV永久一区二区三区久久| 久久精品无码专区免费青青| 色婷婷综合久久久久中文| 久久亚洲AV成人无码电影| 丁香色欲久久久久久综合网| 97精品伊人久久大香线蕉app | 91精品无码久久久久久五月天| 久久国产V一级毛多内射| 久久国产色av免费看| 久久国产精品无码网站| 久久精品国产精品亚洲毛片| 国产免费久久久久久无码| 无码伊人66久久大杳蕉网站谷歌| 性做久久久久久免费观看| 精品久久久久久久久久中文字幕| 色综合久久天天综线观看| 色成年激情久久综合| 欧美精品一区二区精品久久| 久久国产免费直播| 久久国产综合精品五月天| 精品久久久久久国产潘金莲| 久久久久久人妻无码| 久久久久国产精品三级网| 久久国产精品-国产精品| 韩国三级大全久久网站| 国产亚洲精久久久久久无码77777| 精品久久久久久无码免费| 欧美777精品久久久久网| 久久综合亚洲欧美成人| 一本色道久久综合亚洲精品| 亚洲美日韩Av中文字幕无码久久久妻妇 | 色综合合久久天天给综看| 久久这里只有精品久久| 久久精品夜夜夜夜夜久久| 精产国品久久一二三产区区别| 欧美粉嫩小泬久久久久久久| 午夜精品久久影院蜜桃| 国产免费久久久久久无码| 久久国产三级无码一区二区 | 久久精品国产亚洲AV忘忧草18| 日本国产精品久久|