青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強而不息

D3D中的紋理貼圖(2)

 
本篇是D3D中的紋理貼圖(1)的后續(xù)篇,編寫了一個例子來演示同時使用紋理,光照和材質(zhì)進行渲染。
 

需要在工程中設(shè)置鏈接d3dx9.lib d3d9.lib dxguid.lib dinput8.lib winmm.lib。
由于文件中用到了GE_APP和GE_INPUT這兩個類,它們的具體使用說明請參閱 主窗口和DirectInput的封裝。
還用到了GE_TIMER類,具體說明請參閱
游戲中時間的封裝。
材質(zhì)和光照的具體內(nèi)容請參閱 D3D中的材質(zhì)和光照處理 。

若發(fā)現(xiàn)代碼中存在錯誤,敬請指出。

源碼及素材下載

來看看頭文件TextureCone.h的定義:

/*************************************************************************************
 [Include File]

 PURPOSE: 
    Define for material, light, texture mapped.
*************************************************************************************/


#ifndef TEXTURE_CONE_H
#define TEXTURE_CONE_H

////////////////////////////////////////// TYPES AND MACROS //////////////////////////////////////////

#define TIGER   0
#define CHESS   1
#define WALL    2

// define for cone
struct CONE_CUSTOM_VERTEX
{
    float x, y, z;
    float nx, ny, nz;
    float u, v;
};

#define CONE_CUSTOM_VERTEX_FVF  (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)

// define for square
struct SQUARE_CUSTOM_VERTEX
{
    float x, y, z, rhw;
    float u, v;
};

#define SQUARE_CUSTOM_VERTEX_FVF    (D3DFVF_XYZRHW | D3DFVF_TEX1)

////////////////////////////////////////// CLASS //////////////////////////////////////////

class TEXTURE_CONE
{
    IDirect3D9* _d3d;
    IDirect3DDevice9* _d3d_device;

    IDirect3DVertexBuffer9* _cone_vertex_buffer;
    IDirect3DVertexBuffer9* _square_vertex_buffer;

    IDirect3DTexture9* _tiger_texture;
    IDirect3DTexture9* _chess_texture;
    IDirect3DTexture9* _wall_texture;

public:
    TEXTURE_CONE();
    ~TEXTURE_CONE();

    bool Create_D3D_Device(HWND hwnd, bool full_screen = true);
    bool Init_Cone_Vertex_Buffer();
    bool Init_Square_Vertex_Buffer();
    void Set_Camera();
    void Set_Point_Light(D3DCOLORVALUE& dif, D3DCOLORVALUE& amb, D3DCOLORVALUE& spe, D3DVECTOR& pos);
    void Set_Object_Material(D3DCOLORVALUE& dif, D3DCOLORVALUE& amb, D3DCOLORVALUE& spe, 
                             D3DCOLORVALUE& emi, float power);
    void Compute_Triangle_Normal(D3DXVECTOR3& v1, D3DXVECTOR3& v2, D3DXVECTOR3& v3, D3DVECTOR& normal);
    bool Create_All_Texture();
    void Set_Texture(int choice);
    void Render();
    void Release_COM_Object();
};

#endif

再來看看它的實現(xiàn),即TextureCone.cpp的定義:
 
/*************************************************************************************
 [Implement File]

 PURPOSE: 
    Define for material, light, texture mapped.
*************************************************************************************/


#include "GE_COMMON.h"
#include "TextureCone.h"

//------------------------------------------------------------------------------------
// Constructor, initialize all pointer with NULL.
//------------------------------------------------------------------------------------
TEXTURE_CONE::TEXTURE_CONE()
{
    _d3d = NULL;
    _d3d_device = NULL;

    _cone_vertex_buffer   = NULL;
    _square_vertex_buffer = NULL;

    _tiger_texture = NULL;
    _chess_texture = NULL;
    _wall_texture  = NULL;
}

//------------------------------------------------------------------------------------
// Destructor, release resource allocated for COM object.
//------------------------------------------------------------------------------------
TEXTURE_CONE::~TEXTURE_CONE()
{
    Release_COM_Object();
}

