Jump to content
  • Advertisement
Sign in to follow this  

how to render a tree's leaf in DX?

This topic is 3430 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I try to use rectangle to denote a leaf. why my following code doesn't work correctly: the surround of the leaf is green(as follows),how to make the rectangle looks like the leaf's texture? the generated leaf see the last line of the post. sorry,I dont know how to create one link of the url.
//(1)  create rectangle 
        6 * sizeof(Vertex), 

    Vertex* v;
    Quad->Lock(0, 0, (void**)&v, 0);

    // quad built from two triangles, note texture coordinates:
    v[0] = Vertex(-1.0f, -1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
    v[1] = Vertex(-1.0f,  1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
    v[2] = Vertex( 1.0f,  1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);

    v[3] = Vertex(-1.0f, -1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
    v[4] = Vertex( 1.0f,  1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);
    v[5] = Vertex( 1.0f, -1.0f, 1.25f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f);


//(2) set the material of the rectangle
    BkGndMtrl = d3d::WHITE_MTRL;

//(3) create the leaf's texture 

    Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
    Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
    Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

 //(4) Set alpha blending states.use alpha in material's diffuse component for alpha
    Device->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_DIFFUSE);
    Device->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1);

    // set blending factors so that alpha component determines transparency
    Device->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);

//(5)render the rectangle with texture
    Device->SetTexture(0, Tex);

    Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);//turn on alpha
    Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);//render rectangle
    Device->SetRenderState(D3DRS_ALPHABLENDENABLE, false);//disable alpha

the generated leaf: the leaf one in the pic is what i rendered and the left is the orignal texture. how to rend the rectanle just look like the texture. http://s19.photo.store.qq.com/http_imgload.cgi?/rurl4_b=1b718b3be555acf251d8a74b64ff766e790d9f6d7beb4b0410164e12e6eb95574ce13077280ad6486edff0a947bb01159ab41c5ae783b2cf62f7abb0cf771e7ffac49230cb3a30b0c44dbffcf698cff35d5f73e0

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!