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

天行健 君子當自強而不息

D3D中的Alpha顏色混合(2)

 

本篇是D3D中的Alpha顏色混合(1)的后續篇,主要講利用ID3DXSprite來實現圖片間的顏色透明效果。

在一幅圖象上透明的顯示另一幅圖象,是Alpha顏色混合的一個典型應用,如下圖所示,瞄準鏡圖象背景透明地顯示在老虎背景圖象上。



實現瞄準鏡的背景透明顯示,首先需要準備如下兩張圖:

                                               
  瞄準鏡源圖  (圖1)                                    瞄準鏡Alpha通道(屏蔽圖)(圖2)

Alpha通道圖(屏蔽圖)的黑色像素對應的源圖像素不被顯示出來,Alpha通道圖(屏蔽圖)的白色像素對應的源圖像素會顯示出來。

Alpha 通道圖(屏蔽圖)的像素顏色值是作為DirectX顏色結構體的alpha分量值來使用的。圖2所示的黑色像素將產生一個為0的Alpha值,而白色像素將產生一個為1的Alpha值。如果此時將渲染管道流水線的D3DRS_SRCBLEND源混合因子參數設置為D3DBLEND_SRCALPHA,目標混合因子參數設置為D3DBLEND_INVSRCALPHA,然后先繪制圖1所示的紋理圖,再繪制圖2所示的紋理圖,那么混合后的結果將是圖1所示的白色背景不被顯示出來,僅顯示一個圓和一個十字形,正因為Alpha通道圖具有以上的屏蔽效果,因此圖2所示的Alpha通道圖也稱為屏蔽圖。

如果直接采用上面的方法實現圖形間的透明效果,那么需要進行3次紋理貼圖,并設置好相應的混合參數。第一次先繪制出老虎背景圖,接著繪制瞄準鏡源圖,最后繪制瞄準鏡Alpha通道圖。這樣做顯然是比較繁瑣的,因此可用DirectX提供的ID3DXSprite接口進行繪制。

首先,在DirectX安裝目錄下的Utilities目錄下執行DxTex.exe,這是DirectX提供的用于生成紋理圖象的Alpha通道圖的工具。