//------------------------------------------------------------------------------------
// Create direct3D interface and direct3D device.
//------------------------------------------------------------------------------------
bool TEXTURE_CONE::Create_D3D_Device(HWND hwnd, bool full_screen)
{
    // Create a IDirect3D9 object and returns an interace to it.
    _d3d = Direct3DCreate9(D3D_SDK_VERSION);
    if(_d3d == NULL)
        return false;

    // retrieve adapter capability
    D3DCAPS9 d3d_caps;    
    _d3d->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3d_caps);
    
    bool hardware_process_enable = (d3d_caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT ? true : false);

    // Retrieves the current display mode of the adapter.
    D3DDISPLAYMODE display_mode;
    if(FAILED(_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &display_mode)))
        return false;

    // set present parameter for direct3D device
    D3DPRESENT_PARAMETERS present_param = {0};

    present_param.BackBufferWidth      = WINDOW_WIDTH;
    present_param.BackBufferHeight     = WINDOW_HEIGHT;
    present_param.BackBufferFormat     = display_mode.Format;
    present_param.BackBufferCount      = 1;
    present_param.hDeviceWindow        = hwnd;
    present_param.Windowed             = !full_screen;
    present_param.SwapEffect           = D3DSWAPEFFECT_FLIP;
    present_param.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;

    // Creates a device to represent the display adapter.
    DWORD behavior_flags;

    behavior_flags = hardware_process_enable ? 
D3DCREATE_HARDWARE_VERTEXPROCESSING : D3DCREATE_SOFTWARE_VERTEXPROCESSING;

    if(FAILED(_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, behavior_flags, 
                                 &present_param, &_d3d_device)))
    {
        return false;
    }
    
    // create successfully
    return true;
}

//------------------------------------------------------------------------------------
// Initialize vertex buffer for cone.
//------------------------------------------------------------------------------------
bool TEXTURE_CONE::Init_Cone_Vertex_Buffer()
{
    CONE_CUSTOM_VERTEX cone_custom_vertex[12];
    
    D3DXVECTOR3 v[] = 
    {
        D3DXVECTOR3(5.0f, 6.0f, 5.0f),    // left triangle
        D3DXVECTOR3(6.0f, 0.0f, 3.0f),
        D3DXVECTOR3(1.0f, 0.0f, 7.0f),  
        D3DXVECTOR3(5.0f, 6.0f, 5.0f),    // right triangle
        D3DXVECTOR3(10.0f, 0.0f, 8.0f),
        D3DXVECTOR3(6.0f, 0.0f, 3.0f), 
        D3DXVECTOR3(5.0f, 6.0f, 5.0f),    // back triangle
        D3DXVECTOR3(1.0f, 0.0f, 7.0f),
        D3DXVECTOR3(10.0f, 0.0f, 8.0f),
        D3DXVECTOR3(1.0f, 0.0f, 7.0f),    // bottom triangle
        D3DXVECTOR3(6.0f, 0.0f, 3.0f),
        D3DXVECTOR3(10.0f, 0.0f, 8.0f)      
    };

    D3DVECTOR normal;

    // compute all triangle normal
    for(int i = 0; i < 12; i += 3)
    {
        // compute current triangle's normal
        Compute_Triangle_Normal(v[i], v[i+1], v[i+2], normal);

        // assign current vertex coordinate and current triangle normal to custom vertex array
        for(int j = 0; j < 3; j++)
        {
            int k = i + j;

            cone_custom_vertex[k].x  = v[k].x;
            cone_custom_vertex[k].y  = v[k].y;
            cone_custom_vertex[k].z  = v[k].z;
            cone_custom_vertex[k].nx = normal.x;
            cone_custom_vertex[k].ny = normal.y;
            cone_custom_vertex[k].nz = normal.z;
        }
    }

    cone_custom_vertex[0].u  = 0.0f;
    cone_custom_vertex[0].v  = 0.0f;
    cone_custom_vertex[1].u  = 0.0f;
    cone_custom_vertex[1].v  = 1.0f;
    cone_custom_vertex[2].u  = 1.0f;
    cone_custom_vertex[2].v  = 1.0f;

    cone_custom_vertex[3].u  = 0.0f;
    cone_custom_vertex[3].v  = 0.0f;
    cone_custom_vertex[4].u  = 1.0f;
    cone_custom_vertex[4].v  = 0.0f;
    cone_custom_vertex[5].u  = 1.0f;
    cone_custom_vertex[5].v  = 1.0f;

    cone_custom_vertex[6].u  = 0.0f;
    cone_custom_vertex[6].v  = 0.0f;
    cone_custom_vertex[7].u  = 1.0f;
    cone_custom_vertex[7].v  = 0.0f;
    cone_custom_vertex[8].u  = 1.0f;
    cone_custom_vertex[8].v  = 1.0f;

    cone_custom_vertex[9].u  = 0.0f;
    cone_custom_vertex[9].v  = 0.0f;
    cone_custom_vertex[10].u = 1.0f;
    cone_custom_vertex[10].v = 0.0f;
    cone_custom_vertex[11].u = 1.0f;
    cone_custom_vertex[11].v = 1.0f;

    BYTE* vertex_data;

    // create vertex buffer
    if(FAILED(_d3d_device->CreateVertexBuffer(12 * sizeof(CONE_CUSTOM_VERTEX), 0, CONE_CUSTOM_VERTEX_FVF,
                            D3DPOOL_DEFAULT, &_cone_vertex_buffer, NULL)))
    {
        return false;
    }

    // get data pointer to vertex buffer
    if(FAILED(_cone_vertex_buffer->Lock(0, 0, (void **) &vertex_data, 0)))
        return false;

    // copy custom vertex data into vertex buffer
    memcpy(vertex_data, cone_custom_vertex, sizeof(cone_custom_vertex));

    // unlock vertex buffer
    _cone_vertex_buffer->Unlock();

    return true;
}

