为什么D3DXCreateCylinder做网格着色/材质不工作? [英] why D3DXCreateCylinder made mesh coloring/material is not working?

查看:206
本文介绍了为什么D3DXCreateCylinder做网格着色/材质不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是
我想画它有3D阴影通常任何3D网格如果呈现默认情况下。
我不太清楚材料。或者是显卡的问题(我只是想:D)。



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

解决方案

尝试

 code> g_d3d_device-> SetRenderState(D3DRS_DIFFUSEMATERIALSOURCE,D3DMCS_MATERIAL); 

此时,它默认使用Color 1,它是2个可能顶点中的第一个颜色。


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 .

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

解决方案

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.

这篇关于为什么D3DXCreateCylinder做网格着色/材质不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