Can't texture quad

Started by
1 comment, last by Sneftel 15 years, 3 months ago
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]
Advertisement
Replied in your Other Thread.
Please don't cross-post on these forums.

This topic is closed to new replies.

Advertisement