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

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

坐標(biāo)系與基本圖元(3)

渲染頂點緩沖區(qū)圖形

void render()
{
g_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_X#050505, 1.0f, 0);
	g_device->BeginScene();
	g_device->SetStreamSource(0, g_vertex_buffer, 0, sizeof(sCustomVertex));
g_device->SetFVF(D3DFVF_CUSTOM_VERTEX);
g_device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1);
	g_device->EndScene();
	g_device->Present(NULL, NULL, NULL, NULL);
}

函數(shù)IDirect3DDevice9::SetStreamSource()將頂點緩沖區(qū)和渲染數(shù)據(jù)流鏈接。

Binds a vertex buffer to a device data stream. For more information, see Setting the Stream Source (Direct3D 9).

HRESULT SetStreamSource(
UINT StreamNumber,
IDirect3DVertexBuffer9 * pStreamData,
UINT OffsetInBytes,
UINT Stride
);

Parameters

StreamNumber
[in] Specifies the data stream, in the range from 0 to the maximum number of streams -1.
pStreamData
[in] Pointer to an IDirect3DVertexBuffer9 interface, representing the vertex buffer to bind to the specified data stream.
OffsetInBytes
[in] Offset from the beginning of the stream to the beginning of the vertex data, in bytes. To find out if the device supports stream offsets, see the D3DDEVCAPS2_STREAMOFFSET constant in D3DDEVCAPS2.
Stride
[in] Stride of the component, in bytes. See Remarks.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be D3DERR_INVALIDCALL.

Remarks

When a FVF vertex shader is used, the stride of the vertex stream must match the vertex size, computed from the FVF. When a declaration is used, the stride should be greater than or equal to the stream size computed from the declaration.

When calling SetStreamSource, the stride is normally required to be equal to the vertex size. However, there are times when you may want to draw multiple instances of the same or similar geometry (such as when using instancing to draw). For this case, use a zero stride to tell the runtime not to increment the vertex buffer offset (ie: use the same vertex data for all instances). For more information about instancing, see Efficiently Drawing Multiple Instances of Geometry (Direct3D 9).

函數(shù)IDirect3DDevice9::SetFVF()的作用是聲明當(dāng)前的渲染數(shù)據(jù)流中的靈活頂點格式。

Sets the current vertex stream declaration.

HRESULT SetFVF(
DWORD FVF
);

Parameters

FVF
[in] DWORD containing the fixed function vertex type. For more information, see D3DFVF.

Return Values

If the method succeeds, the return value is D3D_OK. If the method fails, the return value can be: D3DERR_INVALIDCALL.

Remarks

Here are the steps necessary to initialize and use vertices that have a position, diffuse and specular color, and texture coordinates:

  1. Define the custom vertex type and FVF code.
    struct LVertex
    {
    FLOAT x, y, z;
    D3DCOLOR specular, diffuse;
    FLOAT tu, tv;
    };

    const DWORD VertexFVF = (D3DFVF_XYZ | D3DFVF_DIFFUSE |
    D3DFVF_SPECULAR | D3DFVF_TEX1 );
  2. Create a vertex buffer with enough room for four vertices using IDirect3DDevice9::CreateVertexBuffer.
    g_d3dDevice->CreateVertexBuffer( 4*sizeof(LVertex),  
    D3DUSAGE_WRITEONLY, VertexFVF, D3DPOOL_DEFAULT, &pBigSquareVB, NULL );
  3. Set the values for each vertex.
    LVertex * v;
    pBigSquareVB->Lock( 0, 0, (BYTE**)&v, 0 );

    v[0].x = 0.0f; v[0].y = 10.0; v[0].z = 10.0f;
    v[0].diffuse = 0xffff0000;
    v[0].specular = 0xff00ff00;
    v[0].tu = 0.0f; v[0].tv = 0.0f;

    v[1].x = 0.0f; v[1].y = 0.0f; v[1].z = 10.0f;
    v[1].diffuse = 0xff00ff00;
    v[1].specular = 0xff00ffff;
    v[1].tu = 0.0f; v[1].tv = 0.0f;

    v[2].x = 10.0f; v[2].y = 10.0f; v[2].z = 10.0f;
    v[2].diffuse = 0xffff00ff;
    v[2].specular = 0xff000000;
    v[2].tu = 0.0f; v[2].tv = 0.0f;

    v[3].x = 0.0f; v[3].y = 10.0f; v[3].z = 10.0f;
    v[3].diffuse = 0xffffff00;
    v[3].specular = 0xffff0000;
    v[3].tu = 0.0f; v[3].tv = 0.0f;

    pBigSquareVB->Unlock();
  4. The vertex buffer has been initialized and is ready to render. The following code example shows how to use the legacy FVF to draw a square.
    g_d3dDevice->SetFVF(VertexFVF);
    g_d3dDevice->SetStreamSource(0, pBigSquareVB, 0, sizeof(LVertex));
    g_d3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0 ,2);

