Jump to content
  • Advertisement
Sign in to follow this  
MrBeaner

having a problem drawing a textured quad

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

hello- i am not sure what i am doing wrong, but i can't get the quad to render. directx is set up properly, i can render things, but i can't get the quad class to do its thing. i think it might be the way i am describing the quad. Here is the functiont to create the billboard:
void cBillboard::CreateBillboard()
{
	
	HRESULT r;
	VOID* pVertices;

	v = new CUSTOM_VERTEX[4];
    
	//create the vertical info.
	//thisprobably cold only happen once if the billboard isn't changing, but it works for now
		v[0].x = 0.0f;
		v[0].y = 0.0f;
		v[0].z = 0.0f;
		v[0].color = myColor;
		v[0].u = 0.0f;
		v[0].v = 1.0f;

		v[1].x = myWidth;
		v[1].y = 0.0f;
		v[1].z = 0.0f;
		v[1].color = myColor;
		v[1].u = 1.0f;
		v[1].v = 1.0f;

		v[2].x = myWidth;
		v[2].y = myHeight;
		v[2].z = 0.0f;
		v[2].color = myColor;
		v[2].u = 1.0f;
		v[2].v = 0.0f;

		v[3].x = 0.0f;
		v[3].y = myHeight;
		v[3].z = 0;
		v[3].color = myColor;
		v[3].u = 0.0f;
		v[3].v = 0.0f;

	r = VB->Lock( 0, 0, (VOID**)&pVertices, 0 );

	if(r != D3D_OK)
	{
		gLog<<"cBillboard:  Failed to lock vertex the buffer.  "<<DXGetErrorString(r)<<endl;
		return;
	}

	memcpy(pVertices, v, sizeof(v));

	VB->Unlock();
}

here is the render code:
void cBillboard::render()
{	

	D3DXMATRIX final, trans;
	D3DXMatrixIdentity(&final);
	D3DXMatrixTranslation(&trans, Position.x, Position.y, Position.z);
	D3DXMatrixMultiply(&final, &final, &trans);
	Game->GetDX()->GetRenderer()->GetDevice()->SetTransform(D3DTS_WORLD, &final);

	gLog<<"rendering."<<endl;
	Game->GetDX()->GetRenderer()->GetDevice()->SetTexture(0, myTexture);
	Game->GetDX()->GetRenderer()->GetDevice()->SetStreamSource(0, VB, 0, sizeof(CUSTOM_VERTEX));
	Game->GetDX()->GetRenderer()->GetDevice()->SetFVF(FVF());
	Game->GetDX()->GetRenderer()->GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1);
}

here is the constructor:
cBillboard::cBillboard(LPDIRECT3DTEXTURE9 Texture, float x, float y, float z, float tu, float tv, UINT w, UINT h)
{
	myTexture = Texture;
	SetPosition(x, y, z);
	texu = tu;
	texv = tv;
	myColor = D3DCOLOR_ARGB(255,0,0,0);
	myWidth = w;
	myHeight = h;
	v = 0;

	VB = NULL;

	HRESULT r;

	r = Game->GetDX()->GetRenderer()->GetDevice()->CreateVertexBuffer((4*sizeof(CUSTOM_VERTEX)), 0, FVF(), D3DPOOL_DEFAULT, &VB, NULL);
	if(r != D3D_OK)
	{
		gLog<<"cBillboard:  error creating vertex buffer.  "<<DXGetErrorString(r)<<endl;
		delete this;
	}

	CreateBillboard();

}		

any ideas would be greatly appretiated.

Share this post


Link to post
Share on other sites
Advertisement
I noticed you aren't drawing enough trianglestrips. You need two draw two, the upper-left triangle and lower-right triangle that make up the quad. But that probably won't completely fix your problem.


void cBillboard::render()
{

D3DXMATRIX final, trans;
D3DXMatrixIdentity(&final);
D3DXMatrixTranslation(&trans, Position.x, Position.y, Position.z);
D3DXMatrixMultiply(&final, &final, &trans);
Game->GetDX()->GetRenderer()->GetDevice()->SetTransform(D3DTS_WORLD, &final);

gLog<<"rendering."<<endl;
Game->GetDX()->GetRenderer()->GetDevice()->SetTexture(0, myTexture);
Game->GetDX()->GetRenderer()->GetDevice()->SetStreamSource(0, VB, 0, sizeof(CUSTOM_VERTEX));
Game->GetDX()->GetRenderer()->GetDevice()->SetFVF(FVF());
Game->GetDX()->GetRenderer()->GetDevice()->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); <-----*******
}



Check your function FVF() to make sure it returns the right stuff. It may be easier to just delcare a constant like so:

const DWORD VertexFVF = (D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1 );



Just pass in the constant to SetFVF.

Share this post


Link to post
Share on other sites
You've got myColour set to black and fully opaque - you're not clearing the back buffer to black are you (so it is drawing, it's just you can't tell?)

Change the back buffer clearing to something obvious like lime green just to test.

Is the shader expecting the colours in the same order as there getting passed in - i.e. the black opaque isn't getting re-arranged so it's red fully transparent or something along those lines?

:)

Share this post


Link to post
Share on other sites
Actually, scratch that, it's:

memcpy(pVertices, v, sizeof(v));

that's wrong - the sizeof(v) is the sizeof a pointer which is only 4 bytes so it's not copying all the data over into the VB.

what you need is:

memcpy(pVertices, v, (sizeof(CUSTOM_VERTEX) * uiNumVerts));

where uiNumVerts = 4 in this case.

Cheers,

:D

Share this post


Link to post
Share on other sites
Quote:

You've got myColour set to black and fully opaque - you're not clearing the back buffer to black are you (so it is drawing, it's just you can't tell?)

Change the back buffer clearing to something obvious like lime green just to test.



that did it! nice job! its there, but now its a wierd line. i think maybe i should check the camera angle now. thanks a lot!

Share this post


Link to post
Share on other sites
Quote:
Original post by MrBeaner
Quote:

You've got myColour set to black and fully opaque - you're not clearing the back buffer to black are you (so it is drawing, it's just you can't tell?)

Change the back buffer clearing to something obvious like lime green just to test.



that did it! nice job! its there, but now its a wierd line. i think maybe i should check the camera angle now. thanks a lot!


that'll be the memcpy line i've posted about.

:D

Glad i've helped.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!