//------------------------------------------------------------------------------------
// Initialize vertex buffer for square.
//------------------------------------------------------------------------------------
bool TEXTURE_CONE::Init_Square_Vertex_Buffer()
{
    SQUARE_CUSTOM_VERTEX square_custom_vertex[] =     
    {
        {0.0f,   0.0f,   0.0f, 1.0f, 0.0f, 0.0f}, 
        {130.0f, 0.0f,   0.0f, 1.0f, 1.0f, 0.0f}, 
        {0.0f,   130.0f, 0.0f, 1.0f, 0.0f, 1.0f},
        {130.0f, 130.0f, 0.0f, 1.0f, 1.0f, 1.0f}
    };

    BYTE* vertex_data;

    // create vertex buffer
    if(FAILED(_d3d_device->CreateVertexBuffer(12 * sizeof(SQUARE_CUSTOM_VERTEX), 0, SQUARE_CUSTOM_VERTEX_FVF,
                            D3DPOOL_MANAGED, &_square_vertex_buffer, NULL)))
    {
        return false;
    }

    // get data pointer to vertex buffer
    if(FAILED(_square_vertex_buffer->Lock(0, 0, (void **) &vertex_data, 0)))
        return false;

    // copy custom vertex data into vertex buffer
    memcpy(vertex_data, square_custom_vertex, sizeof(square_custom_vertex));

    // unlock vertex buffer
    _square_vertex_buffer->Unlock();

    return true;
}

//------------------------------------------------------------------------------------
// Set camera position.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Set_Camera()
{
    D3DXVECTOR3 eye(-6.0, 1.5, 10.0);
    D3DXVECTOR3 at(6.0, 2.0, 3.0);
    D3DXVECTOR3 up(0.0, 1.0, 0.0);

    D3DXMATRIX view_matrix;

    // Builds a left-handed, look-at matrix.
    D3DXMatrixLookAtLH(&view_matrix, &eye, &at, &up);

    // Sets d3d device view transformation state.
    _d3d_device->SetTransform(D3DTS_VIEW, &view_matrix);

    D3DXMATRIX proj_matrix;

    // Builds a left-handed perspective projection matrix based on a field of view.
    D3DXMatrixPerspectiveFovLH(&proj_matrix, D3DX_PI/2, WINDOW_WIDTH / WINDOW_HEIGHT, 1.0, 1000.0);
    
    // Sets d3d device projection transformation state.
    _d3d_device->SetTransform(D3DTS_PROJECTION, &proj_matrix);
    // enable automatic normalization of vertex normals
    _d3d_device->SetRenderState(D3DRS_NORMALIZENORMALS, true);
}

