Skip to main content
GameDev.net gamedev.net
🔒 Locked

IDirect3DDevice8::SetTexture

Started by randal Dec 16, 2002 at 10:39 PM 2 replies 400+ views
Original Post
randal
randal
I'm following tutorials on andypike.com. In the mesh loading tutorial when he loads the .x file, he uses 3DXCreateTextureFromFile. He checks if this function fails and if it does he sets the texture array (m_pMeshTextures) to NULL. Then in the Render function he sets the texture like m_pD3DDevice->SetTexture(0, m_pMeshTextures[i]) When the texture is NULL it appears to not load anything. Trying to load the texture and seeing if it fails, then calling SetTexture on the NULL texture interface just seems like a bad way to do this.. what would be a better way? [edited by - randal on December 17, 2002 9:28:14 AM]
CrazedGenius
CrazedGenius
Setting the texture to NULL is okay. In fact, that's what you need to do to set the stage to no texture.

Read the docs:
quote:
When the texture is no longer needed, set the texture at the appropriate stage to NULL. Failure to do this results in a memory leak.



It's the way to decrement the ref count on the current texture (before shutting down, etc.)

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

[edited by - CrazedGenius on December 17, 2002 1:56:51 AM]
randal
randal
hey thanks for the reply. I actually did check the docs first but for whatever reason I didn''t see that at the time. I musta been pretty tired cause I checked again and did see the info I needed. It still seems strange to me though to check if 3DXCreateTextureFromFile failed, then set the texture to NULL.
mickey
mickey
hi randal,

if the D3DXCreateTextureFromFile fails, and he didn''t set the texture to NULL, then when the render function comes, it will break,

so.., probably rather than having his render function liks this,


void Render()
{
if(theres a texture)
SetTexture();
RenderXFile();
}


he can then instead omit the if, then just call on SetTexture and it won''t break because it''s set to NULL anyways,



http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.