(注:如果你執行DxTex.exe時系統提示如下信息:

Unable to create Direct3D Device. Please make sure your desktop color depth is 16 or 32 bit, and that d3dref.dll is installed.

請參考解決方案 運行DxTex.exe碰到的問題

首先執行"File - Open"菜單,將圖1所示的瞄準鏡源圖打開,然后執行"Change Surface Format ..." 菜單,重新設置bmp圖象的像素顏色格式為A8R8G8B8,即添加一個Alpha顏色值。

              

執行新增加的"File - Open onto alpha channel of this texture..."菜單,彈出一個文件打開對話框,選擇圖2所示的瞄準鏡Alpha通道圖并打開,DxTex將自動把Alpha通道圖的屏蔽信息插入圖象中。如下圖所示,DxTex默認的淡藍色背景色表示該像素顏色已為透明色。最后,執行"File - Save"菜單,將同時具有源圖信息和Alpha通道信息的圖象保存為DDS格式的gun.dds。



生成瞄準鏡的DDS文件后,就可以利用d3dx9.lib庫的ID3DXSprite提供的方法,將瞄準鏡背景透明地顯示出來。ID3DXSprite接口對象是通過D3DXCreateSprite函數進行創建的,來看看該函數的具體使用信息:

Creates a sprite object which is associated with a particular device. Sprite objects are used to draw 2D images to the screen.

HRESULT D3DXCreateSprite(
LPDIRECT3DDEVICE9 pDevice,
LPD3DXSPRITE * ppSprite
);

Parameters

pDevice
[in] Pointer to an IDirect3DDevice9 interface, the device to be associated with the sprite.
ppSprite
[out] Address of a pointer to an ID3DXSprite interface. This interface allows the user to access sprite functions.

Return Values

If the function succeeds, the return value is S_OK. If the function fails, the return value can be one of the following: D3DERR_INVALIDCALL, E_OUTOFMEMORY.

Remarks

This interface can be used to draw two dimensional images in screen space of the associated device.


再來看看SDK文檔提供的有關ID3DXSprite的使用說明:

The ID3DXSprite interface provides a set of methods that simplify the process of drawing sprites using Microsoft Direct3D.

ID3DXSprite Members

Method Description
ID3DXSprite::Begin Prepares a device for drawing sprites.
ID3DXSprite::Draw Adds a sprite to the list of batched sprites.
ID3DXSprite::End Calls ID3DXSprite::Flush and restores the device state to how it was before ID3DXSprite::Begin was called.
ID3DXSprite::Flush Forces all batched sprites to be submitted to the device. Device states remain as they were after the last call to ID3DXSprite::Begin. The list of batched sprites is then cleared.
ID3DXSprite::GetDevice Retrieves the device associated with the sprite object.
ID3DXSprite::GetTransform Gets the sprite transform.
ID3DXSprite::OnLostDevice Use this method to release all references to video memory resources and delete all stateblocks. This method should be called whenever a device is lost or before resetting a device.
ID3DXSprite::OnResetDevice Use this method to re-acquire resources and save initial state.
ID3DXSprite::SetTransform Sets the sprite transform.
ID3DXSprite::SetWorldViewLH Sets the left-handed world-view transform for a sprite. A call to this method is required before billboarding or sorting sprites.
ID3DXSprite::SetWorldViewRH Sets the right-handed world-view transform for a sprite. A call to this method is required before billboarding or sorting sprites.

Remarks

The ID3DXSprite interface is obtained by calling the D3DXCreateSprite function.

The application typically first calls ID3DXSprite::Begin, which allows control over the device render state, alpha blending, and sprite transformation and sorting. Then for each sprite to be displayed, call ID3DXSprite::Draw. ID3DXSprite::Draw can be called repeatedly to store any number of sprites. To display the batched sprites to the device, call ID3DXSprite::End or ID3DXSprite::Flush.

The LPD3DXSPRITE type is defined as a pointer to the ID3DXSprite interface.

typedef interface ID3DXSprite ID3DXSprite;
typedef interface ID3DXSprite *LPD3DXSPRITE;

Begin方法和End方法表明繪制精靈圖象的開始和結束,這是一對配套函數,必須用在IDirect3DDevice9::BeginScene和IDirect3DDevice9::EndScene的調用之間。

接著來看看Begin方法的使用說明:

Prepares a device for drawing sprites.

HRESULT Begin(
DWORD Flags
);

Parameters

Flags
[in] Combination of zero or more flags that describe sprite rendering options. For this method, the valid flags are:
  • D3DXSPRITE_ALPHABLEND
  • D3DXSprite__BILLBOARD
  • D3DXSPRITE_DONOTMODIFY_RENDERSTATE
  • D3DXSPRITE_DONOTSAVESTATE
  • D3DXSPRITE_OBJECTSPACE
  • D3DXSprite__SORT_DEPTH_BACKTOFRONT
  • D3DXSprite__SORT_DEPTH_FRONTTOBACK
  • D3DXSprite__SORT_TEXTURE
For a description of the flags and for information on how to control device state capture and device view transforms, see D3DXSPRITE.

Return Values

If the method succeeds, the return value is S_OK. If the method fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DERR_OUTOFVIDEOMEMORY, D3DXERR_INVALIDDATA, E_OUTOFMEMORY.

Remarks

This method must be called from inside a IDirect3DDevice9::BeginScene . . . IDirect3DDevice9::EndScene sequence. ID3DXSprite::Begin cannot be used as a substitute for either IDirect3DDevice9::BeginScene or ID3DXRenderToSurface::BeginScene.

This method will set the following states on the device.

Render States:

Type (D3DRENDERSTATETYPE) Value
D3DRS_ALPHABLENDENABLE TRUE
D3DRS_ALPHAFUNC D3DCMP_GREATER
D3DRS_ALPHAREF 0x00
D3DRS_ALPHATESTENABLE AlphaCmpCaps
D3DRS_BLENDOP D3DBLENDOP_ADD
D3DRS_CLIPPING TRUE
D3DRS_CLIPPLANEENABLE FALSE
D3DRS_COLORWRITEENABLE D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED
D3DRS_CULLMODE D3DCULL_NONE
D3DRS_DESTBLEND D3DBLEND_INVSRCALPHA
D3DRS_DIFFUSEMATERIALSOURCE D3DMCS_COLOR1
D3DRS_ENABLEADAPTIVETESSELLATION FALSE
D3DRS_FILLMODE D3DFILL_SOLID
D3DRS_FOGENABLE FALSE
D3DRS_INDEXEDVERTEXBLENDENABLE FALSE
D3DRS_LIGHTING FALSE
D3DRS_RANGEFOGENABLE FALSE
D3DRS_SEPARATEALPHABLENDENABLE FALSE
D3DRS_SHADEMODE D3DSHADE_GOURAUD
D3DRS_SPECULARENABLE FALSE
D3DRS_SRCBLEND D3DBLEND_SRCALPHA
D3DRS_SRGBWRITEENABLE FALSE
D3DRS_STENCILENABLE FALSE
D3DRS_VERTEXBLEND FALSE
D3DRS_WRAP0 0

Texture Stage States:

Stage Identifier Type (D3DTEXTURESTAGESTATETYPE) Value
0 D3DTSS_ALPHAARG1 D3DTA_TEXTURE
0 D3DTSS_ALPHAARG2 D3DTA_DIFFUSE
0 D3DTSS_ALPHAOP D3DTOP_MODULATE
0 D3DTSS_COLORARG1 D3DTA_TEXTURE
0 D3DTSS_COLORARG2 D3DTA_DIFFUSE
0 D3DTSS_COLOROP D3DTOP_MODULATE
0 D3DTSS_TEXCOORDINDEX 0
0 D3DTSS_TEXTURETRANSFORMFLAGS D3DTTFF_DISABLE
1 D3DTSS_ALPHAOP D3DTOP_DISABLE
1 D3DTSS_COLOROP D3DTOP_DISABLE

Sampler States:

Sampler Stage Index Type (D3DSAMPLERSTATETYPE) Value
0 D3DSAMP_ADDRESSU D3DTADDRESS_CLAMP
0 D3DSAMP_ADDRESSV D3DTADDRESS_CLAMP
0 D3DSAMP_MAGFILTER D3DTEXF_ANISOTROPIC if TextureFilterCaps includes D3DPTFILTERCAPS_MAGFANISOTROPIC; otherwise D3DTEXF_LINEAR
0 D3DSAMP_MAXMIPLEVEL 0
0 D3DSAMP_MAXANISOTROPY MaxAnisotropy
0 D3DSAMP_MINFILTER D3DTEXF_ANISOTROPIC if TextureFilterCaps includes D3DPTFILTERCAPS_MINFANISOTROPIC; otherwise D3DTEXF_LINEAR
0 D3DSAMP_MIPFILTER D3DTEXF_LINEAR if TextureFilterCaps includes D3DPTFILTERCAPS_MIPFLINEAR; otherwise D3DTEXF_POINT
0 D3DSAMP_MIPMAPLODBIAS 0
0 D3DSAMP_SRGBTEXTURE 0

Note    This method disables N-patches.


參數Flags允許設置的D3DXSPRITE模式如下所示:

The following flags are used to specify sprite rendering options to the flags parameter in the ID3DXSprite::Begin method:

#define Description
D3DXSPRITE_DONOTSAVESTATE The device state is not to be saved or restored when ID3DXSprite::Begin or ID3DXSprite::End is called.
D3DXSPRITE_DONOTMODIFY_RENDERSTATE The device render state is not to be changed when ID3DXSprite::Begin is called. The device is assumed to be in a valid state to draw vertices containing UsageIndex = 0 in the D3DDECLUSAGE_POSITION, D3DDECLUSAGE_TEXCOORD, and D3DDECLUSAGE_COLOR data.
D3DXSPRITE_OBJECTSPACE The world, view, and projection transforms are not modified. The transforms currently set to the device are used to transform the sprites when the batched sprites are drawn (when ID3DXSprite::Flush or ID3DXSprite::End is called). If this flag is not specified, then world, view, and projection transforms are modified so that sprites are drawn in screen-space coordinates.
D3DXSPRITE_BILLBOARD Each sprite will be rotated about its center so that it is facing the viewer. ID3DXSprite::SetWorldViewLH or ID3DXSprite::SetWorldViewRH must be called first.
D3DXSPRITE_ALPHABLEND Enables alpha blending with D3DRS_ALPHATESTENABLE set to TRUE (for nonzero alpha). D3DBLEND_SRCALPHA will be the source blend state, and D3DBLEND_INVSRCALPHA will be the destination blend state in calls to IDirect3DDevice9::SetRenderState. See Alpha Blending State (Direct3D 9). ID3DXFont expects this flag to be set when drawing text.
D3DXSPRITE_SORT_TEXTURE Sort sprites by texture prior to drawing. This can improve performance when drawing non-overlapping sprites of uniform depth.

You may also combine D3DXSPRITE_SORT_TEXTURE with either D3DXSPRITE_SORT_DEPTH_FRONTTOBACK or D3DXSPRITE_SORT_DEPTH_BACKTOFRONT. This will sort the list of sprites by depth first and texture second.

D3DXSPRITE_SORT_DEPTH_FRONTTOBACK Sprites are sorted by depth in front-to-back order prior to drawing. This procedure is recommended when drawing opaque sprites of varying depths.

You may combine D3DXSPRITE_SORT_DEPTH_FRONTTOBACK with D3DXSPRITE_SORT_TEXTURE to sort first by depth, and second by texture.

D3DXSPRITE_SORT_DEPTH_BACKTOFRONT Sprites are sorted by depth in back-to-front order prior to drawing. This procedure is recommended when drawing transparent sprites of varying depths.

You may combine D3DXSPRITE_SORT_DEPTH_BACKTOFRONT with D3DXSPRITE_SORT_TEXTURE to sort first by depth, and second by texture.

D3DXSPRITE_DO_NOT_ADDREF_TEXTURE Disables calling AddRef() on every draw, and Release() on Flush() for better performance.

再來看看End方法的使用信息:

Calls ID3DXSprite::Flush and restores the device state to how it was before ID3DXSprite::Begin was called.

HRESULT End();

Parameters

None.

Return Values

If the method succeeds, the return value is S_OK. If the method fails, the following value will be returned.

D3DERR_INVALIDCALL

Remarks

ID3DXSprite::End cannot be used as a substitute for either IDirect3DDevice9::EndScene or ID3DXRenderToSurface::EndScene.


Draw方法用來在指定位置繪制精靈,來看看它的使用說明:

Adds a sprite to the list of batched sprites.

HRESULT Draw(
LPDIRECT3DTEXTURE9 pTexture,
CONST RECT * pSrcRect,
CONST D3DXVECTOR3 * pCenter,
CONST D3DXVECTOR3 * pPosition,
D3DCOLOR Color
);

Parameters

pTexture
[in] Pointer to an IDirect3DTexture9 interface that represents the sprite texture.
pSrcRect
[in] Pointer to a RECT structure that indicates the portion of the source texture to use for the sprite. If this parameter is NULL, then the entire source image is used for the sprite.
pCenter
[in] Pointer to a D3DXVECTOR3 vector that identifies the center of the sprite. If this argument is NULL, the point (0,0,0) is used, which is the upper-left corner.
pPosition
[in] Pointer to a D3DXVECTOR3 vector that identifies the position of the sprite. If this argument is NULL, the point (0,0,0) is used, which is the upper-left corner.
Color
[in] D3DCOLOR type. The color and alpha channels are modulated by this value. A value of 0xFFFFFFFF maintains the original source color and alpha data. Use the D3DCOLOR_RGBA macro to help generate this color.

Return Values

If the method succeeds, the return value is S_OK. If the method fails, the return value can be one of the following: D3DERR_INVALIDCALL, D3DXERR_INVALIDDATA.

Remarks

To scale, rotate, or translate a sprite, call ID3DXSprite::SetTransform with a matrix that contains the scale, rotate, and translate (SRT) values, before calling ID3DXSprite::Draw. For information about setting SRT values in a matrix, see Matrix Transforms.

 

好了,現在來看一個例子:

需要在工程中設置鏈接d3dx9.lib d3d9.lib dinput8.lib dxguid.lib。
由于文件中用到了GE_APP和GE_INPUT這兩個類,它的具體使用說明請參閱主窗口和DirectInput的封裝。


若發現代碼中存在錯誤,敬請指出。

源碼及素材下載

來看看shoot.h的定義:
 
/*************************************************************************************
 [Include File]

 PURPOSE: 
    Define for alpha blending test, use ID3DXSprit interface.
*************************************************************************************/


#ifndef SHOOT_H
#define SHOOT_H

class SHOOT
{
private:
    IDirect3D9* _d3d;
    IDirect3DDevice9* _d3d_device;
    IDirect3DTexture9* _texture_tiger;
    IDirect3DTexture9* _texture_gun;
    ID3DXSprite* _sprite_tiger;
    ID3DXSprite* _sprite_gun;

public:
    float m_gun_pos_x, m_gun_pos_y;

public:
    SHOOT();
    ~SHOOT();
    
    bool Create_D3D_Device(HWND hwnd, bool full_screen = true);
    bool Create_Sprite();
    bool Create_Sprite_Texture(IDirect3DTexture9** texture, const char* image_file);
    void Render();
    void Release_COM_Object();
};

#endif

再來看看shoot.cpp的定義:

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

 PURPOSE: 
    Define for alpha blending test, use ID3DXSprit interface.
*************************************************************************************/


#include "GE_COMMON.h"
#include "GE_INPUT.h"
#include "shoot.h"

//------------------------------------------------------------------------------------
// Constructor, initialize data.
//------------------------------------------------------------------------------------
SHOOT::SHOOT()
{
    _d3d            = NULL;
    _d3d_device     = NULL;
    _texture_tiger  = NULL;
    _texture_gun    = NULL;
    _sprite_tiger   = NULL;
    _sprite_gun     = NULL;

    m_gun_pos_x     = 500.0f;
    m_gun_pos_y     = 180.0f;
}

//------------------------------------------------------------------------------------
// Destructor, release COM object.
//------------------------------------------------------------------------------------
SHOOT::~SHOOT()
{
    Release_COM_Object();
}

//------------------------------------------------------------------------------------
// Create direct3D interface and direct3D device.
//------------------------------------------------------------------------------------
bool SHOOT::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;

    ZeroMemory(&present_param, 
sizeof(present_param));

    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;
}

//------------------------------------------------------------------------------------
// Creates two sprite objects which is associated with a particular device. 
// Sprite objects are used to draw 2D images to the screen.
//------------------------------------------------------------------------------------
bool SHOOT::Create_Sprite()
{
    
// create sprite for image tiger
    if(FAILED(D3DXCreateSprite(_d3d_device, &_sprite_tiger)))
    {
        MessageBox(NULL, "Create sprite tiger failed!", "ERROR", MB_OK);
        
return false;
    }

    
// create sprite for image gun
    if(FAILED(D3DXCreateSprite(_d3d_device, &_sprite_gun)))
    {
        MessageBox(NULL, "Create sprite gun failed!", "ERROR", MB_OK);
        
return false;
    }

    
// create texture for tiger sprite
    if(! Create_Sprite_Texture(&_texture_tiger, "tiger.jpg"))
    {
        MessageBox(NULL, "Create texture interface for sprite tiger failed.", "ERROR", MB_OK);
        
return false;
    }

    
// create texture for gun sprite
    if(! Create_Sprite_Texture(&_texture_gun, "gun.dds"))
    {
        MessageBox(NULL, "Create texture interface for sprite gun failed.", "ERROR", MB_OK);
        
return false;
    }

    
return true;
}

//------------------------------------------------------------------------------------
// Creates a texture from image file.
//------------------------------------------------------------------------------------
bool SHOOT::Create_Sprite_Texture(IDirect3DTexture9** texture, const char* image_file)
{
    
if(FAILED(D3DXCreateTextureFromFile(_d3d_device, image_file, texture)))
        
return false;

    
return true;
}

//------------------------------------------------------------------------------------
// Draw alpha blend image.
//------------------------------------------------------------------------------------
void SHOOT::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);

    
// 1) draw tiger

    // begin scene
    _d3d_device->BeginScene();    

    
// Prepares a device for drawing sprites.
    _sprite_tiger->Begin(D3DXSPRITE_ALPHABLEND);
    
    
// Adds a sprite to the list of batched sprites.
    if(FAILED(_sprite_tiger->Draw(_texture_tiger, NULL, NULL, NULL, 0xFFFFFFFF)))
    {
        MessageBox(NULL, "Draw image tiger failed.", "ERROR", MB_OK);
        
return;
    }

    
// restores the device state to how it was before ID3DXSprite::Begin was called.
    _sprite_tiger->End();

    
// 2) draw gun

    // prepare for begin draw 
    _sprite_gun->Begin(D3DXSPRITE_ALPHABLEND);

    D3DXVECTOR3 pos(m_gun_pos_x, m_gun_pos_y, 0);

    
// draw gun now
    if(FAILED(_sprite_gun->Draw(_texture_gun, NULL, NULL, &pos, 0xFFFFFFFF)))
    {
        MessageBox(NULL, "Draw gun failed.", "ERROR", MB_OK);
        
return;
    }

    