//------------------------------------------------------------------------------------
// Set point light.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Set_Point_Light(D3DCOLORVALUE& dif, D3DCOLORVALUE& amb, D3DCOLORVALUE& spe, D3DVECTOR& pos)
{
    D3DLIGHT9 light;

    // clear memory with 0
    ZeroMemory(&light, sizeof(D3DLIGHT9));

    light.Type          = D3DLIGHT_POINT;
    light.Diffuse       = dif;
    light.Ambient       = amb;
    light.Specular      = spe;
    light.Position      = pos;
    light.Attenuation0  = 1.0;
    light.Attenuation1  = 0.0;
    light.Attenuation2  = 0.0;
    light.Range         = 1000.0;

    // Assigns point lighting properties for this device
    _d3d_device->SetLight(0, &light);
    // enable point light
    _d3d_device->LightEnable(0, TRUE);
    // enable light 
    _d3d_device->SetRenderState(D3DRS_LIGHTING, TRUE);
    // add ambient light
    _d3d_device->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(50, 50, 50));
}

//------------------------------------------------------------------------------------
// Sets the material properties for the device.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Set_Object_Material(D3DCOLORVALUE& dif, D3DCOLORVALUE& amb, D3DCOLORVALUE& spe, 
                                       D3DCOLORVALUE& emi, float power)
{
    D3DMATERIAL9 material;

    material.Diffuse  = dif;
    material.Ambient  = amb;
    material.Specular = spe;
    material.Emissive = emi;
    material.Power    = power;

    // Sets the material properties for the device.
    _d3d_device->SetMaterial(&material);
}

//------------------------------------------------------------------------------------
// Create all texture interface.
//------------------------------------------------------------------------------------
bool TEXTURE_CONE::Create_All_Texture()
{
    if(FAILED( D3DXCreateTextureFromFile(_d3d_device, "tiger.jpg", &_tiger_texture) ))
        goto fail;

    if(FAILED( D3DXCreateTextureFromFile(_d3d_device, "chess.bmp", &_chess_texture) ))
        goto fail;

    if(FAILED( D3DXCreateTextureFromFile(_d3d_device, "wall.bmp", &_wall_texture) ))
        goto fail;

    return true;

fail:
    MessageBox(NULL, "Create texture interface failed.", "ERROR", MB_OK);
    return false;
}

//------------------------------------------------------------------------------------
// Set texture interface to DirectX3D.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Set_Texture(int choice)
{
    switch(choice)
    {
    case TIGER:
        _d3d_device->SetTexture(0, _tiger_texture);
        break;
    case CHESS:
        _d3d_device->SetTexture(0, _chess_texture);
        break;
    case WALL:
        _d3d_device->SetTexture(0, _wall_texture);
        break;
    }
}

