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

天行健 君子當自強而不息

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>
            亚洲欧美在线x视频| 欧美激情bt| 欧美黄色小视频| 欧美www在线| 亚洲国产高清一区| 亚洲国产成人在线视频| 亚洲美女av网站| 亚洲一区综合| 久久久久亚洲综合| 欧美日韩国产在线| 国产日韩精品电影| 亚洲国产精品成人综合| 夜夜嗨av一区二区三区网页| 亚洲午夜黄色| 久久久不卡网国产精品一区| 久久永久免费| 99国产一区二区三精品乱码| 亚洲欧美在线一区二区| 老司机免费视频久久| 欧美日韩伦理在线免费| 一区二区三区 在线观看视频| 99精品免费| 国产欧美亚洲日本| 一色屋精品视频免费看| 亚洲片区在线| 久久精品女人的天堂av| 欧美高清视频一区二区| 夜夜嗨av一区二区三区网页 | 久久综合九色99| 亚洲国内自拍| 欧美在线一级视频| 欧美天天在线| 亚洲精品小视频| 久久综合成人精品亚洲另类欧美| 亚洲日本一区二区| 久久嫩草精品久久久精品| 国产精品无码专区在线观看| 亚洲精品视频二区| 鲁大师成人一区二区三区| a4yy欧美一区二区三区| 欧美xx视频| 亚洲国产精品久久久久秋霞蜜臀| 午夜国产精品视频| 亚洲乱码日产精品bd| 美女图片一区二区| 韩国av一区二区三区四区| 亚洲欧美日韩另类| 亚洲另类自拍| 欧美国产在线观看| 亚洲国产天堂久久国产91| 久久久久久久999精品视频| 一区二区三区四区国产| 欧美国产在线电影| 亚洲精品久久久久中文字幕欢迎你| 久久精品国产99国产精品澳门| 一区二区免费看| 欧美日韩日本网| 99re亚洲国产精品| 亚洲精品美女在线观看| 欧美激情1区2区3区| 亚洲人成免费| 亚洲日本中文字幕免费在线不卡| 蜜桃久久精品乱码一区二区| 亚洲第一偷拍| 牛牛国产精品| 欧美激情精品久久久久久蜜臀| 亚洲国产日韩美| 亚洲国产欧美日韩另类综合| 免费一级欧美片在线播放| 亚洲国产精品久久91精品| 欧美成人黑人xx视频免费观看| 欧美在线观看天堂一区二区三区 | 日韩视频永久免费观看| 欧美韩日视频| 欧美精品三级日韩久久| 日韩午夜在线电影| 一区二区欧美视频| 欧美一区二区三区在线播放| 欧美精品久久一区| 亚洲一区影音先锋| 午夜久久久久久久久久一区二区| 国产精品一级在线| 久久综合给合久久狠狠色| 另类天堂视频在线观看| 日韩视频在线播放| 一本色道久久88综合亚洲精品ⅰ| 欧美私人网站| 亚洲人体偷拍| 国模套图日韩精品一区二区| 欧美国产在线视频| 亚洲一级二级| 欧美一区二区三区在线观看视频| 伊人成人在线| 欧美激情 亚洲a∨综合| 欧美日韩一区二区视频在线观看| 午夜精品久久久久久久99樱桃| 久久久精品视频成人| 日韩视频二区| 欧美一区二区在线| 99re在线精品| 欧美资源在线| 亚洲午夜一区| 久久久久久久久久久成人| 日韩一级视频免费观看在线| 亚洲欧美成aⅴ人在线观看| 亚洲激情欧美| 性伦欧美刺激片在线观看| 亚洲第一区在线观看| 亚洲欧美日韩一区在线| 99国产精品国产精品久久| 欧美一区二区三区啪啪| 亚洲性视频网站| 欧美多人爱爱视频网站| 欧美中文在线观看国产| 欧美日产在线观看| 欧美不卡在线视频| 国产午夜精品福利| 亚洲午夜精品17c| 亚洲人体一区| 免费成人高清视频| 开心色5月久久精品| 国产一区91| 欧美在线播放一区| 久久成人国产| 国产日韩欧美在线看| 亚洲私人影院在线观看| 在线一区观看| 欧美日韩视频在线一区二区观看视频| 欧美夫妇交换俱乐部在线观看| 国内成人自拍视频| 欧美一区二区三区在线观看| 午夜免费日韩视频| 国产精品国产成人国产三级| 99热精品在线观看| 亚洲已满18点击进入久久| 欧美日韩国产精品一区| 亚洲精品国产精品乱码不99| 亚洲黄网站黄| 欧美韩日一区二区三区| 亚洲高清在线视频| 亚洲精品中文字幕在线| 可以免费看不卡的av网站| 欧美99久久| 老牛影视一区二区三区| 久久av免费一区| 午夜精品网站| 亚洲伊人观看| 老司机午夜精品视频| 久久久久免费观看| 亚洲人屁股眼子交8| 欧美日韩精品免费观看视频完整| 久久激情五月婷婷| 国产一区二区三区四区hd| 久久福利影视| 国产一区二区黄色| 欧美亚洲综合另类| 久久久久国产精品一区| 亚洲精品美女在线观看| 亚洲国产精品电影| 欧美二区在线| 9i看片成人免费高清| 亚洲新中文字幕| 国产一区二区av| 久久夜色撩人精品| 亚洲美女啪啪| 久久人人97超碰人人澡爱香蕉| 1024欧美极品| 欧美日韩中文另类| 久久精品国产久精国产思思| 亚洲二区在线| 性欧美长视频| 亚洲人成在线观看| 国产精品免费在线| 久久综合一区二区三区| 在线综合视频| 玖玖国产精品视频| 亚洲图片激情小说| 影音欧美亚洲| 国产精品国产三级国产a| 久久精品中文| 一区二区欧美视频| 免费亚洲电影在线观看| 亚洲综合首页| 欧美高清视频一区二区| 欧美成va人片在线观看| 欧美性猛交xxxx乱大交蜜桃 | 最新高清无码专区| 女女同性精品视频| 久久www成人_看片免费不卡| 欧美国产精品中文字幕| 久久人人超碰| 亚洲电影观看| 亚洲午夜激情网站| 国内视频精品| 亚洲深夜福利网站| 亚洲精品一区二区三区婷婷月| 欧美精品粉嫩高潮一区二区 | 欧美好骚综合网| 国产自产在线视频一区| 99视频有精品|