0

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

Community
  • 1
  • 1
Rick2047
  • 1,565
  • 7
  • 24
  • 35
  • 1
    Have you also set up a light source before? If not, you need to do that. – casablanca Apr 13 '11 at 14:52
  • Fine, it working here in the same project after I added a light .. but not in the main project (another separate project). I tried it vertex way as follows For it light is not required. It really has gone tough for me. 'pTempEarthMesh->CloneMeshFVF( 0, D3DFVF_MY_VERTEX, g_pd3dDevice, &g_pEarthMesh ); CUSTOMVERTEX *pVertices = NULL; pTempVertexBuffer->Lock( 0, 0, (void**)&pVertices, 0 ); {for( int i = 0; i < nNumVerts; ++i )pVertices[i].diffuse = D3DCOLOR_COLORVALUE( 0.0, 0.0, 1.0, 1.0 );' – Rick2047 Apr 13 '11 at 15:22
  • It worked for the project I linked to. – Rick2047 Apr 18 '11 at 07:42

1 Answers1

0

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.

Goz
  • 61,365
  • 24
  • 124
  • 204
  • Lighting has done the required. please also look at http://stackoverflow.com/questions/5700001/how-to-give-a-mesh-vertex-like-self-lighitng – Rick2047 Apr 18 '11 at 09:10