游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1167|回复: 1

问题

[复制链接]

5

主题

8

帖子

30

积分

注册会员

Rank: 2

积分
30
发表于 2009-6-8 23:41:00 | 显示全部楼层 |阅读模式
void ShowTerrain(int nRow,int nCol,int nSize)
{
        const int col = 5;

    #define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

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

    static cellData2 cellData[col][col];

        CMyPos beginPos = {300,300};
        int startY = 0;
        for(startY = 0 ; startY < nCol;++startY)
        {
                for (int startX = 0 ; startX < nRow ;++startX)
                {
                        cellData[startY][startX].x = beginPos.x + startX * nSize;
                        cellData[startY][startX].y = beginPos.y + startY * nSize;
                        cellData[startY][startX].z = 0;
            cellData[startY][startX].rhw = 1;
                        cellData[startY][startX].color = 0;
                }
        }

        static int indexData[(col - 1) * (col - 1) * 6];

        int count = 0;
        int n = 0;
        for(startY = 0;startY < (nCol -1 ) * (nRow - 1) * 6;startY += 6)
        {
                indexData[startY] = n;
                indexData[startY + 1] = n + 1;
                indexData[startY + 2] = (count + 1) * nCol + n;
               
                indexData[startY + 3] = n + 1;
                indexData[startY + 4] = (count + 1) * nCol + n + 1;
                indexData[startY + 5] = (count + 1) * nCol + n;
                ++n;
                if(n%nCol==0)
                   ++count;
        }

        LPDIRECT3DVERTEXBUFFER8 vb;
        g_D3DDevice->CreateVertexBuffer(3 * sizeof(cellData2),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_MANAGED,&vb);

        void* vertex;
        vb->Lock(0,sizeof(cellData),(BYTE**)&vertex,0);
        memcpy(vertex,cellData,sizeof(cellData));
        vb->Unlock();

        static LPDIRECT3DINDEXBUFFER8 ibs;

//为什么下边一行创建的时候总是报错啊
    g_D3DDevice->CreateIndexBuffer( sizeof ( indexData ),D3DUSAGE_WRITEONLY,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&ibs );

        VOID* pIndices;
       
        if( FAILED( ibs->Lock( 0,                 // Fill from start of the buffer.
                sizeof(indexData), // Size of the data to load.
                (BYTE**)&pIndices, // Returned index data.
                0 ) ) )            // Send default flags to the lock.
                return;
       
        memcpy( pIndices, indexData, sizeof(indexData) );
        ibs->Unlock();

        g_D3DDevice->SetStreamSource(0,vb,sizeof(cellData2));
        g_D3DDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );

        g_D3DDevice->SetIndices( ibs, 0 );

        g_D3DDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0,nCol * nRow, 0, sizeof(indexData)/(sizeof(int) *3));

}abc

11

主题

650

帖子

651

积分

高级会员

Rank: 4

积分
651
发表于 2009-6-9 09:09:00 | 显示全部楼层

Re:问题

1.置顶第3条
2.莫非你这显卡是mx440之类的?(纯猜测)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2025-12-20 01:00

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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