//------------------------------------------------------------------------------------
// Draw cone and square.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Render()
{
    if(_d3d_device == NULL)
        return;

    // clear surface with black
    _d3d_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0, 0);

    // begin scene
    _d3d_device->BeginScene();

    // 1) draw cone with texture stick on surface

    // Binds a vertex buffer to a device data stream.
    _d3d_device->SetStreamSource(0, _cone_vertex_buffer, 0, sizeof(CONE_CUSTOM_VERTEX));

    // Sets the current vertex stream declaration.
    _d3d_device->SetFVF(CONE_CUSTOM_VERTEX_FVF);

    // Sets the sampler state value.
    
    // D3DSAMP_MIPFILTER: 
    //      Mipmap filter to use during minification.
    //
    // D3DTEXF_POINT:
    //      Point filtering used as a texture magnification or minification filter. The texel with coordinates 
    //      nearest to the desired pixel value is used. The texture filter to be used between mipmap levels 
    //      is nearest-point mipmap filtering. The rasterizer uses the color from the texel of the nearest 
    //      mipmap texture. 
    _d3d_device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

    // D3DSAMP_MAGFILTER:
    //      Magnification filter of type D3DTEXTUREFILTERTYPE. 
    //
    // D3DTEXF_LINEAR:
    //      Bilinear interpolation filtering used as a texture magnification or minification filter.
    //      A weighted average of a 2 × 2 area of texels surrounding the desired pixel is used. 
    //      The texture filter to use between mipmap levels is trilinear mipmap interpolation. 
    //      The rasterizer linearly interpolates pixel color, using the texels of the two nearest mipmap textures.
    _d3d_device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

    // D3DSAMP_MINFILTER:
    //      Minification filter of type D3DTEXTUREFILTERTYPE. 
    _d3d_device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);

    // Renders a sequence of nonindexed, geometric primitives of the specified type from the current 
    // set of data input streams.
    _d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4);

    // 2) draw square with texture stick on surface

    // Binds a vertex buffer to a device data stream. 
    _d3d_device->SetStreamSource(0, _square_vertex_buffer, 0, sizeof(SQUARE_CUSTOM_VERTEX));

    // Sets the current vertex stream declaration.
    _d3d_device->SetFVF(SQUARE_CUSTOM_VERTEX_FVF);

    // draw square
    _d3d_device->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

    // end scene
    _d3d_device->EndScene();

    // Presents the contents of the next buffer in the sequence of back buffers owned by the device.
    _d3d_device->Present(NULL, NULL, NULL, NULL);
}

//------------------------------------------------------------------------------------
// Compute triangle normal.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Compute_Triangle_Normal(D3DXVECTOR3& v1, D3DXVECTOR3& v2, D3DXVECTOR3& v3, D3DVECTOR& normal)
{
    D3DXVECTOR3 vec1 = v1 - v2;
    D3DXVECTOR3 vec2 = v1 - v3;
    D3DXVECTOR3 normal_vec;

    D3DXVec3Cross(&normal_vec, &vec1, &vec2);
    D3DXVec3Normalize(&normal_vec, &normal_vec);

    normal = (D3DVECTOR) normal_vec;
}

//------------------------------------------------------------------------------------
// Release all resource allocated for D3D.
//------------------------------------------------------------------------------------
void TEXTURE_CONE::Release_COM_Object()
{
    Safe_Release(_tiger_texture);
    Safe_Release(_chess_texture);
    Safe_Release(_wall_texture);

    Safe_Release(_square_vertex_buffer);
    Safe_Release(_cone_vertex_buffer);

    Safe_Release(_d3d_device);
    Safe_Release(_d3d);
}

這里主要指出Render()函數(shù)需要注意的一個細節(jié),在繪制三棱錐時的代碼:

_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4);

而在繪制正方形時的代碼是:

_d3d_device- >DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

一個是D3DPT_TRIANGLELIST,另一個卻是D3DPT_TRIANGLESTRIP,這是因為他們存儲頂點的方式不同,來看看SDK文檔提供的說明:
 
D3DPT_TRIANGLELIST
Renders the specified vertices as a sequence of isolated triangles. Each group of three vertices defines a separate triangle.
Back-face culling is affected by the current winding-order render state.

D3DPT_TRIANGLESTRIP
Renders the vertices as a triangle strip. The backface-culling flag is automatically flipped on even-numbered triangles.

 


三棱錐數(shù)組存儲了12個頂點,每個三角形面有3個頂點,所以12個頂點共存儲了4個三角形面的頂點,這些頂點部分重復(fù)了,所以使用 D3DPT_TRIANGLELIST模式來繪制。

CONE_CUSTOM_VERTEX cone_custom_vertex[12];

而正方形僅僅保存了4個頂點的數(shù)據(jù),頂點存儲沒有冗余,頂點被一些面共用,所以使用D3DPT_TRIANGLESTRIP來渲染。


SQUARE_CUSTOM_VERTEX square_custom_vertex[] =    
    {
        {0.0f,   0.0f,   0.0f, 1.0f, 0.0f, 0.0f},
        {130.0f, 0.0f,   0.0f, 1.0f, 1.0f, 0.0f},
        {0.0f,   130.0f, 0.0f, 1.0f, 0.0f, 1.0f},
        {130.0f, 130.0f, 0.0f, 1.0f, 1.0f, 1.0f}
    };

