Jump to content

  • Log In with Google      Sign In   
  • Create Account


how to set a texture?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 16 April 2014 - 07:17 PM

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, 16 April 2014 - 07:42 PM.


Sponsor:

#2 Dave Hunt   Crossbones+   -  Reputation: 2419

Like
1Likes
Like

Posted 16 April 2014 - 08:32 PM

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, 16 April 2014 - 08:33 PM.


#3 DarkRonin   Members   -  Reputation: 604

Like
0Likes
Like

Posted 16 April 2014 - 09:20 PM

Ahh, ok. Got it smile.png

I am not up and running.

Thanks smile.png




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS