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

天行健 君子當自強而不息

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>
            午夜精品视频一区| 日韩视频免费| 久久久青草青青国产亚洲免观| 亚洲午夜小视频| 国产精品国产三级国产aⅴ浪潮| 亚洲一区二区在| 中文网丁香综合网| 国产视频一区二区三区在线观看| 久久精品国产精品亚洲精品| 久久久久国产精品www| 亚洲国产高清aⅴ视频| 亚洲国产精品第一区二区三区| 欧美成人a∨高清免费观看| 99热免费精品| 亚洲欧美日韩精品综合在线观看| 在线观看视频欧美| 亚洲大片在线观看| 国产精品久久久对白| 久久久久免费视频| 欧美激情在线观看| 亚洲自拍电影| 久久久久久夜精品精品免费| 日韩视频三区| 欧美一区二区三区男人的天堂| 亚洲精品欧美极品| 亚洲欧美激情四射在线日 | 欧美精品一区二区视频| 亚洲永久免费观看| 老巨人导航500精品| 亚洲尤物影院| 欧美高清视频在线| 久久久久国产精品人| 欧美精品成人一区二区在线观看 | 久久不见久久见免费视频1| 久久综合一区| 久久av二区| 欧美日本高清| 农村妇女精品| 国产欧美高清| 一区二区日韩伦理片| 亚洲欧洲视频| 久久久久久久尹人综合网亚洲| 亚洲欧美日韩精品| 欧美激情在线有限公司| 欧美成人精品一区二区| 国产一区二区三区在线观看免费| 一本色道久久综合亚洲91| 亚洲精品免费在线播放| 久久综合九色综合欧美就去吻| 欧美一区二区三区精品| 欧美视频免费在线| 日韩视频永久免费| 亚洲精品久久久久久久久| 久久久久一区二区| 久久国产视频网站| 国产亚洲福利| 午夜激情久久久| 久久国产黑丝| 国产美女精品人人做人人爽| 亚洲在线免费视频| 亚洲欧美在线免费| 国产精品无码专区在线观看| 一区二区三区精品视频| 99国产精品久久久久老师| 欧美成人黄色小视频| 欧美激情视频一区二区三区免费| 亚洲国产成人精品久久| 久久综合99re88久久爱| 欧美xxxx在线观看| 91久久精品美女高潮| 蜜桃av综合| 91久久国产综合久久| 亚洲最新视频在线播放| 欧美日韩精品高清| 宅男噜噜噜66一区二区| 性一交一乱一区二区洋洋av| 国产精品视频精品视频| 亚洲欧美日韩中文播放| 久久久久久久综合日本| 亚洲电影第三页| 欧美激情综合色综合啪啪| 夜夜嗨av一区二区三区四区| 欧美亚洲在线播放| 国内精品国产成人| 猛干欧美女孩| 亚洲一区二区四区| 久久久久久久国产| 亚洲精品免费在线观看| 国产精品久久久一区麻豆最新章节| 亚洲中字在线| 欧美激情第8页| 亚洲一区二区免费| 国内精品久久久久久| 久久婷婷色综合| 一区二区三区四区国产精品| 久热精品视频| 亚洲午夜高清视频| 国内不卡一区二区三区| 欧美全黄视频| 香蕉亚洲视频| 亚洲日本欧美日韩高观看| 午夜精品亚洲| 日韩午夜免费视频| 国产欧美一区二区三区久久| 免费亚洲电影在线| 亚洲欧美成人一区二区在线电影| 欧美成人一二三| 午夜精品久久久| 亚洲国产一区二区三区在线播 | 欧美成人国产| 久久国产精品久久久久久| 亚洲日本va午夜在线电影| 欧美专区一区二区三区| 亚洲视频第一页| 亚洲国产欧美久久| 国产乱码精品一区二区三区五月婷 | 欧美/亚洲一区| 欧美一区二区三区在线观看视频| 日韩视频中午一区| 极品av少妇一区二区| 国产精品美女久久久久久久| 欧美多人爱爱视频网站| 久久精品亚洲国产奇米99| 亚洲视频福利| 99热在线精品观看| 亚洲激情午夜| 欧美激情一区在线| 米奇777超碰欧美日韩亚洲| 久久国产88| 欧美一区二区三区在线观看 | 国产区精品视频| 国产精品黄色| 欧美性猛交xxxx乱大交蜜桃 | 欧美大胆a视频| 久久精品国产91精品亚洲| 欧美一区午夜精品| 性欧美办公室18xxxxhd| 亚洲男人的天堂在线| 一区二区免费在线播放| 一道本一区二区| 一本色道久久精品| 一区二区三区免费观看| 亚洲美女精品成人在线视频| 亚洲精品欧美| 亚洲黄网站在线观看| 亚洲精品免费一二三区| 亚洲精品久久久久| 亚洲毛片在线免费观看| 一本久久综合亚洲鲁鲁| 亚洲一区区二区| 欧美一区二区三区另类| 久久精品最新地址| 美国十次成人| 欧美黄网免费在线观看| 欧美色图麻豆| 国产欧美精品va在线观看| 国产亚洲欧美一区二区| 极品少妇一区二区三区精品视频| 伊人成综合网伊人222| 亚洲激情网址| 亚洲午夜一二三区视频| 午夜精品在线视频| 久久久久久免费| 欧美成人一品| 一区二区三区视频在线看| 午夜精品视频一区| 欧美aa国产视频| 欧美婷婷六月丁香综合色| 国产美女精品视频免费观看| 在线精品视频一区二区三四| 亚洲综合999| 久久久久一本一区二区青青蜜月| 欧美福利小视频| 国产精品久久久一区麻豆最新章节| 国产一区二区观看| 亚洲理论电影网| 午夜一级久久| 欧美成人三级在线| 亚洲社区在线观看| 六月天综合网| 国产精品一区二区女厕厕| 亚洲第一天堂无码专区| 亚洲欧美另类在线观看| 欧美激情精品| 亚洲欧美在线aaa| 欧美日韩ab片| 伊人婷婷欧美激情| 亚洲欧美综合另类中字| 欧美福利一区二区| 亚洲一区中文| 欧美精品一区三区| 激情小说另类小说亚洲欧美| 亚洲欧美成人一区二区在线电影| 牛牛影视久久网| 欧美在线短视频| 欧美偷拍另类| 99视频一区二区| 免费中文字幕日韩欧美| 亚洲欧美一区二区三区在线| 欧美日韩国产系列|