Jump to content
  • Advertisement
Sign in to follow this  
guyaton

i haven't done anything with textures for a while

This topic is 4855 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 haven't done anything with textures for a while and can't seem to get a simple texture to work. I am trying to create a skybox (which works) and if i set the diffuse color to red that works. However, when I try to assign the texture, all I get is a black image. I checked and the Image is loading properly maybe i'm just setting it up incorrectly? my header file
struct SFVF_XYZ_DIFFUSE
{
	D3DXVECTOR3 coord;
	DWORD diffuse;
	float tu, tv;
};

#define FVF_XYZ_DIFFUSE ( D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 )

class CSkybox// : public CRenderable
{
public:
	CSkybox();
	~CSkybox();

	virtual HRESULT CreateSkybox( float fWidth, float fHeight, float fDepth, DWORD dwColor ); //x, y, z
	virtual HRESULT Render();

protected:
	LPDIRECT3DVERTEXBUFFER9 m_vb;
	LPDIRECT3DINDEXBUFFER9  m_ib;
	LPDIRECT3DTEXTURE9		m_tex;

};

my source file
CSkybox::CSkybox() : 
	//CRenderable( true ),
	m_vb( NULL ),
	m_ib( NULL ),
	m_tex( NULL )
{
	;
}

CSkybox::~CSkybox()
{
	SAFE_RELEASE( this->m_vb );
	SAFE_RELEASE( this->m_ib );
	SAFE_RELEASE( this->m_tex );
}

HRESULT CSkybox::CreateSkybox( float fWidth, float fHeight, float fDepth, DWORD dwColor )
{
	SFVF_XYZ_DIFFUSE Skybox[8];

	Skybox[0].coord = D3DXVECTOR3( fWidth, fHeight, fDepth );
	Skybox[0].diffuse = dwColor;
	Skybox[0].tu = 0.0f;
	Skybox[0].tu = 0.0f;

	Skybox[1].coord = D3DXVECTOR3( -fWidth, fHeight, fDepth );
	Skybox[1].diffuse = dwColor;
	Skybox[1].tu = 1.0f;
	Skybox[1].tu = 0.0f;

	Skybox[2].coord = D3DXVECTOR3( -fWidth, -fHeight, fDepth );
	Skybox[2].diffuse = dwColor;
	Skybox[2].tu = 1.0f;
	Skybox[2].tu = 1.0f;

	Skybox[3].coord = D3DXVECTOR3( fWidth, -fHeight, fDepth );
	Skybox[3].diffuse = dwColor;
	Skybox[3].tu = 0.0f;
	Skybox[3].tu = 1.0f;

	Skybox[4].coord = D3DXVECTOR3( fWidth, fHeight, -fDepth );
	Skybox[4].diffuse = dwColor;
	Skybox[4].tu = 0.0f;
	Skybox[4].tu = 0.0f;

	Skybox[5].coord = D3DXVECTOR3( -fWidth, fHeight, -fDepth );
	Skybox[5].diffuse = dwColor;
	Skybox[5].tu = 1.0f;
	Skybox[5].tu = 0.0f;

	Skybox[6].coord = D3DXVECTOR3( -fWidth, -fHeight, -fDepth );
	Skybox[6].diffuse = dwColor;
	Skybox[6].tu = 1.0f;
	Skybox[6].tu = 1.0f;

	Skybox[7].coord = D3DXVECTOR3( fWidth, -fHeight, -fDepth );
	Skybox[7].diffuse = dwColor;
	Skybox[7].tu = 0.0f;
	Skybox[7].tu = 1.0f;
			//i don't want 2 sides thats why these are commented out
	DWORD dwIndices[] = { /*1, 0, 2, 2, 0, 3, 4, 5, 6, 4, 6, 7,*/ 0, 4, 3, 3, 4, 7, 5, 1, 6, 6, 1, 2, 0, 1, 5, 0, 5, 4, 2, 3, 6, 3, 7, 6 };


	if( FAILED( g_device3D->CreateVertexBuffer( 24*sizeof( SFVF_XYZ_DIFFUSE ), D3DUSAGE_WRITEONLY, 
		FVF_XYZ_DIFFUSE, D3DPOOL_MANAGED, &this->m_vb, NULL ) ) )
	{
		return E_FAIL;
	}

	SFVF_XYZ_DIFFUSE *ptr;

	this->m_vb->Lock( 0, sizeof( Skybox ), (void**)&ptr, 0 );
	memcpy( ptr, Skybox, sizeof( Skybox ) );
	this->m_vb->Unlock();

	LPDIRECT3DINDEXBUFFER9 temp;
	if( FAILED( g_device3D->CreateIndexBuffer( sizeof( dwIndices ), D3DUSAGE_WRITEONLY, 
		D3DFMT_INDEX32, D3DPOOL_MANAGED, &this->m_ib, NULL ) ) )
	{
		return E_FAIL;
	}

	this->m_ib->Lock( 0, 0, (void**)&temp, 0 );

	memcpy( temp, dwIndices, sizeof( dwIndices ) );
	this->m_ib->Unlock();

	if( FAILED( D3DXCreateTextureFromFile( g_device3D, "..\\media\\back.bmp", &this->m_tex ) ) )
	{
		return E_FAIL;
	}

	return S_OK;
}

HRESULT CSkybox::Render()
{
	//g_device3D->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
	//g_device3D->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME );
	D3DXMATRIXA16 matWorld;
	D3DXMatrixIdentity( &matWorld );

	g_device3D->SetRenderState( D3DRS_LIGHTING, FALSE );

	g_device3D->SetTexture( 0, this->m_tex );
	g_device3D->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
	g_device3D->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
	g_device3D->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTOP_DISABLE );

	g_device3D->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
	g_device3D->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );

	g_device3D->SetStreamSource( 0, this->m_vb, 0, sizeof( SFVF_XYZ_DIFFUSE ) );
	g_device3D->SetFVF( FVF_XYZ_DIFFUSE );
	g_device3D->SetIndices( this->m_ib );
	g_device3D->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12 );

	return S_OK;
}

thanks for your help in advance ~guyaton

Share this post


Link to post
Share on other sites
Advertisement
Skybox[0].tu = 0.0f;
Skybox[0].tu = 0.0f;

maybe you mean

Skybox[0].tu = 0.0f;
Skybox[0].tv = 0.0f;

g_device3D->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
If you're going to disable the alpha operation, setting the parameters does absolutely nothing but waste time and make your code more comfusing.

g_device3D->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
g_device3D->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
g_device3D->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTOP_DISABLE );
That's a problem... you're telling Direct3D to pick the diffuse color and ignore the color from the texture. Also the D3DTOP constants are for COLOROP and ALPHAOP, the D3DTA constants are for COLORARGs and ALPHAARGS. You used D3DTOP_DISABLE for COLORARG2. What you probably want to do multiply (modulate) the diffuse color with the texture.
g_device3D->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
g_device3D->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE );
g_device3D->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE );

Also, make sure dwColor isn't black or too dark.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!