Here are the steps necessary to initialize and use vertices that have a position, a normal, and texture coordinates:

  1. Define the custom vertex type and FVF code.
    struct Vertex
    {
    FLOAT x, y, z;
    FLOAT nx, ny, nz;
    FLOAT tu, tv;
    };

    const DWORD VertexFVF = ( D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1 );
  2. Create a vertex buffer with enough room for four vertices using IDirect3DDevice9::CreateVertexBuffer (similar to the example above).
  3. Set the values for each vertex.
    Vertex * v;
    pBigSquareVB->Lock(0, 0, (BYTE**)&v, 0);

    v[0].x = 0.0f; v[0].y = 10.0; v[0].z = 10.0f;
    v[0].nx = 0.0f; v[0].ny = 1.0f; v[0].nz = 0.0f;
    v[0].tu = 0.0f; v[0].tv = 0.0f;

    v[1].x = 0.0f; v[1].y = 0.0f; v[1].z = 10.0f;
    v[1].nx = 0.0f; v[1].ny = 1.0f; v[1].nz = 0.0f;
    v[1].tu = 0.0f; v[1].tv = 0.0f;

    v[2].x = 10.0f; v[2].y = 10.0f; v[2].z = 10.0f;
    v[2].nx = 0.0f; v[2].ny = 1.0f; v[2].nz = 0.0f;
    v[2].tu = 0.0f; v[2].tv = 0.0f;

    v[3].x = 0.0f; v[3].y = 10.0f; v[3].z = 10.0f;
    v[3].nx = 0.0f; v[3].ny = 1.0f; v[3].nz = 0.0f;
    v[3].tu = 0.0f; v[3].tv = 0.0f;

    pBigSquareVB->Unlock();
  4. Draw the object (similar to the example above).

函數(shù)IDirect3DDevice9::DrawPrimitive()用來繪制當(dāng)前的渲染數(shù)據(jù)流中的圖元。

示例程序VertexBuffer的完整源碼如下:

 #include <d3d9.h>

#define CLASS_NAME    "GameApp"

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

IDirect3D9
*                g_d3d;
IDirect3DDevice9
*        g_device;
IDirect3DVertexBuffer9
* g_vertex_buffer;

struct sCustomVertex
{
    
float x, y, z, rhw;
    DWORD color;
};

#define D3DFVF_CUSTOM_VERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) 

void init_vb()
{
    sCustomVertex vertices[] 
=
    {
        { 
100.0f400.0f1.0f1.0f0xffffff00, },
        { 
300.0f,  50.0f1.0f1.0f0xff00ff00, }, 
        { 
500.0f400.0f1.0f1.0f0xffff00ff, },
    };

    g_device
->CreateVertexBuffer(sizeof(vertices), 0, D3DFVF_CUSTOM_VERTEX, D3DPOOL_DEFAULT, &g_vertex_buffer, NULL);

    
void* ptr;

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

bool init_d3d(HWND hwnd)
{
    g_d3d 
= Direct3DCreate9(D3D_SDK_VERSION);

    
if(g_d3d == NULL)
        
return false;

    D3DPRESENT_PARAMETERS d3dpp;
    ZeroMemory(
&d3dpp, sizeof(d3dpp));

    d3dpp.Windowed            
= TRUE;
    d3dpp.SwapEffect        
= D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat    
= D3DFMT_UNKNOWN;

    
if(FAILED(g_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                  
&d3dpp, &g_device)))
    {
        
return false;
    }

    init_vb();

    
return true;
}

void cleanup()
{
    release_com(g_vertex_buffer);
    release_com(g_device);
    release_com(g_d3d);
}

void render()
{
    g_device
->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(555), 1.0f0);

    g_device
->BeginScene();

    g_device
->SetStreamSource(0, g_vertex_buffer, 0sizeof(sCustomVertex));
    g_device
->SetFVF(D3DFVF_CUSTOM_VERTEX);
    g_device
->DrawPrimitive(D3DPT_TRIANGLELIST, 01);

    g_device
