• Advertisement
Sign in to follow this  

Can't texture quad

This topic is 3309 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 have problems texturing my quad. I am pretty sure that I have loaded the textures correctly. Can anyone please see if I have missed out something? At the moment it just show the quad in a grey-ish (default) colour.
#define D3DFVF_CUSTOMVERTEX  D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1

void Setup()
{

	//
	// Create vertex and index buffers.
	//

	Device->CreateVertexBuffer(
		24 * sizeof(Vertex), 
		0,
		Vertex::FVF,
		D3DPOOL_MANAGED,
		&VB,
		0);


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

	// floor
	v[0] = Vertex(-7.5f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	v[1] = Vertex(-7.5f, 0.0f,   0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
	v[2] = Vertex( 7.5f, 0.0f,   0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
	
	v[3] = Vertex(-7.5f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	v[4] = Vertex( 7.5f, 0.0f,   0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);
	v[5] = Vertex( 7.5f, 0.0f, -10.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f);

	VB->;Unlock();

	D3DXCreateTextureFromFile(Device, "floor.jpg", &FloorTex);
	
	Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
}


bool Display(float timeDelta)
{
	if( Device )
	{
		// snipped out some initialisation etc

		D3DXMatrixInverse(&mWorldViewIT, NULL, &mWorldView);
		D3DXMatrixTranspose(&mWorldViewIT, &mWorldViewIT);
		mFX->SetMatrix(mhWorldViewIT,&(mWorldViewIT));
		mFX->SetMatrix(mhWVP,&(mWorld*mView*mproj));

		//Begin passes
		mFX->Begin(&numPasses,0);
		//draw textured quad
		for(int i=0; i < numPasses; ++i)
		{
			mFX->BeginPass(i);			
			mFX->SetTexture(mhgTex,FloorTex);
			mFX->CommitChanges();
			Device->SetStreamSource(0, VB, 0, sizeof(Vertex));
			Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
			mFX->EndPass();		

		}
		mFX->End();		
		
		Device->EndScene();
		Device->Present(0,0,0,0); 
	}
	return true;
}





[Edited by - jonathanc on January 26, 2009 1:21:14 PM]

Share this post


Link to post
Share on other sites
Advertisement
Please don't cross-post on these forums.

Share this post


Link to post
Share on other sites

This topic is 3309 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.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement