How to paste texture

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

Recommended Posts

I just use D3DXCreateTextureFromFile() to create a sphere. But i cant paste a picture on my sphere. I dont know , whats wrong with my code. Please help me , Thanks... And , That is my code : //inital area LPDIRECT3DDEVICE9 m_pDevice; LPD3DXMESH m_meshSphere; LPDIRECT3DTEXTURE9 m_pMyTexture; D3DMATERIAL9* m_sphereMaterials; ............ D3DXCreateSphere(m_pDevice, 200.0f, 20, 10, &m_meshSphere, NULL); D3DXCreateTextureFromFile(m_pDevice , L"XXX.jpg" , &m_pMyTexture); m_sphereMaterials = new D3DMATERIAL9; m_sphereMaterials->Diffuse.r=1.0; m_sphereMaterials->Diffuse.g=1.0; m_sphereMaterials->Diffuse.b=1.0; m_sphereMaterials->Diffuse.a=1; m_sphereMaterials->Ambient = m_sphereMaterials->Diffuse; m_sphereMaterials->Power=1; m_pDevice->SetRenderState(D3DRS_LIGHTING, TRUE); m_pDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(255, 255, 255)); m_pDevice->SetRenderState(D3DRS_ZENABLE ,TRUE); //render area m_pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); m_pDevice->SetTexture( 0 , (IDirect3DBaseTexture9*)m_pMyTexture ); m_pDevice->SetMaterial(m_sphereMaterials); m_meshSphere->DrawSubset(0);

Share on other sites
I am not familiar with the fixed pipeline functions, but isn't lighting supposed to be off when you have no lights in your scene? I've seen a couple of questions passing by lately about people not seeing anything rendered and it turned out to be the lighting parameter.

Share on other sites
I thought the same thing at first, but the ambient color is set to maximum (which should kind of nulify the lighting effect).

Share on other sites
just out of curiousity, did you try rendering it with just an ambient color, no texture? Is there no output at all? Are you sure the texture get's loaded properly (and is not a null parameter)?

Share on other sites
Quote:
 Original post by FeverGamesjust out of curiousity, did you try rendering it with just an ambient color, no texture? Is there no output at all? Are you sure the texture get's loaded properly (and is not a null parameter)?

D3DXCreateTextureFromFile() and SetTexture() return S_OK ...

And,the parameter(LPDIRECT3DTEXTURE9 m_pMyTexture;) in break point mode ,its seem has a correct address ( 0x4b6932b8 ).

Finaly, I don`t understand how the texture link to mesh.

My example code in book just show me put SetTexture() before DrawSubset().

Somebody help me , please ......QQ

[Edited by - pleaselouis on April 21, 2009 10:51:52 PM]

Share on other sites
Here are some steps to follow when debugging these types of problems.
1. Check if you can render the sphere without any materials/lighting/textures applied to it.
2. Apply some directional (best debugging light) lighting to the sphere and see if that works.
3. Apply a texture without any lighting (turn lighting off, because this mostly just confuses things when working with too many variables).

Other than that, what you need to be aware of is the following.
When rendering an object with lights the following variables need to be correct.
1. Material
2. Lighting setup correctly.

I hope this helps!

• 12
• 9
• 13
• 41
• 15