// indicate end draw for sprite gun
    _sprite_gun->End();

    
// 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);
}

//------------------------------------------------------------------------------------
// Release all COM object.
//------------------------------------------------------------------------------------
void SHOOT::Release_COM_Object()
{
    Safe_Release(_texture_tiger);
    Safe_Release(_texture_gun);
    Safe_Release(_sprite_tiger);
    Safe_Release(_sprite_gun);    
    Safe_Release(_d3d_device);
    Safe_Release(_d3d);
}

Create_Sprite方法用來創建背景圖和瞄準鏡的ID3DXSprite精靈接口對象和紋理接口對象, Create_Sprite_Texture方法根據圖象文件創建精靈的紋理對象,這里使用DDS格式的文件創建出一個背景透明的瞄準器精靈對象。 Render方法調用ID3DXSprite接口的Begin,Draw,End方法繪制出背景圖和背景透明的瞄準鏡圖象。

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

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

 PURPOSE: 
    Test for sprite draw with alpha blending.
*************************************************************************************/


#define DIRECTINPUT_VERSION 0x0800

#include "GE_COMMON.h"
#include "GE_APP.h"
#include "GE_INPUT.h"
#include "shoot.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;
    SHOOT shoot;

    MSG msg = {0};

    
// create window
    if(! ge_app.Create_Window("Sprite draw test with Alpha blending", instance, cmd_show))
        
