Archived

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

Textured polygon wont render

This topic is 5375 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 have a class that´s supposed to handle all particle objects in my little engine but at the moment they refuse to render. This is the code
    
//Handles particles

#include<d3d9.h>
#include<d3dx9.h>

#define CUSTOMVERTEX_FVF (D3DFVF_XYZ|D3DFVF_TEX1|D3DFVF_DIFFUSE)

struct CUSTOMVERTEX
{
	float fX,fY,fZ;
	float fU,fV;
	D3DCOLOR color;
};

class cParticle
{
public:
	bool SetupPolygon(LPDIRECT3DDEVICE9);
	void SetupMovement(LPDIRECT3DDEVICE9);
	void RenderParticle(LPDIRECT3DDEVICE9);
private:
	LPDIRECT3DVERTEXBUFFER9 m_iD3DVertBuf; //Vertex buffer for particle polygon

	LPDIRECT3DTEXTURE9 m_iParticleTexture; //Particle

};

bool cParticle::SetupPolygon(LPDIRECT3DDEVICE9 lpD3DDev9)
{

	CUSTOMVERTEX sVertices[4] =
	{
		{0.0f,50.0f, 0.0f,0.0f,0.0f,D3DCOLOR_XRGB(0,255,0)},
		{0.0f,0.0f,  0.0f,0.0f,1.0f,D3DCOLOR_XRGB(0,255,0)},
		{50.0f,50.0f,0.0f,1.0f,0.0f,D3DCOLOR_XRGB(0,255,0)},
		{50.0f,0.0f, 0.0f,1.0f,1.0f,D3DCOLOR_XRGB(0,255,0)}
	};

	if(FAILED(lpD3DDev9->CreateVertexBuffer(sizeof(CUSTOMVERTEX)*4,
		0,CUSTOMVERTEX_FVF,D3DPOOL_DEFAULT,&m_iD3DVertBuf,NULL)))
	{
		MessageBox(NULL,"Failed to create vertexbuffer", "Error", MB_OK|MB_ICONSTOP);
		return false;
	}
	
	VOID *pPtr;
	if(FAILED(m_iD3DVertBuf->Lock(0,sizeof(sVertices),(VOID**)&pPtr,0)))
	{
		MessageBox(NULL,"Failed to lock vertexbuffer", "Error", MB_OK|MB_ICONSTOP);
		return false;
	}

	memcpy(pPtr,sVertices, sizeof(sVertices));

	//Create the texture

	if(FAILED(D3DXCreateTextureFromFile(lpD3DDev9 ,"particle.bmp", &m_iParticleTexture)))
	{
		MessageBox(NULL,"Failed to create texture from file", "Error", MB_OK|MB_ICONSTOP);
		return false;
	}

	return true;
}

void cParticle::SetupMovement(LPDIRECT3DDEVICE9 lpD3DDev9)
{
	D3DXMATRIX matWorld;
	D3DXMatrixIdentity(&matWorld);
	lpD3DDev9->SetTransform(D3DTS_WORLD, &matWorld);
}

void cParticle::RenderParticle(LPDIRECT3DDEVICE9 lpD3DDev9)
{
	lpD3DDev9->SetStreamSource(0, m_iD3DVertBuf, 0, sizeof(CUSTOMVERTEX));
	lpD3DDev9->SetFVF(CUSTOMVERTEX_FVF);
	lpD3DDev9->SetTexture(0, m_iParticleTexture);
	lpD3DDev9->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
	
}
  
It seems to load the texture and all ok and I guess there is something really simple I´ve overlooked. Any help would be greatly appreciated.
Bad Monkey Productions [edited by - shakazed on March 25, 2003 1:29:54 PM]

Share this post


Link to post
Share on other sites
you have diffuse color and texture coordinates in the wrong order. Try this


struct CUSTOMVERTEX
{
float fX,fY,fZ;
D3DCOLOR color;
float fU,fV;
};


Look up vertex format in the DirectX SDK docs and you will see the order that the elements need to be in.

-dizzy

[edited by - yzzid on March 25, 2003 1:47:17 PM]

Share this post


Link to post
Share on other sites
I remember a similar problem i had, and i solve it changing the FVF and the vertex declaration, try changing to this:


  
#define CUSTOMVERTEX_FVF (D3DFVF_XYZ|D3DFVF_DIFFUSE|D3DFVF_TEX1)struct CUSTOMVERTEX
{
float fX,fY,fZ;
D3DCOLOR color;
float fU,fV;
};


Really weird but it works for me.

Hope this help

If God with me, Who against me?

Share this post


Link to post
Share on other sites
quote:
Really weird but it works for me.

With the fixed-function pipeline, there are certain limitations on the order of vertex data. You can read about that in the docs (8.1): DirectX Graphics->Programmers'' guide->Using Direct3D->Vertex Data->Fixed function vertex and pixel processing->Vertex formats.

Share this post


Link to post
Share on other sites
Thanks for the tip, but unfortunatly it still wont render. What I´m doing is that I first render a .x model which rotates around the y axis, then I try to load and render a particle. If you have the time I´ve uploaded the entire project to my website. Just follow the link in my sign. It´s under the files section "Zulu Engine"




Bad Monkey Productions

Share this post


Link to post
Share on other sites
I believe D3D uses clockwise winding order. It looks like you are drawing your vertices in counter-clockwise order. So what you are actually drawing is the backface of the polygon which isn't displayed.
You should be able to quickly test this by setting the following state after you set up your device

pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);


-dizzy

[edited by - yzzid on March 25, 2003 4:02:59 PM]

Share this post


Link to post
Share on other sites