->EndScene();

    g_device
->Present(NULL, NULL, NULL, NULL);
}

LRESULT WINAPI WinProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    
switch(msg)
    {
    
case WM_KEYDOWN:
        
if(wParam == VK_ESCAPE)
            DestroyWindow(hwnd);
        
break;

    
case WM_DESTROY:        
        PostQuitMessage(
0);
        
return 0;
    }

    
return DefWindowProc(hwnd, msg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE inst, HINSTANCE, LPSTR, INT)
{
    WNDCLASSEX wc;

    wc.cbSize            
= sizeof(WNDCLASSEX);
    wc.style            
= CS_CLASSDC;
    wc.lpfnWndProc        
= WinProc;
    wc.cbClsExtra        
= 0;
    wc.cbWndExtra        
= 0;
    wc.hInstance        
= inst;
    wc.hIcon            
= NULL;
    wc.hCursor            
= NULL;
    wc.hbrBackground    
= NULL;
    wc.lpszMenuName        
= NULL;
    wc.lpszClassName    
= CLASS_NAME;
    wc.hIconSm            
= NULL;

    
if(! RegisterClassEx(&wc))
        
return -1;

    HWND hwnd 
= CreateWindow(CLASS_NAME, "Direct3D App", WS_OVERLAPPEDWINDOW, 200100600500,
                             NULL, NULL, wc.hInstance, NULL);

    
if(hwnd == NULL)
        
return -1;

    
if(init_d3d(hwnd))
    {
        ShowWindow(hwnd, SW_SHOWDEFAULT);
        UpdateWindow(hwnd);

        MSG msg;
        ZeroMemory(
&msg, sizeof(msg));

        
while(msg.message != WM_QUIT)
        {
            
if(PeekMessage(&msg, NULL, 00, PM_REMOVE))
            {
                TranslateMessage(
&msg);
                DispatchMessage(
&msg);
            }
                
            render();
        }
    }

    cleanup();

    UnregisterClass(CLASS_NAME, wc.hInstance);    

    
return 0;
}

 

運行截圖:


posted on 2008-04-30 13:59 lovedday 閱讀(839) 評論(0)  編輯 收藏 引用


