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

发布于 2024-11-01 02:55:22 字数 2608 浏览 0 评论 0原文

这个问题是“为什么 D3DXCreateCylinder 不创建圆柱体?”。我可以绘制圆柱体,但它只是将其绘制为 full White

代码如下

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;
    }
}

或者下载工程。 我在这里吸引了我的代码“项目代码< /a>” 我想用 3D 阴影来绘制它,如果默认渲染的话,通常任何 3D 网格都会有这种阴影。 我对材料不太了解。或者是显卡的问题(我只是想:D)。

此外,我可以在哪里获取 abt SetRenderState 的信息和示例

This question is in continuation of "why D3DXCreateCylinder is not creating a cylinder?". I m able to draw the cylinder but it is only drawing it as full white.

The code is as follows

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;
    }
}

or download the project.
I have attracted my codes here "project code"
I want to draw it having 3D shades what generally any 3D mesh has if rendered by default.
I am not nicely aware of materials. Or is it the problem with graphics card (I just thought :D ).

In addition where can I get information and samples abt SetRenderState

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

水晶透心 2024-11-08 02:55:22

尝试

g_d3d_device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL );

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

Try

g_d3d_device->SetRenderState( D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_MATERIAL );

At the moment it is defaulting to using "Color 1" which is the first of the 2 possible vertex colours.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文