C++ 为什么D3DXCreateCylinder制作的网格着色/材质不起作用?

C++ 为什么D3DXCreateCylinder制作的网格着色/材质不起作用?,c++,directx-9,C++,Directx 9,这项质询是“的延续”。我能画圆柱体,但它只是画得像我一样 代码如下 void draw_Cylinder(void){ D3DXMATRIX rot_matrix; D3DXMATRIX trans_matrix; D3DXMATRIX world_matrix; static float rot_triangle=0.0f; static float rot_triangle2=0.0f; D3DXMatrixRotationY(&

这项质询是“的延续”。我能画圆柱体,但它只是画得像我一样

代码如下

void draw_Cylinder(void){

    D3DXMATRIX rot_matrix;
    D3DXMATRIX trans_matrix;
    D3DXMATRIX world_matrix;
    static float rot_triangle=0.0f;
    static float rot_triangle2=0.0f;


    D3DXMatrixRotationY(&rot_matrix,rot_triangle);  //Rotate the cylinder
    D3DXMatrixRotationX(&rot_matrix,rot_triangle2);  //Rotate the cylinder
    D3DXMatrixTranslation(&trans_matrix,2.0f,0,20.0f); //Shift it 2 units to the left
    D3DXMatrixMultiply(&world_matrix,&rot_matrix,&trans_matrix);



    D3DMATERIAL9  material;// = new D3DMATERIAL9();



    ZeroMemory( &material, sizeof(D3DMATERIAL9) );

    // Set the RGBA for diffuse reflection.
    material.Diffuse.r = 0.5f;
    material.Diffuse.g = 0.0f;
    material.Diffuse.b = 0.5f;
    material.Diffuse.a = 1.0f;

    // Set the RGBA for ambient reflection.
    material.Ambient.r = 0.5f;
    material.Ambient.g = 0.0f;
    material.Ambient.b = 0.5f;
    material.Ambient.a = 1.0f;

    // Set the color and sharpness of specular highlights.
    material.Specular.r = 1.0f;
    material.Specular.g = 1.0f;
    material.Specular.b = 1.0f;
    material.Specular.a = 1.0f;
    material.Power = 2.0f;

    // Set the RGBA for emissive color.
    material.Emissive.r = 0.0f;
    material.Emissive.g = 0.0f;
    material.Emissive.b = 0.0f;
    material.Emissive.a = 0.0f;


    g_d3d_device->SetMaterial(&material);

    g_d3d_device->SetTexture(0,NULL);

    g_d3d_device->SetTransform(D3DTS_WORLD,&world_matrix);
    m_ppMeshCylinder->DrawSubset(0);
    ////Render from our Vertex Buffer
    //g_d3d_device->DrawPrimitive(D3DPT_TRIANGLELIST, //PrimitiveType
    //                            0,                  //StartVertex
    //                            g_pyramid_count);   //PrimitiveCount

    rot_triangle+=0.0007f;
    if(rot_triangle > D3DX_PI*2)
    {  
        rot_triangle-=D3DX_PI*2;
    }

    rot_triangle2+=0.0007f;
    if(rot_triangle2 > D3DX_PI*2)
    {  
        rot_triangle2-=D3DX_PI*2;
    }
}
或者下载项目。 我在这里吸引了我的代码“” 我想画它有三维阴影,通常任何三维网格都有,如果默认情况下渲染。 我对材料不是很了解。或者是图形卡的问题(我只是想:D)

此外,我在哪里可以获得信息和样本abt
SetRenderState

试试看

g_d3d_device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL );

目前,它默认使用“颜色1”,这是两种可能的顶点颜色中的第一种

您以前也设置过光源吗?如果没有,你需要这样做。好吧,在我加了一盏灯之后,它在同一个项目中工作。。但不在主项目中(另一个单独的项目)。我尝试了它的顶点的方式如下,因为它的光是不需要的。这对我来说真的很艰难。”pTempEarthMesh->CloneMeshFVF(0,D3DFVF_MY_顶点,g_pd3d设备和g_pEarthMesh);CUSTOMVERTEX pVertices=NULL;pTempVertexBuffer->Lock(0,0,(void*)和pVertices,0);{for(int i=0;i