return false;

    HWND hwnd = ge_app.Get_Window_Handle();    

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

    
// create direct input
    ge_input.Create_Input(instance, hwnd);    
    
    
// Create direct3D interface and direct3D device.
    if(! shoot.Create_D3D_Device(hwnd, false))
        
return false;

    
// create all sprites
    if(! shoot.Create_Sprite())
        
return false;

    
// Draw all cones
    shoot.Render();

    
while(msg.message != WM_QUIT)
    {
        
if(PeekMessage(&msg, NULL, 0,0 , PM_REMOVE))
        {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
        
else
        {
            
// get keyboard input
            if(ge_input.Read_Keyboard())
            {
                
if(ge_input.Is_Key_Pressed(DIK_ESCAPE))
                    PostQuitMessage(0);

                
if(ge_input.Is_Key_Pressed(DIK_RIGHT))
                {
                    shoot.m_gun_pos_x += 5.5;
                    shoot.Render();
                }

                
if(ge_input.Is_Key_Pressed(DIK_LEFT))
                {
                    shoot.m_gun_pos_x -= 5.5;
                    shoot.Render();
                }

                
if(ge_input.Is_Key_Pressed(DIK_UP))
                {
                    shoot.m_gun_pos_y -= 5.5;
                    shoot.Render();
                }

                
if(ge_input.Is_Key_Pressed(DIK_DOWN))
                {
                    shoot.m_gun_pos_y += 5.5;
                    shoot.Render();
                }
            }
        }
    }    

    UnregisterClass(WINDOW_CLASS_NAME, instance);

    
return true;
}
 
