游戏开发论坛

 找回密码
 立即注册
搜索
查看: 2103|回复: 6

关于DX的索引渲染,不知道错再那?

[复制链接]

29

主题

97

帖子

99

积分

注册会员

Rank: 2

积分
99
发表于 2005-4-25 18:36:00 | 显示全部楼层 |阅读模式
//关于DX的索引渲染,不知道错再那?
truct CUSTOMVERTEX
{
FLOAT x, y, z; // the untransformed, 3D position for the vertex
DWORD color; // the color of the vertex
};

CUSTOMVERTEX g_Vertices3[] = {
// X Y Z U V
{-200.0f,-200.0f,-200.0f, D3DCOLOR_ARGB(0,0,255,0)}, // 0
{-200.0f, 200.0f,-200.0f, D3DCOLOR_ARGB(0,0,255,0)}, // 1
{200.0f, 200.0f,-200.0f, D3DCOLOR_ARGB(0,0,255,0)}, // 2
{200.0f,-200.0f,-200.0f, D3DCOLOR_ARGB(0,0,255,0)}, // 3

};
void IndexBufferRender(void)
{
// Check to make sure you have a valid Direct3D device
if( NULL == pd3dDevice )
return;// Clear the back buffer to a blue color
pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB( 0,0,255 ), 1.0f, 0 );

// Create the vertex buffer
HRESULT hr;

//CREATE VERTEXT BUFFER
LPDIRECT3DVERTEXBUFFER9 vertexBuffer;

hr = pd3dDevice->CreateVertexBuffer(sizeof(g_Vertices3) * sizeof(CUSTOMVERTEX),
0,
D3DFVF_DIFFUSE|D3DFVF_XYZRHW,
D3DPOOL_DEFAULT,
&vertexBuffer,
NULL );
// Check the return code of CreateVertexBuffer call to make sure it succeeded
if FAILED (hr)
hr=NULL;
// Prepare to copy the vertices into the vertex buffer
VOID* pVertices;
// Lock the vertex buffer
hr = vertexBuffer->Lock(0,
sizeof(g_Vertices3)*sizeof(CUSTOMVERTEX),
(void**) &pVertices,
0);
// Check to make sure the vertex buffer can be locked
if FAILED (hr)
hr=NULL;
// Copy the vertices into the buffer
memcpy ( pVertices, g_Vertices3, sizeof(g_Vertices3)*sizeof(CUSTOMVERTEX) );
// Unlock the vertex buffer
vertexBuffer->Unlock();
// Present the back buffer contents to the display




LPDIRECT3DINDEXBUFFER9 iBuffer;
// index buffer data
WORD IndexData3[ ] = {
0,1,2, // triangle 1
2,3,0 // triangle 2
};
// Create the index buffer
//MessageBox(NULL,"gg","D",MB_ABORTRETRYIGNORE);

hr = pd3dDevice->CreateIndexBuffer(sizeof(IndexData3)*sizeof(WORD),
                                                                   D3DUSAGE_WRITEONLY,
                                                                   D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&iBuffer,
NULL );
// Check the return code of CreateVertexBuffer call to make sure it succeeded
if FAILED (hr)
hr=NULL;
// // Prepare to copy the indexes into the index buffer
VOID* IndexPtr;;
// Lock the vertex buffer
hr = iBuffer->Lock(0,
0,
(void**) &IndexPtr,
0);
// Check to make sure the vertex buffer can be locked
if FAILED (hr)
hr=NULL;
// // Copy the indices into the buffer
memcpy ( IndexPtr, g_Vertices3, sizeof(IndexData3)*sizeof(WORD) );
// Unlock the vertex buffer
iBuffer->Unlock();
// Present the back buffer contents to the display


pd3dDevice->BeginScene();
// Set the vertex format
pd3dDevice->SetFVF( D3DFVF_DIFFUSE|D3DFVF_XYZRHW );
pd3dDevice->SetStreamSource( 0, vertexBuffer, 0, sizeof(CUSTOMVERTEX) );


// Set the indices to use
pd3dDevice->SetIndices(iBuffer);

// Call DrawPrimitive to draw the cube
pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,
0, // BaseVertexIndex
0, // MinIndex
4, // NumVertices
0, // StartIndex
2 ); // primitive count*/
pd3dDevice->EndScene();


pd3dDevice-&gtresent( NULL, NULL, NULL, NULL );
}
sf_2005425183618.jpg

0

主题

237

帖子

237

积分

中级会员

Rank: 3Rank: 3

积分
237
发表于 2005-4-25 19:32:00 | 显示全部楼层

Re:关于DX的索引渲染,不知道错再那?

你宣告的Vertex?料不正?, 你Vertex?料的是XYZ|DIFFUSE, 但你Create VB和渲染?r都是用DIFFUSE|XYZRHW, ?料型?B和次序都?了 !!

??r只看到??...

29

主题

97

帖子

99

积分

注册会员

Rank: 2

积分
99
 楼主| 发表于 2005-4-26 11:15:00 | 显示全部楼层

Re:关于DX的索引渲染,不知道错再那?

我改成XYZ|DIFFUSE 后,不出错了,谢谢.但是还是没有渲染出任何东西来.

29

主题

97

帖子

99

积分

注册会员

Rank: 2

积分
99
 楼主| 发表于 2005-4-26 13:03:00 | 显示全部楼层

Re:关于DX的索引渲染,不知道错再那?

没人知道吗?救命啊

2

主题

85

帖子

85

积分

注册会员

Rank: 2

积分
85
发表于 2005-4-26 17:27:00 | 显示全部楼层

Re:关于DX的索引渲染,不知道错再那?

你没有设置变换矩阵。

想要得到正确的结果应该都用XYZ_RHW

18

主题

579

帖子

583

积分

高级会员

Rank: 4

积分
583
发表于 2005-4-28 03:36:00 | 显示全部楼层

Re:关于DX的索引渲染,不知道错再那?

RHW是不经过变换的,看你的坐标应该是用RHW德,D3DFVF_DIFFUSE|D3DFVF_XYZRHW顺序翻了没关系的。

18

主题

579

帖子

583

积分

高级会员

Rank: 4

积分
583
发表于 2005-4-28 03:37:00 | 显示全部楼层

Re:关于DX的索引渲染,不知道错再那?

看看你得Adapter是否支持INdex32
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-25 12:08

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表