• Advertisement

Archived

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

D3DX Texture problems - please help

This topic is 5061 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'm trying to follow Jim Adams 'Role Playing Games' book and am having trouble displaying a texture onto a vertex buffer. Also the polygon gets drawn in the top right hand side, when I want it to be on the left. Is this due to not setting the view, world matrix and so on. If so could some one please show me how it is done. Thank you very much for your time and help. bellow is my code to setup everything and then an attempt to display a texture. Sory if the code is a little out of shape. 'pD3DTexture' is the texture

BOOL DoInit()
{
	D3DPRESENT_PARAMETERS d3dpp;
	D3DDISPLAYMODE        d3ddm;
	BYTE *Ptr;
	
	sVertex Verts[4] = {
		{0.0f, 1.0f, 1.0f, 0.0f, 0.0f },
		{1.0f, 1.0f, 1.0f, 1.0f, 0.0f },
		{1.0f, 0.0f, 1.0f, 1.0f, 1.0f },
		{0.0f, 0.0f, 1.0f, 0.0f, 1.0f }
	};

	 // Do a windowed mode initialization of Direct3D

	if((g_pD3D = Direct3DCreate8(D3D_SDK_VERSION)) == NULL)
		return FALSE;
	  if(FAILED(g_pD3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &d3ddm)))
		return FALSE;
	  ZeroMemory(&d3dpp, sizeof(d3dpp));
	  d3dpp.Windowed = TRUE;
	  d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
	  d3dpp.BackBufferFormat = d3ddm.Format;
	  d3dpp.EnableAutoDepthStencil = FALSE;
	  if(FAILED(g_pD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd,
									  D3DCREATE_SOFTWARE_VERTEXPROCESSING,
									  &d3dpp, &g_pD3DDevice)))
		return FALSE;

	  // Create Vertex Buffer

	  if(FAILED((g_pD3DDevice->CreateVertexBuffer(					  sizeof(sVertex) *4, 0, VertexFVF,			  D3DPOOL_MANAGED, &pD3DVB)))) {
		  return FALSE;
	  }


	  // Lock the Vertex Buffer memory

	  if(FAILED(pD3DVB->Lock(0, 0, (BYTE**)&Ptr, 0))) {
		  return FALSE;
	  }

	  // Copy local vertices into vertex buffer

	  memcpy(Ptr, Verts, sizeof(Verts));

	  pD3DVB->Unlock(); // Unlock Vertex Buffer


	  // Load Texture

	  if(FAILED(D3DXCreateTextureFromFile(g_pD3DDevice, "Texture.bmp", &pD3DTexture))) {
		  return FALSE;}

	  if(FAILED(g_pD3DDevice->SetTextureStageState(0,					  D3DTSS_MINFILTER, D3DTEXF_POINT))) {
		  return FALSE;}

  return TRUE;
}

BOOL DoShutdown()
{
	// Release Vertex Buffer

	if(pD3DVB != NULL)
		pD3DVB->Release();

	// Release Texture object

	if(pD3DTexture != NULL)
		pD3DTexture->Release();

	// Release device and 3D objects

	  if(g_pD3DDevice != NULL)
		g_pD3DDevice->Release();

	  if(g_pD3D != NULL)
		g_pD3D->Release();
	  return TRUE;
}

BOOL DoFrame()
{

	if(FAILED(g_pD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,				D3DCOLOR_RGBA(255,255,255,255), 1.0f, 0))) {
		return FALSE;
	}

	if(SUCCEEDED(g_pD3DDevice->BeginScene())) {

		
		// Set the Vertex Stream and Shader

		g_pD3DDevice->SetStreamSource(0, pD3DVB, sizeof(sVertex));
		g_pD3DDevice->SetVertexShader(VertexFVF);
		g_pD3DDevice->SetTexture(0, pD3DTexture);

		g_pD3DDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);
		
		g_pD3DDevice->SetTexture(0, NULL);

		// End the scene

		g_pD3DDevice->EndScene();
	}

	if(FAILED(g_pD3DDevice->Present(NULL,NULL,NULL,NULL))) {
		return FALSE;
	}

  return TRUE;
}
[edited by - Superpig on June 11, 2004 4:04:17 AM]

Share this post


Link to post
Share on other sites
Advertisement
quote:
Original post by computer_guy
Sorry about the form thing not working

It''s [ source ] you wanted, not [form], as the Forum FAQ explains. I''ve fixed it for you.

Share this post


Link to post
Share on other sites
One problem is that you never made a call to SetFVF. What is your FVF anyway?

Since you''re not using any matrices at all, you need to specify your vertices as screen coordinates. If that''s the case, your 1x1 box will be VERY tiny.

Take a look at Tutorial 2 from the SDK and try modifying it to allow you to use textures.

neneboricua

Share this post


Link to post
Share on other sites

  • Advertisement