Archived

This topic is now archived and is closed to further replies.

SumDude

Direct3D Texturing Trouble

Recommended Posts

For some reason my Direct3D Application is not displaying a texture or my triangle at all. My Structure is struct point_vertex { float x,y,z; float tU,tV; }; and i define the info as int vert_count=sizeof(line)/sizeof(point_vertex); int byte_count=vert_count*sizeof(point_vertex); #define point_fvf D3DFVF_XYZ|D3DFVF_TEX1 The craziest thing tho is that when i change it to D3DFVF_XYZRHW and add rhw at the end of the first float it works.. like struct point_vertex { float x,y,z,rhw; float tU,tV; }; #define point_fvf D3DFVF_XYZRHW|D3DFVF_TEX1

void Render(void)
{
	line[0].x=100.0f;
	line[0].y=100.0f;
	line[0].z=1.0f;
	line[0].tU=0.0f;
	line[0].tV=0.0f;

	line[1].x=200.0f;
	line[1].y=200.0f;
	line[1].z=1.0f;
	line[1].tU=1.0f;
	line[1].tV=1.0f;
	
	line[2].x=100.0f;
	line[2].y=200.0f;
	line[2].z=1.0f;
	line[2].tU=0.0f;
	line[2].tV=1.0f;

	void *pVertices;
	g_pVB->Lock(0,0,&pVertices,0);
	memcpy(pVertices,line,byte_count);
	g_pVB->Unlock();

	g_pd3dDevice->SetStreamSource(0,g_pVB,0,sizeof(point_vertex));

	g_pd3dDevice->SetFVF(point_fvf);
	g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET,0x00000000,1.0f, 0);

	g_pd3dDevice->BeginScene();

	g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,vert_count/3);
	
	g_pd3dDevice->EndScene();

	g_pd3dDevice->Present(NULL,NULL,NULL,NULL);
}

void InitD3D(HWND hWnd)
{
	g_pd3d = Direct3DCreate9(D3D_SDK_VERSION);
	if(!g_pd3d)
	{
	}
	D3DPRESENT_PARAMETERS d3dpp;
	ZeroMemory(&d3dpp, sizeof(d3dpp));

	d3dpp.BackBufferCount = 1;
	d3dpp.Windowed = true;
	d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
	d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;

	g_pd3d->CreateDevice(D3DADAPTER_DEFAULT, 
		D3DDEVTYPE_HAL, 
		hWnd,
		D3DCREATE_SOFTWARE_VERTEXPROCESSING,
		&d3dpp,
		&g_pd3dDevice);

	g_pd3dDevice->CreateVertexBuffer(byte_count, D3DUSAGE_WRITEONLY,point_fvf,D3DPOOL_MANAGED,
		&g_pVB,NULL);	

	D3DXCreateTextureFromFile(g_pd3dDevice,"Texture.bmp",&g_pTexture);

	g_pd3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_MODULATE);
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_COLORARG2, D3DTA_DIFFUSE);
	// Turn off the alpha channel since the texture doesn''t have one
	g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_DISABLE);
	g_pd3dDevice->SetTexture(0,g_pTexture);
	
}

 

Share this post


Link to post
Share on other sites
The reason it doesn''t work in the case where your FVF is set up as "D3DFVF_XYZ|D3DFVF_TEX1" is because you never specify any of your tranformation matrices. You''re never setting your World, View, or Projection matrices at all.

On the other hand, when you specify that you''re going to be using transformed vertices (which is what D3DFVF_XYZRHW means) then you don''t need to specify any matrices. D3D assumes that any coordinates you give it are already in screen space.

neneboricua

Share this post


Link to post
Share on other sites