只有注冊用戶登錄后才能發(fā)表評論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(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>
            午夜欧美大尺度福利影院在线看 | 久久人91精品久久久久久不卡| 久久国产精品久久精品国产| 中日韩男男gay无套| 久久久久久久999| 亚洲欧美在线免费| 欧美激情在线有限公司| 美女网站久久| 国产亚洲精品激情久久| 亚洲香蕉视频| 亚洲视频中文字幕| 欧美日韩视频在线观看一区二区三区| 欧美黄色成人网| 在线观看日韩av| 久久久精品日韩欧美| 午夜在线视频观看日韩17c| 欧美色图五月天| 亚洲毛片在线看| 亚洲另类自拍| 欧美国产日韩精品| 亚洲第一久久影院| 亚洲电影成人| 久久综合久久综合久久| 狂野欧美激情性xxxx| 国产一区二区三区av电影| 性亚洲最疯狂xxxx高清| 欧美中文在线视频| 国产亚洲精品7777| 久久精品国产91精品亚洲| 久久免费精品日本久久中文字幕| 国产日韩欧美在线播放| 欧美在线视频播放| 久久人人97超碰国产公开结果| 国内精品**久久毛片app| 欧美一区二区三区电影在线观看| 欧美在线免费视屏| 黄色一区二区三区| 久热这里只精品99re8久| 欧美激情1区2区3区| 亚洲伦理在线观看| 国产精品观看| 性欧美xxxx大乳国产app| 另类综合日韩欧美亚洲| 亚洲国产高清在线观看视频| 欧美jizz19性欧美| 99精品欧美一区二区蜜桃免费| 亚洲影院高清在线| 国产欧美一区二区精品婷婷| 久久精品综合网| 亚洲成人在线视频播放| 亚洲毛片一区二区| 国产精品久久久对白| 欧美伊人久久| 欧美激情中文不卡| 亚洲淫性视频| 亚洲大胆在线| 欧美日一区二区在线观看 | 精品动漫3d一区二区三区免费版| 久久免费少妇高潮久久精品99| 亚洲第一精品在线| 亚洲欧美日韩系列| 精品成人国产在线观看男人呻吟| 欧美激情第8页| 午夜精品一区二区在线观看| 欧美α欧美αv大片| 亚洲一区黄色| 136国产福利精品导航| 欧美视频观看一区| 久久亚洲私人国产精品va媚药| 99精品国产在热久久婷婷| 久久久免费av| 亚洲欧美国产77777| 亚洲国产精品毛片| 国产精品私人影院| 欧美人与禽猛交乱配| 欧美在线在线| 一本大道久久精品懂色aⅴ| 久久视频免费观看| 午夜精品视频在线观看一区二区 | 亚洲一区二区三区精品视频| 国语自产精品视频在线看抢先版结局| 欧美激情一区二区三区| 久久精品人人做人人爽| 亚洲天堂av图片| 亚洲国产乱码最新视频| 久久中文字幕一区| 欧美一区二区三区在线观看视频| 99精品视频免费观看视频| 一区视频在线播放| 国产一区二区成人| 国产乱码精品一区二区三| 欧美日韩亚洲91| 欧美精品首页| 欧美激情网站在线观看| 久久久久国产精品麻豆ai换脸| 亚洲一区中文字幕在线观看| 亚洲毛片av| 日韩天堂在线观看| 亚洲人精品午夜| 亚洲高清在线视频| 欧美福利一区二区三区| 久久亚洲春色中文字幕久久久| 欧美一区高清| 欧美一区二区三区免费视频| 亚洲欧美日韩精品久久亚洲区| 在线一区亚洲| 在线亚洲欧美| 亚洲自拍三区| 香蕉久久夜色精品国产使用方法| 亚洲一区二区视频| 亚洲女女女同性video| 亚洲在线观看免费| 亚洲欧美激情精品一区二区| 亚洲综合999| 亚洲欧美中文日韩在线| 欧美一区二区三区在线播放| 欧美在线免费视屏| 久久综合色播五月| 欧美大胆a视频| 亚洲三级免费| 亚洲午夜精品福利| 欧美影院精品一区| 久久精品综合网| 欧美成人免费小视频| 欧美欧美在线| 国产精品香蕉在线观看| 国产一区二区三区免费在线观看| 激情偷拍久久| 亚洲久色影视| 午夜激情综合网| 久久男女视频| 亚洲国产欧美一区二区三区丁香婷 | 亚洲精品小视频| 在线视频亚洲| 久久精品国产99国产精品| 噜噜噜噜噜久久久久久91| 欧美激情一区二区三区成人| 亚洲精品一区二区三| 亚洲一区二区精品| 久久综合伊人77777蜜臀| 欧美精品二区| 国产亚洲欧美日韩美女| 亚洲美女网站| 欧美在线视频在线播放完整版免费观看 | 久久亚洲春色中文字幕久久久| 欧美高清自拍一区| 国产精品午夜在线| 亚洲日本在线视频观看| 午夜欧美电影在线观看| 欧美福利在线| 亚洲欧美一区二区三区在线 | 欧美一区二区三区另类| 欧美91福利在线观看| 国产精品免费视频xxxx| 亚洲国产你懂的| 欧美在线视频一区二区| 91久久黄色| 久久精品91| 国产精品xvideos88| 亚洲国产精品电影| 久久国产手机看片| 日韩一区二区精品葵司在线| 久久国产天堂福利天堂| 国产精品igao视频网网址不卡日韩| 一区二区三区在线视频免费观看| 亚洲自拍高清| 亚洲精品1区2区| 久久亚洲精品中文字幕冲田杏梨| 欧美性猛交xxxx免费看久久久| 亚洲高清中文字幕| 久久久99久久精品女同性| 中文久久乱码一区二区| 欧美不卡视频一区发布| 在线成人国产| 久久综合久久美利坚合众国| 亚洲欧美日韩一区| 欧美体内谢she精2性欧美 | 在线观看av一区| 久久精品九九| 亚洲欧美日韩成人| 国产精品久久久久久一区二区三区| 亚洲日韩中文字幕在线播放| 蜜臀99久久精品久久久久久软件 | 欧美成人亚洲成人| 在线精品国精品国产尤物884a| 久久精品系列| 午夜在线成人av| 国产日韩精品入口| 欧美在线你懂的| 午夜国产一区| 国产亚洲欧美一区| 久久全国免费视频| 久久爱www.| 激情综合亚洲| 免费久久99精品国产自在现线| 久久久精品动漫| 亚洲国产成人不卡| 欧美国产在线电影| 欧美国产欧美亚洲国产日韩mv天天看完整| 亚洲国产精品成人va在线观看|