Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  
DividedByZero

how to set a texture?

This topic is 2013 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

Hi guys,

I am playing with triangle lists for the first time to draw an object (I have always relied on ID3DXSPRITE in the past)

I can get a tringle to render ok with the following code, but I am not sure on how to apply a texture to that triangle.

This is what I have so far (all crammed in the draw call)
 
LPDIRECT3DVERTEXBUFFER9 pVertexObject = NULL;
void *pVertexBuffer = NULL; 

struct D3DVERTEX{
				float x,y,z,rhw;
				DWORD color;
				float u;
				float v;
					} vertices[3]; 

vertices[0].x = 50; 
vertices[0].y = 50; 
vertices[0].z = 0; 
vertices[0].rhw = 1.0f; 
vertices[0].color = 0xffffff;
vertices[0].u=0.0;
vertices[0].v=0.0;

vertices[1].x = 250; 
vertices[1].y = 50; 
vertices[1].z = 0; 
vertices[1].rhw = 1.0f; 
vertices[1].color = 0xffffff; 
vertices[0].u=1.0;
vertices[0].v=0.0;

vertices[2].x = 50; 
vertices[2].y = 250; 
vertices[2].z = 0; 
vertices[2].rhw = 1.0f;
vertices[2].color = 0xffffff;
vertices[0].u=0.0;
vertices[0].v=1.0;

if(FAILED(mRenderer->getDevice()->CreateVertexBuffer(3*sizeof(D3DVERTEX),0,D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1,D3DPOOL_DEFAULT,&pVertexObject,NULL)))
	return(0);
 
if(FAILED(pVertexObject->Lock(0,3*sizeof(D3DVERTEX),&pVertexBuffer,0)))
	return(0);
memcpy(pVertexBuffer, vertices, 3*sizeof(D3DVERTEX));
pVertexObject->Unlock();


// do the actual render
mRenderer->getDevice()->SetStreamSource(0,pVertexObject,0,sizeof(D3DVERTEX));
mRenderer->getDevice()->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
mRenderer->getDevice()->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);

mRenderer->getDevice()->SetTexture(0,mRenderer->pTexture);
I know, not effiecient having this all crammed into the draw call. This is for testing purposes only and once I get it working I'll move the calls to where they should be. My main challenge is to get the texture on to the triangle.

I know that pTexture is a valid texture (as I am using it in my ID3DXSPRITE calls that are commented out in my code)

Any help would be awesome! smile.png Edited by lonewolff

Share this post


Link to post
Share on other sites
Advertisement

You might want to set the texture on the device before you draw the primitive. :-)

 

Also, you need to use an FVF (if you insist on avoiding shaders) that matches your vertex buffer (e.g. it needs to include D3DFVF_TEX1).

Edited by Dave Hunt

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!