• <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>

            天行健 君子當自強而不息

            高級紋理映射技術(4)

            發光映射

            發光映射(glowing mapping)與黑暗映射正好相反,它對于模擬那些具有獨立于基礎貼圖的發光部分的物體很有用,比如模擬發光二極管、按鈕、建筑物內的燈光、太空船上的燈光等。發光映射應僅影響基礎貼圖上的發光區域,而不影響其他部分。因此需要對發光效果做加法,而不是做乘法。

            pd3dDevice->SetTexture(0, g_base_texture);
            pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
            pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
            pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);

            pd3dDevice->SetTexture(1, g_dark_texture);
            pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
            pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
            pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
            pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADD);

            運行效果:

             

            細節映射

            如果要模擬一塊粗糙的石灰泥墻壁,可以通過細節映射(detail mapping)來實現。實現過程是:將基礎貼圖(也就是第一張紋理)的顏色未經修改便作為第二個紋理操作階段中的第二個參數,然后通過D3DTOP_ADDSIGNED將灰色的細節紋理與基礎貼圖相加。這個操作本質上是做了一個加法,只是使用了有符號的顏色值來代替平時使用的無符號值。在對兩張紋理的像素顏色進行D3DTOP_ADDSIGNED操作時,它將參數的每個成分相加后再減去偏移量0.5,從而使有效值域變為-0.5 ~ 0.5。對一些比較舊的顯卡,當其不能支持D3DTOP_ADDSIGNED操作時,可以使用D3DTOP_MODULATE2X代替D3DTOP_ADDSIGNED操作進行模擬。

            在細節貼圖中較亮的灰色紋理元素會使基礎貼圖變得更亮,而較暗的灰色紋理元素會使基礎貼圖變得更暗。由此可使物體呈現出粗糙的表面,從而使之看上去更為真實。示例代碼如下:

            pd3dDevice->SetTexture(0, g_base_texture);
            pd3dDevice->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, 0);
            pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
            pd3dDevice->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
            pd3dDevice->SetTexture(1, g_detail_texture);
            pd3dDevice->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX, 0);
            pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG1, D3DTA_TEXTURE);
            pd3dDevice->SetTextureStageState(1, D3DTSS_COLORARG2, D3DTA_CURRENT);
            hr = pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED);
            if(FAILED(hr))
            pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);

            物體紋理

            細節紋理

             

            運行效果:

             

            主程序:

            #include "dxstdafx.h"
            #include 
            "resource.h"

            #pragma warning(disable : 
            4127 4995 4996)

            #define release_com(p)    do { if(p) { (p)->Release(); (p) = NULL; } } while(0)

            struct sCustomVertex
            {
                
            float x, y, z;
                
            float u, v;
            };

            #define D3DFVF_CUSTOM_VERTEX    (D3DFVF_XYZ | D3DFVF_TEX1)

            #define IDC_TOGGLE_FULLSCREEN        1
            #define IDC_TOGGLE_REF                2
            #define IDC_CHANGE_DEVICE            3

            #define BLEND_DARK                    1
            #define BLEND_DARK_ANIM                2
            #define BLEND_TEXTURE_DIFFUSE        3
            #define BLEND_DARK_DIFFUSE            4
            #define BLEND_GLOW                    5
            #define BLEND_DETAIL                6

            #define BLEND_INFO_DARK                L"Dark Blend"
            #define BLEND_INFO_DARK_ANIM        L"Dark Blend Animation"
            #define BLEND_INFO_TEXTURE_DIFFUSE    L"Blend Texture and Vertex Diffuse Color"
            #define BLEND_INFO_DARK_DIFFUSE        L"Blend Texture and Vertex Diffuse Color and Dark"
            #define BLEND_INFO_GLOW                L"Glow Mapping"
            #define BLEND_INFO_DETAIL            L"Detail Mapping"

            const D3DXCOLOR FONT_COLOR(0.85f0.85f0.85f1.0f);

            CDXUTDialogResourceManager    g_dlg_resource_manager;
            CD3DSettingsDlg                g_settings_dlg;
            CDXUTDialog                    g_button_dlg;

            IDirect3DVertexBuffer9
            *        g_vertex_buffer;
            IDirect3DTexture9
            *            g_base_texture;
            IDirect3DTexture9
            *            g_dark_texture;
            IDirect3DTexture9
            *            g_detail_texture;

            ID3DXFont
            *        g_font;
            ID3DXSprite
            *    g_text_sprite;
            bool            g_show_help = true;
            D3DLIGHT9        g_light;
            D3DMATERIAL9    g_material;
            int                g_blend_flag = BLEND_DARK;
            WCHAR            g_blend_info[
            128= BLEND_INFO_DARK;

            //--------------------------------------------------------------------------------------
            // Rejects any devices that aren't acceptable by returning false
            //--------------------------------------------------------------------------------------
            bool CALLBACK IsDeviceAcceptable( D3DCAPS9* pCaps, D3DFORMAT AdapterFormat, 
                                              D3DFORMAT BackBufferFormat, 
            bool bWindowed, void* pUserContext )
            {
                
            // Typically want to skip backbuffer formats that don't support alpha blending

                IDirect3D9
            * pD3D = DXUTGetD3DObject(); 

                
            if( FAILED( pD3D->CheckDeviceFormat( pCaps->AdapterOrdinal, pCaps->DeviceType, AdapterFormat, 
                                D3DUSAGE_QUERY_POSTPIXELSHADER_BLENDING, D3DRTYPE_TEXTURE, BackBufferFormat ) ) )
                    
            return false;

                
            // check whether device support multi textures render
                if(pCaps->MaxTextureBlendStages <= 1)
                    
            return false;

                
            return true;
            }


            //--------------------------------------------------------------------------------------
            // Before a device is created, modify the device settings as needed.
            //--------------------------------------------------------------------------------------
            bool CALLBACK ModifyDeviceSettings( DXUTDeviceSettings* pDeviceSettings, const D3DCAPS9* pCaps, void* pUserContext )
            {
                
            // If video card does not support hardware vertex processing, then uses sofaware vertex processing.
                if((pCaps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) == 0)
                    pDeviceSettings
            ->BehaviorFlags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;

                
            static bool is_first_time = true;

                
            if(is_first_time)
                {
                    is_first_time 
            = false;

                    
            // if using reference device, then pop a warning message box.
                    if(pDeviceSettings->DeviceType == D3DDEVTYPE_REF)
                        DXUTDisplaySwitchingToREFWarning();
                }

                
            return true;
            }


            //--------------------------------------------------------------------------------------
            // Create any D3DPOOL_MANAGED resources here 
            //--------------------------------------------------------------------------------------
            HRESULT CALLBACK OnCreateDevice( IDirect3DDevice9* pd3dDevice, 
                                             
            const D3DSURFACE_DESC* pBackBufferSurfaceDesc, 
                                             
            void* pUserContext )
            {
                HRESULT    hr;

                V_RETURN(g_dlg_resource_manager.OnCreateDevice(pd3dDevice));
                V_RETURN(g_settings_dlg.OnCreateDevice(pd3dDevice));

                D3DXCreateFont(pd3dDevice, 
            180, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
                               DEFAULT_PITCH 
            | FF_DONTCARE, L"Arial"&g_font);

                V_RETURN(D3DXCreateTextureFromFile(pd3dDevice, L
            "wall.bmp",    &g_base_texture));
                V_RETURN(D3DXCreateTextureFromFile(pd3dDevice, L
            "dark.bmp",    &g_dark_texture));
                V_RETURN(D3DXCreateTextureFromFile(pd3dDevice, L
            "detail.bmp",  &g_detail_texture));

                
            // create vertex buffer and fill data

                sCustomVertex vertices[] 
            =     
                {
                    { 
            -3.0f-3.0f,  0.0f,  0.0f1.0f},
                    { 
            -3.0f,  3.0f,  0.0f,  0.0f0.0f},
                    {  
            3.0f-3.0f,  0.0f,  1.0f1.0f},
                    {  
            3.0f,  3.0f,  0.0f,  1.0f0.0f}
                };

                pd3dDevice
            ->CreateVertexBuffer(sizeof(vertices), 0, D3DFVF_CUSTOM_VERTEX, D3DPOOL_MANAGED, &g_vertex_buffer, NULL);

                
            void* ptr;
                g_vertex_buffer
            ->Lock(0sizeof(vertices), (void**)&ptr, 0);
                memcpy(ptr, vertices, 
            sizeof(vertices));
                g_vertex_buffer
            ->Unlock();

                
            return S_OK;
            }


            //--------------------------------------------------------------------------------------
            // Create any D3DPOOL_DEFAULT resources here 
            //--------------------------------------------------------------------------------------
            HRESULT CALLBACK OnResetDevice( IDirect3DDevice9* pd3dDevice, 
                                            
            const D3DSURFACE_DESC* pBackBufferSurfaceDesc, 
                                            
            void* pUserContext )
            {
                HRESULT hr;

                V_RETURN(g_dlg_resource_manager.OnResetDevice());
                V_RETURN(g_settings_dlg.OnResetDevice());
                V_RETURN(g_font
            ->OnResetDevice());
                V_RETURN(D3DXCreateSprite(pd3dDevice, 
            &g_text_sprite));

                
            // set dialog position and size

                g_button_dlg.SetLocation(pBackBufferSurfaceDesc
            ->Width - 1700);
                g_button_dlg.SetSize(
            170170);

                
            // setup view matrix

                D3DXMATRIX mat_view;
                D3DXVECTOR3 eye(
            0.0f0.0f-10.0f);
                D3DXVECTOR3  at(
            0.0f0.0f,  0.0f);
                D3DXVECTOR3  up(
            0.0f1.0f,  0.0f);

                D3DXMatrixLookAtLH(
            &mat_view, &eye, &at, &up);
                pd3dDevice
            ->SetTransform(D3DTS_VIEW, &mat_view);

                
            // set projection matrix
                D3DXMATRIX mat_proj;
                
            float aspect = (float)pBackBufferSurfaceDesc->Width / pBackBufferSurfaceDesc->Height;
                D3DXMatrixPerspectiveFovLH(
            &mat_proj, D3DX_PI/4, aspect, 1.0f100.0f);
                pd3dDevice
            ->SetTransform(D3DTS_PROJECTION, &mat_proj);

                
            // setup light

                ZeroMemory(
            &g_light, sizeof(D3DLIGHT9));

                g_light.Type      
            = D3DLIGHT_DIRECTIONAL;
                g_light.Diffuse.r 
            = 0.5f;
                g_light.Diffuse.g 
            = 0.5f;
                g_light.Diffuse.b 
            = 0.5f;

                D3DXVECTOR3 light_dir(
            0010);
                D3DXVec3Normalize((D3DXVECTOR3
            *&g_light.Direction, &light_dir);

                
            // setup material

                ZeroMemory(
            &g_material, sizeof(D3DMATERIAL9));

                g_material.Ambient.r 
            = 1.0f;
                g_material.Ambient.g 
            = 1.0f;
                g_material.Ambient.b 
            = 1.0f;
                g_material.Ambient.a 
            = 1.0f;
                g_material.Diffuse.r 
            = 0.7f;
                g_material.Diffuse.g 
            = 0.7f;
                g_material.Diffuse.b 
            = 0.7f;
                g_material.Diffuse.a 
            = 0.5f;

                
            // set texture sample method
                pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
                pd3dDevice
            ->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
                pd3dDevice
            ->SetSamplerState(1, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
                pd3dDevice
            ->SetSamplerState(1, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

                
            return S_OK;
            }

            //--------------------------------------------------------------------------------------
            // Release resources created in the OnResetDevice callback here 
            //--------------------------------------------------------------------------------------
            void CALLBACK OnLostDevice( void* pUserContext )
            {
                g_dlg_resource_manager.OnLostDevice();
                g_settings_dlg.OnLostDevice();
                g_font
            ->OnLostDevice();

                release_com(g_text_sprite);
            }


            //--------------------------------------------------------------------------------------
            // Release resources created in the OnCreateDevice callback here
            //--------------------------------------------------------------------------------------
            void CALLBACK OnDestroyDevice( void* pUserContext )
            {
                g_dlg_resource_manager.OnDestroyDevice();
                g_settings_dlg.OnDestroyDevice();    

                release_com(g_font);
                release_com(g_vertex_buffer);
                release_com(g_base_texture);
                release_com(g_dark_texture);
                release_com(g_detail_texture);
            }

            //--------------------------------------------------------------------------------------
            // Handle updates to the scene
            //--------------------------------------------------------------------------------------
            void CALLBACK OnFrameMove( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
            {
                HRESULT hr 
            = S_OK;

                
            if(g_blend_flag == BLEND_DARK)
                {
                    pd3dDevice
            ->SetTexture(0, g_base_texture);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLOROP,            D3DTOP_SELECTARG1);

                    pd3dDevice
            ->SetTexture(1, g_dark_texture);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG2,        D3DTA_CURRENT);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP,            D3DTOP_MODULATE);

                    wcscpy(g_blend_info, BLEND_INFO_DARK);
                }
                
            else if(g_blend_flag == BLEND_DARK_ANIM)
                {
                    pd3dDevice
            ->SetTexture(0, g_base_texture);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLOROP,            D3DTOP_SELECTARG1);

                    pd3dDevice
            ->SetTexture(1, g_dark_texture);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG2,        D3DTA_CURRENT);

                    
            static double last_time = 0.0f;
                    
            double interval = fTime - last_time;

                    
            if(interval < 0.5f)
                        pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE);
                    
            else if(interval > 0.5f && interval < 1.0f)
                        pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);
                    
            else if(interval > 1.0f && interval < 1.5f)
                        pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE4X);
                    
            else if(interval > 1.5f)
                        last_time 
            = fTime;

                    wcscpy(g_blend_info, BLEND_INFO_DARK_ANIM);
                }
                
            else if(g_blend_flag == BLEND_TEXTURE_DIFFUSE)
                {
                    pd3dDevice
            ->SetRenderState(D3DRS_LIGHTING, TRUE);
                    pd3dDevice
            ->SetRenderState(D3DRS_AMBIENT,  0x00808080);
                    pd3dDevice
            ->SetLight(0&g_light);
                    pd3dDevice
            ->LightEnable(0, TRUE);
                    pd3dDevice
            ->SetMaterial(&g_material);

                    pd3dDevice
            ->SetTexture(0, g_base_texture);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG2,        D3DTA_DIFFUSE);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLOROP,            D3DTOP_ADD);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP,            D3DTOP_DISABLE);
                    
                    wcscpy(g_blend_info, BLEND_INFO_TEXTURE_DIFFUSE);
                }
                
            else if(g_blend_flag == BLEND_DARK_DIFFUSE)
                {
                    pd3dDevice
            ->SetRenderState(D3DRS_LIGHTING, TRUE);
                    pd3dDevice
            ->SetRenderState(D3DRS_AMBIENT,  0x0080FFFF);
                    pd3dDevice
            ->SetLight(0&g_light);
                    pd3dDevice
            ->LightEnable(0, TRUE);
                    pd3dDevice
            ->SetMaterial(&g_material);

                    pd3dDevice
            ->SetTexture(0, g_base_texture);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG2,        D3DTA_DIFFUSE);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLOROP,            D3DTOP_MODULATE);
                    
                    pd3dDevice
            ->SetTexture(1, g_dark_texture);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG2,        D3DTA_CURRENT);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP,            D3DTOP_MODULATE);

                    wcscpy(g_blend_info, BLEND_INFO_DARK_DIFFUSE);
                }
                
            else if(g_blend_flag == BLEND_GLOW)
                {
                    pd3dDevice
            ->SetTexture(0, g_base_texture);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG1,        D3DTA_TEXTURE);        
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLOROP,            D3DTOP_SELECTARG1);

                    pd3dDevice
            ->SetTexture(1, g_dark_texture);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG2,        D3DTA_CURRENT);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP,            D3DTOP_ADD);

                    wcscpy(g_blend_info, BLEND_INFO_GLOW);        
                }
                
            else if(g_blend_flag == BLEND_DETAIL)
                {
                    pd3dDevice
            ->SetTexture(0, g_base_texture);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLORARG1,        D3DTA_TEXTURE);        
                    pd3dDevice
            ->SetTextureStageState(0, D3DTSS_COLOROP,            D3DTOP_SELECTARG1);

                    pd3dDevice
            ->SetTexture(1, g_detail_texture);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_TEXCOORDINDEX,    0);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG1,        D3DTA_TEXTURE);
                    pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLORARG2,        D3DTA_CURRENT);

                    hr 
            = pd3dDevice->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_ADDSIGNED);

                    
            if(FAILED(hr))
                        pd3dDevice
            ->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_MODULATE2X);

                    wcscpy(g_blend_info, BLEND_INFO_DETAIL);
                }
            }

            //--------------------------------------------------------------------------------------
            // Render the helper information
            //--------------------------------------------------------------------------------------
            void RenderText()
            {
                CDXUTTextHelper text_helper(g_font, g_text_sprite, 
            20);
                
                text_helper.Begin();

                
            // show frame and device states
                text_helper.SetInsertionPos(55);
                text_helper.SetForegroundColor(FONT_COLOR);
                text_helper.DrawTextLine( DXUTGetFrameStats(
            true) );
                text_helper.DrawTextLine( DXUTGetDeviceStats() );

                
            // show other simple information
                text_helper.SetForegroundColor( D3DXCOLOR(1.0f1.0f1.0f1.0f) );
                text_helper.DrawTextLine(g_blend_info);

                
            // show helper information
                
                
            const D3DSURFACE_DESC* surface_desc = DXUTGetBackBufferSurfaceDesc();

                
            if(g_show_help)
                {
                    text_helper.SetInsertionPos(
            10, surface_desc->Height - 18 * 10);
                    text_helper.SetForegroundColor(FONT_COLOR);
                    text_helper.DrawTextLine(L
            "Controls (F1 to hide):");
                    
                    text_helper.SetInsertionPos(
            40, surface_desc->Height - 18 * 9);
                    text_helper.DrawTextLine(L
            "Quit: ESC");

                    text_helper.DrawTextLine(L
            "");
                    text_helper.DrawTextLine(L
            "1: Dark Blend");
                    text_helper.DrawTextLine(L
            "2: Dark Blend Animation");
                    text_helper.DrawTextLine(L
            "3: Blend Texture and Vertex Diffuse Color");
                    text_helper.DrawTextLine(L
            "4: Blend Texture and Vertex Diffuse Color and Dark");
                    text_helper.DrawTextLine(L
            "5: Glow Mapping");
                    text_helper.DrawTextLine(L
            "6: Detail Mapping");        
                }
                
            else
                {
                    text_helper.SetInsertionPos(
            10, surface_desc->Height - 15 * 4);
                    text_helper.SetForegroundColor( D3DXCOLOR(
            1.0f1.0f1.0f1.0f) );
                    text_helper.DrawTextLine(L
            "Press F1 for help");
                }

                text_helper.End();
            }

            //--------------------------------------------------------------------------------------
            // Render the scene 
            //--------------------------------------------------------------------------------------
            void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext )
            {
                HRESULT hr;

                
            if(g_settings_dlg.IsActive())
                {
                    g_settings_dlg.OnRender(fElapsedTime);
                    
            return;
                }

                
            // Clear the render target and the zbuffer 
                V( pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0326480), 1.0f0) );

                
            // Render the scene
                if( SUCCEEDED( pd3dDevice->BeginScene() ) )
                {
                    pd3dDevice
            ->SetStreamSource(0, g_vertex_buffer, 0sizeof(sCustomVertex));
                    pd3dDevice
            ->SetFVF(D3DFVF_CUSTOM_VERTEX);
                    pd3dDevice
            ->DrawPrimitive(D3DPT_TRIANGLESTRIP, 02);

                    RenderText();

                    V(g_button_dlg.OnRender(fElapsedTime));

                    V( pd3dDevice
            ->EndScene() );
                }
            }


            //--------------------------------------------------------------------------------------
            // Handle messages to the application 
            //--------------------------------------------------------------------------------------
            LRESULT CALLBACK MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, 
                                      
            bool* pbNoFurtherProcessing, void* pUserContext )
            {
                
            *pbNoFurtherProcessing = g_dlg_resource_manager.MsgProc(hWnd, uMsg, wParam, lParam);
                
            if(*pbNoFurtherProcessing)
                    
            return 0;

                
            if(g_settings_dlg.IsActive())
                {
                    g_settings_dlg.MsgProc(hWnd, uMsg, wParam, lParam);
                    
            return 0;
                }

                
            *pbNoFurtherProcessing = g_button_dlg.MsgProc(hWnd, uMsg, wParam, lParam);
                
            if(*pbNoFurtherProcessing)
                    
            return 0;

                
            return 0;
            }


            //--------------------------------------------------------------------------------------
            // Handle keybaord event
            //--------------------------------------------------------------------------------------
            void CALLBACK OnKeyboardProc(UINT charater, bool is_key_down, bool is_alt_down, void* user_context)
            {
                
            if(is_key_down)
                {
                    
            switch(charater)
                    {
                    
            case VK_F1:
                        g_show_help 
            = !g_show_help;
                        
            break;
                    
            case 49:    // press key "1"
                        g_blend_flag = BLEND_DARK;
                        
            break;
                    
            case 50:    // press key "2"
                        g_blend_flag = BLEND_DARK_ANIM;
                        
            break;
                    
            case 51:    // press key "3"
                        g_blend_flag = BLEND_TEXTURE_DIFFUSE;
                        
            break;
                    
            case 52:    // press key "4"
                        g_blend_flag = BLEND_DARK_DIFFUSE;
                        
            break;
                    
            case 53:    // press key "5"
                        g_blend_flag = BLEND_GLOW;
                        
            break;
                    
            case 54:    // press key "6"
                        g_blend_flag = BLEND_DETAIL;
                        
            break;
                    }
                }
            }

            //--------------------------------------------------------------------------------------
            // Handle events for controls
            //--------------------------------------------------------------------------------------
            void CALLBACK OnGUIEvent(UINT eventint control_id, CDXUTControl* control, void* user_context)
            {
                
            switch(control_id)
                {
                
            case IDC_TOGGLE_FULLSCREEN:
                    DXUTToggleFullScreen();
                    
            break;

                
            case IDC_TOGGLE_REF:
                    DXUTToggleREF();
                    
            break;

                
            case IDC_CHANGE_DEVICE:
                    g_settings_dlg.SetActive(
            true);
                    
            break;
                }
            }

            //--------------------------------------------------------------------------------------
            // Initialize dialogs
            //--------------------------------------------------------------------------------------
            void InitDialogs()
            {
                g_settings_dlg.Init(
            &g_dlg_resource_manager);
                g_button_dlg.Init(
            &g_dlg_resource_manager);

                g_button_dlg.SetCallback(OnGUIEvent);

                
            int x = 35, y = 10, width = 125, height = 22;

                g_button_dlg.AddButton(IDC_TOGGLE_FULLSCREEN, L
            "Toggle full screen", x, y,         width, height);
                g_button_dlg.AddButton(IDC_TOGGLE_REF,          L
            "Toggle REF (F3)",     x, y += 24, width, height);
                g_button_dlg.AddButton(IDC_CHANGE_DEVICE,      L
            "Change device (F2)", x, y += 24, width, height, VK_F2);    
            }

            //--------------------------------------------------------------------------------------
            // Initialize everything and go into a render loop
            //--------------------------------------------------------------------------------------
            INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
            {
                
            // Enable run-time memory check for debug builds.
            #if defined(DEBUG) | defined(_DEBUG)
                _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF 
            | _CRTDBG_LEAK_CHECK_DF );
            #endif

                
            // Set the callback functions
                DXUTSetCallbackDeviceCreated( OnCreateDevice );
                DXUTSetCallbackDeviceReset( OnResetDevice );
                DXUTSetCallbackDeviceLost( OnLostDevice );
                DXUTSetCallbackDeviceDestroyed( OnDestroyDevice );
                DXUTSetCallbackMsgProc( MsgProc );
                DXUTSetCallbackFrameRender( OnFrameRender );
                DXUTSetCallbackFrameMove( OnFrameMove );
                DXUTSetCallbackKeyboard(OnKeyboardProc);
               
                
            // TODO: Perform any application-level initialization here
                InitDialogs();

                
            // Initialize DXUT and create the desired Win32 window and Direct3D device for the application
                DXUTInit( truetruetrue ); // Parse the command line, handle the default hotkeys, and show msgboxes
                DXUTSetCursorSettings( truetrue ); // Show the cursor and clip it when in full screen
                DXUTCreateWindow( L"Texture Color Blend" );
                DXUTCreateDevice( D3DADAPTER_DEFAULT, 
            true640480, IsDeviceAcceptable, ModifyDeviceSettings );

                
            // Start the render loop
                DXUTMainLoop();

                
            // TODO: Perform any application-level cleanup here

                
            return DXUTGetExitCode();
            }

             

             

            下載示例工程


            posted on 2008-05-20 14:47 lovedday 閱讀(1610) 評論(1)  編輯 收藏 引用

            評論

            # re: 高級紋理映射技術(4) 2008-05-20 15:45 w2001

            寫得很好!向博主學習!  回復  更多評論   

            公告

            導航

            統計

            常用鏈接

            隨筆分類(178)

            3D游戲編程相關鏈接

            搜索

            最新評論

            91久久成人免费| 中文国产成人精品久久亚洲精品AⅤ无码精品| 国产精品久久久99| 国产精品美女久久久久网| 亚洲精品乱码久久久久久中文字幕| 日本加勒比久久精品| 无码8090精品久久一区| 久久五月精品中文字幕| 婷婷久久综合九色综合绿巨人| 久久亚洲国产精品五月天婷| 亚洲精品国精品久久99热| 色天使久久综合网天天| 无码日韩人妻精品久久蜜桃 | 久久这里只精品99re66| 久久精品无码专区免费| 亚洲午夜无码久久久久小说| 亚洲中文字幕无码久久精品1| 久久婷婷五月综合国产尤物app| 久久99精品久久久久久动态图 | 久久久久综合中文字幕| 亚洲欧洲久久av| 久久精品毛片免费观看| 7国产欧美日韩综合天堂中文久久久久 | 久久九九久精品国产| 国产69精品久久久久观看软件| 久久综合九色综合网站| 狠狠综合久久综合中文88 | 久久这里有精品视频| 亚洲国产日韩欧美综合久久| 一本色道久久88—综合亚洲精品| 久久久一本精品99久久精品66| 国产99久久久国产精免费| 欧美久久综合九色综合| 久久精品国产亚洲av麻豆小说| 精品免费久久久久国产一区 | 久久久久久久久66精品片| 久久亚洲私人国产精品vA| 久久精品夜色噜噜亚洲A∨| 2021少妇久久久久久久久久| 一本久久综合亚洲鲁鲁五月天| 麻豆亚洲AV永久无码精品久久|