再來看看測試代碼main.cpp:

/*************************************************************************************
 [Implement File]

 PURPOSE: 
    Test for texture, material, lighting.
*************************************************************************************/


#define DIRECTINPUT_VERSION 0x0800

#include "GE_COMMON.h"
#include "GE_APP.h"
#include "GE_INPUT.h"
#include "GE_TIMER.h"
#include "TextureCone.h"

#pragma warning(disable : 4305 4996)

int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR cmd_line, int cmd_show)
{
    GE_APP ge_app;
    GE_INPUT ge_input;  
    GE_TIMER ge_timer;  
    TEXTURE_CONE texture_cone;

    MSG msg = {0};

    // define property for material
    D3DCOLORVALUE material_dif = {1.0f, 1.0f, 1.0f, 1.0f}; 
    D3DCOLORVALUE material_amb = {1.0f, 1.0f, 1.0f, 1.0f};
    D3DCOLORVALUE material_spe = {1.0f, 0.0f, 0.0f, 1.0f};
    D3DCOLORVALUE material_emi = {0.0f, 0.0f, 1.0f, 1.0f};

    // define property for light
    D3DCOLORVALUE light_dif = {1.0f, 0.0f, 0.0f, 1.0f};  
    D3DCOLORVALUE light_amb = {0.0f, 0.7f, 0.0f, 1.0f};
    D3DCOLORVALUE light_spe = {0.0f, 0.0f, 0.0f, 0.0f};

    D3DVECTOR light_pos = {5.0f, 6.0f, -20.0f};

    float last_render_time = 0;

    // create window
    if(! ge_app.Create_Window("Material and light test", instance, cmd_show))
        return false;

    HWND hwnd = ge_app.Get_Window_Handle();

    // create directinput
    ge_input.Create_Input(instance, hwnd);

    SetWindowPos(hwnd, 0, 0,0,0,0, SWP_NOSIZE);
    SetCursorPos(0, 0);

    // initialize game time
    ge_timer.Init_Game_Time();

    // Create direct3D interface and direct3D device.
    if(! texture_cone.Create_D3D_Device(hwnd, false))
        return false;

    // Initialize cone vertex buffer with curstom vertex structure.
    if(! texture_cone.Init_Cone_Vertex_Buffer())
        return false;

    // Initialize square vertex buffer with curstom vertex structure.
    if(! texture_cone.Init_Square_Vertex_Buffer())
        return false;

    // Create all texture interface.
    texture_cone.Create_All_Texture();

    // Set camera position.
    texture_cone.Set_Camera();

    // Sets the material properties for the device.
    texture_cone.Set_Object_Material(material_dif, material_amb, material_spe, material_emi, 0);

    // Set point light.
    texture_cone.Set_Point_Light(light_dif, light_amb, light_spe, light_pos);

    // Set texture interface to tiger
    texture_cone.Set_Texture(TIGER);

    // Draw cone and square.
    texture_cone.Render();

    while(msg.message != WM_QUIT)
    {
        if(PeekMessage(&msg, NULL, 0,0 , PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        else
        {           
            // read data from keyboard buffer
            if(ge_input.Read_Keyboard())
            {
                // press "ESC", close window.
                if(ge_input.Is_Key_Pressed(DIK_ESCAPE))
                    PostQuitMessage(0);

                bool key_left_pressed  = ge_input.Is_Key_Pressed(DIK_LEFT);
                bool key_right_pressed = ge_input.Is_Key_Pressed(DIK_RIGHT);
                bool key_up_pressed    = ge_input.Is_Key_Pressed(DIK_UP);                
                
                // set texture address mode
                if(key_left_pressed || key_right_pressed || key_up_pressed)
                {
                    // Set texture interface to DirectX3D.

                    if(key_left_pressed)                                            
                        texture_cone.Set_Texture(TIGER);                        

                    if(key_right_pressed)
                        texture_cone.Set_Texture(CHESS);            

                    if(key_up_pressed)
                        texture_cone.Set_Texture(WALL);       
                    
                    // draw cone and square
                    texture_cone.Render();
                }                
            } 
            
            // if it is time to reset light
            if((ge_timer.Get_Game_Play_Time() - last_render_time) > 30)
            {
                if(light_amb.r < 1.0f)
                    light_amb.r += 0.001f;
                else
                    light_amb.r = 0.0f;

                if(light_amb.g < 1.0f)
                    light_amb.g += 0.02f;
                else
                    light_amb.g = 0.0f;

                if(light_amb.b < 1.0f)
                    light_amb.b += 0.03f;
                else
                    light_amb.b = 0.0f;

                texture_cone.Set_Point_Light(light_dif, light_amb, light_spe, light_pos);
                texture_cone.Render();

                // update last render time
                last_render_time = ge_timer.Get_Game_Play_Time();
            }
        }
    }    

    UnregisterClass(WINDOW_CLASS_NAME, instance);

    return true;
}

用左右上三個方向鍵控制使用不同的紋理圖渲染。

運行效果:






 
 

posted on 2007-05-14 00:04 lovedday 閱讀(2794) 評論(2)  編輯 收藏 引用

評論

# re: D3D中的紋理貼圖(1) 2007-11-16 10:28 11

不知道如何給紋理貼圖+變量,可以控制貼圖的數(shù)量在規(guī)定的范圍內(nèi)
  回復(fù)  更多評論   

# re: D3D中的紋理貼圖(2) 2010-06-25 00:38 bruce

兄之文章,言簡意賅,深入淺出,實為DX學(xué)習(xí)之佳品。讀之即有醍醐灌頂之感。實在是難得啊。  回復(fù)  更多評論   

公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            国产亚洲精品久久久| 国产精品综合久久久| 久久夜色精品国产噜噜av| 亚洲欧洲精品天堂一级| 国产精品美女在线| 国产精品qvod| 国产精品视频免费| 国产精品一区二区在线观看不卡| 麻豆成人精品| 久久精品99国产精品日本| 亚洲视频一起| 久久xxxx| 久久伊人亚洲| 欧美日韩色婷婷| 欧美成人久久| 欧美体内谢she精2性欧美| 亚洲国产日韩欧美在线图片| 国产精品一区二区在线| 国产午夜精品全部视频在线播放| 国产九九精品视频| 精品96久久久久久中文字幕无| 亚洲激情综合| 久久国产婷婷国产香蕉| 久久综合999| 亚洲美女在线国产| 久久精品日韩欧美| 国产精品99一区| 亚洲国产成人久久| 午夜视频在线观看一区二区| 久久综合九色九九| 亚洲尤物视频网| 欧美美女喷水视频| 欧美在线中文字幕| 亚洲国产精品久久久| 欧美一区二区三区视频在线观看| 欧美成va人片在线观看| 午夜精品久久99蜜桃的功能介绍| 欧美国产视频在线观看| 国产在线观看91精品一区| 99精品国产一区二区青青牛奶| 亚洲影视在线播放| 欧美激情女人20p| 欧美成人亚洲| 一区二区三区导航| 中文av一区特黄| 国产欧美精品xxxx另类| 午夜久久一区| 欧美亚洲免费电影| 一区二区视频欧美| 亚洲国产精品ⅴa在线观看| 国产精品久久久一区二区三区| 亚洲国产一区二区在线| 免费看成人av| 国产精品久久福利| 久久免费高清| 欧美精品999| 午夜在线一区二区| 蜜臀久久99精品久久久久久9| 亚洲日本aⅴ片在线观看香蕉| 亚洲啪啪91| 亚洲电影激情视频网站| 欧美一区二区三区精品电影| 亚洲人成网站在线观看播放| 欧美国产日韩免费| 久久爱www| 欧美精品v国产精品v日韩精品 | 狠狠色狠狠色综合| 亚洲国产另类精品专区| 欧美日韩免费观看一区| 噜噜噜噜噜久久久久久91| 欧美视频一区二区三区四区| 久久成人av少妇免费| 欧美日本网站| 亚洲七七久久综合桃花剧情介绍| 国产欧美不卡| 亚洲午夜在线观看视频在线| 99av国产精品欲麻豆| 久久久久久国产精品mv| 午夜久久资源| 国产精品qvod| 亚洲一区欧美激情| 午夜精品久久久久久久| 亚洲一区二区三区中文字幕 | 在线亚洲美日韩| 亚洲激情视频网站| 欧美成人视屏| 亚洲精品黄色| 午夜精品久久久久久久久久久久 | 亚洲国产精品一区| 亚洲精品一区二区三区樱花| 欧美电影打屁股sp| 99精品久久久| 久久视频免费观看| 亚洲激情成人| 亚洲砖区区免费| 亚洲精品资源美女情侣酒店| 亚洲天天影视| 韩国精品主播一区二区在线观看| 久久午夜精品| 国产精品99久久久久久有的能看| 久久国产精品一区二区三区| 亚洲激情在线播放| 国产情人节一区| 欧美激情欧美激情在线五月| 亚洲天堂激情| 亚洲精品乱码久久久久久久久 | 在线亚洲观看| 久久综合综合久久综合| 国产精品99久久99久久久二8 | 理论片一区二区在线| 欧美大色视频| 亚洲一区二区三区四区中文| 亚洲第一综合天堂另类专| 亚洲欧美日韩在线观看a三区| 亚洲午夜视频在线观看| 国产日韩精品一区二区| 亚洲电影免费在线观看| 欧美日韩一区三区四区| 久久综合久久综合九色| 欧美另类久久久品| 欧美大片一区二区| 国产精品视频导航| 亚洲激情精品| 一区精品在线播放| 欧美一区永久视频免费观看| 一区二区三区日韩| 噜噜噜91成人网| 另类专区欧美制服同性| 国产人成一区二区三区影院| 一区二区三区欧美| 亚洲精品视频中文字幕| 免费观看欧美在线视频的网站| 欧美主播一区二区三区| 国产精品久久久久久久久免费| 亚洲清纯自拍| 日韩视频亚洲视频| 欧美成人一区在线| 亚洲成人在线免费| 亚洲特级片在线| 欧美尤物一区| 欧美专区在线观看一区| 国产精品久久久久久久久久妞妞| 一本色道88久久加勒比精品| 正在播放亚洲一区| 欧美午夜精品久久久久久孕妇 | 欧美一区日本一区韩国一区| 欧美一级午夜免费电影| 国产欧美日韩综合精品二区| 先锋影音国产精品| 久久这里有精品视频| 亚洲国产精品专区久久| 欧美激情女人20p| 在线一区二区三区四区五区| 羞羞答答国产精品www一本 | 亚洲性线免费观看视频成熟| 国产精品电影在线观看| 亚洲欧美日韩综合| 久久综合精品国产一区二区三区| 亚洲欧洲一区二区三区| 欧美另类变人与禽xxxxx| 亚洲制服少妇| 免费视频一区二区三区在线观看| 亚洲精品中文字幕在线观看| 亚洲女人小视频在线观看| 性欧美xxxx视频在线观看| 久久久之久亚州精品露出| 亚洲精品永久免费精品| 性色av一区二区怡红| 欧美成人午夜激情在线| 一区二区久久久久| 国产视频一区二区在线观看 | 亚洲免费观看高清完整版在线观看熊 | 久久精品国产亚洲精品| 亚洲国产成人tv| 午夜日韩激情| 亚洲国产美国国产综合一区二区| 欧美日韩三级在线| 欧美在线欧美在线| 亚洲美女91| 玖玖国产精品视频| 亚洲影院高清在线| 亚洲欧洲日夜超级视频| 国产日韩欧美精品| 欧美日韩www| 另类人畜视频在线| 性18欧美另类| 亚洲视频精选| 最新国产乱人伦偷精品免费网站 | 精品成人乱色一区二区| 美女999久久久精品视频| 亚洲三级电影在线观看| 午夜一区在线| 亚洲黄色有码视频| 久久精品国产v日韩v亚洲| 亚洲高清一二三区| 国产欧美日韩伦理| 欧美日韩三级| 免费在线日韩av| 久久国产精品黑丝| 亚洲在线中文字幕|