閱讀下篇:D3D中的Alpha顏色混合(3)

posted on 2007-05-15 20:08 lovedday 閱讀(2425) 評論(0)  編輯 收藏 引用

公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            欧美国产一区二区三区激情无套| 久久久精品一品道一区| 欧美日韩亚洲一区| 欧美成人精品一区二区三区| 麻豆成人91精品二区三区| 久久九九久精品国产免费直播| 久久国产福利国产秒拍| 欧美一区二区三区免费观看| 欧美一区二区三区四区视频| 亚洲欧美一区二区激情| 欧美一区二区在线看| 久久久久久夜精品精品免费| 免费观看亚洲视频大全| 欧美日韩国产综合视频在线观看 | 久久一区视频| 欧美福利视频一区| 日韩天天综合| 欧美一级久久久| 模特精品裸拍一区| 国产精品久久久久久超碰 | 亚洲激情在线激情| 一区二区三区久久精品| 欧美一区二区三区在线| 奶水喷射视频一区| 99精品国产福利在线观看免费| 午夜精品国产| 欧美成在线观看| 国产欧美一区二区精品忘忧草| 精品成人a区在线观看| 一本色道久久88精品综合| 欧美一区2区视频在线观看| 米奇777超碰欧美日韩亚洲| 亚洲精品影院在线观看| 欧美亚洲在线播放| 欧美日韩高清区| 激情综合在线| 亚洲免费视频网站| 亚洲高清毛片| 香蕉久久夜色精品| 欧美另类人妖| 亚洲国产精品一区二区第一页| 亚洲在线视频一区| 欧美风情在线观看| 欧美一区免费视频| 国产精品日韩一区| 99国产麻豆精品| 免费观看不卡av| 香蕉视频成人在线观看 | 亚洲女女女同性video| 欧美成人一区二区三区在线观看 | 欧美成人一区二区三区片免费| 国产精品国产三级国产普通话99 | 久久在线免费观看视频| 国产精品免费久久久久久| 亚洲欧洲日产国产网站| 久久久水蜜桃| 性欧美xxxx大乳国产app| 欧美香蕉视频| 亚洲私拍自拍| 99re6这里只有精品| 欧美精品免费在线观看| 亚洲国产专区| 欧美成人在线网站| 久久人人97超碰国产公开结果 | 欧美午夜欧美| 亚洲欧美精品在线观看| 一本在线高清不卡dvd| 欧美欧美全黄| 在线亚洲一区观看| 夜夜嗨av一区二区三区中文字幕| 欧美精品videossex性护士| 亚洲欧洲一区二区三区| 亚洲成人在线视频播放 | 亚洲综合成人在线| 国产精品美女在线| 欧美一区二区在线看| 亚洲女人天堂av| 国产日本欧美一区二区三区| 欧美一区免费| 久久久久久国产精品mv| 亚洲大胆美女视频| 亚洲丰满在线| 性色av香蕉一区二区| 国外成人在线视频网站| 老司机午夜精品| 欧美激情片在线观看| 亚洲影院在线观看| 欧美在线视频观看| 亚洲欧洲日韩综合二区| 亚洲精品综合| 午夜性色一区二区三区免费视频| 欧美大片在线观看| 麻豆成人综合网| 久久这里有精品视频| 99视频精品| 亚洲午夜极品| 在线观看欧美日本| 亚洲精品免费网站| 国产欧美日韩麻豆91| 亚洲福利免费| 国产精品中文字幕欧美| 欧美国产极速在线| 国产精品视频九色porn| 欧美成人免费视频| 国产精品专区第二| 亚洲激情国产精品| 久久综合色播五月| 一本色道久久88综合日韩精品| 欧美日韩岛国| 国产日韩欧美一区二区三区在线观看| 久久久噜噜噜久久| 欧美视频亚洲视频| 免费黄网站欧美| 国产精品自在线| 亚洲精品视频免费| 亚洲第一天堂av| 亚洲一区二区三区视频| 亚洲老司机av| 噜噜噜噜噜久久久久久91 | 国产女同一区二区| 亚洲美女少妇无套啪啪呻吟| 一区精品久久| 欧美在线免费播放| 亚洲欧美一区二区三区在线| 欧美激情亚洲自拍| 亚洲综合色丁香婷婷六月图片| 欧美电影免费观看大全| 亚洲乱码国产乱码精品精可以看 | 亚洲精品美女久久久久| 国产精品va在线| 欧美日韩一区三区四区| 男男成人高潮片免费网站| 久久精品欧美日韩精品| 久久精品理论片| 久久裸体视频| 日韩亚洲视频| 欧美日韩国产精品| 久久久精品动漫| 欧美久久影院| 亚洲影视在线播放| 欧美日韩国产成人| 欧美不卡视频一区发布| 国产精品黄视频| 欧美黄色日本| 伊人成综合网伊人222| 久久精品亚洲一区二区三区浴池| 亚洲一级影院| 欧美另类极品videosbest最新版本 | 欧美va亚洲va日韩∨a综合色| 亚洲欧美视频在线| 欧美在线精品一区| 亚洲在线1234| 欧美日韩精品不卡| 亚洲国产专区校园欧美| 在线免费观看日韩欧美| 久久这里有精品视频| 亚洲国产精品va在线看黑人| 欧美一区二区三区另类| 亚洲精品一二| 欧美成黄导航| 亚洲黄色有码视频| 亚洲精品一区二区三| 男女精品视频| 亚洲激情成人网| 一区二区三区导航| 欧美体内she精视频在线观看| 亚洲大胆人体视频| 亚洲精品之草原avav久久| 亚洲欧美日韩一区在线| 欧美成人黑人xx视频免费观看| 国产在线拍揄自揄视频不卡99| 亚洲男人的天堂在线| 欧美一级专区| 日韩亚洲欧美中文三级| 欧美日本成人| 亚洲午夜电影在线观看| 午夜视频精品| 国模叶桐国产精品一区| 欧美激情第1页| 一本一道久久综合狠狠老精东影业| 亚洲一区欧美| 国产网站欧美日韩免费精品在线观看| 麻豆精品传媒视频| 日韩一级欧洲| 久久精品理论片| 亚洲国产另类精品专区| 欧美高清视频在线| 亚洲一区二区三区四区五区午夜| 午夜日韩视频| 亚洲电影在线观看| 欧美国产精品久久| 久久经典综合| 亚洲精品一二三区| 久久久久国产精品人| 亚洲精品国精品久久99热| 国产拍揄自揄精品视频麻豆| 可以免费看不卡的av网站| 夜夜嗨av一区二区三区四季av| 欧美一区日本一区韩国一区| 亚洲国产经典视频|