• <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 閱讀(634) 評論(0)  編輯 收藏 引用

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            无码人妻久久一区二区三区免费丨| 精品蜜臀久久久久99网站| 久久久九九有精品国产| 欧美日韩中文字幕久久伊人| 久久精品无码av| 亚洲女久久久噜噜噜熟女| 欧美久久精品一级c片片| 久久久久久亚洲精品影院| 69SEX久久精品国产麻豆| 性高朝久久久久久久久久| 2020久久精品国产免费| 久久久这里只有精品加勒比| 久久精品国产亚洲综合色| 久久成人小视频| 久久精品亚洲福利| 66精品综合久久久久久久| 亚洲精品乱码久久久久久自慰| 精品人妻伦一二三区久久| 国产精品久久毛片完整版| 久久精品国产亚洲AV蜜臀色欲| 国产精品无码久久四虎| 久久久久99精品成人片试看| 久久青青草视频| 亚洲美日韩Av中文字幕无码久久久妻妇| 国产精品免费看久久久| 人妻无码αv中文字幕久久琪琪布 人妻无码久久一区二区三区免费 人妻无码中文久久久久专区 | 久久毛片免费看一区二区三区| 国产精品女同久久久久电影院| 麻豆成人久久精品二区三区免费| 伊人久久大香线蕉精品不卡| 狠狠久久综合伊人不卡| 国产精品美女久久久网AV| 青青草国产精品久久久久| a级毛片无码兔费真人久久| 99久久精品日本一区二区免费| 色欲久久久天天天综合网| 精品综合久久久久久98| 亚洲精品乱码久久久久久蜜桃不卡| 97精品国产97久久久久久免费 | 亚洲欧美成人久久综合中文网| 久久中文字幕视频、最近更新 |