//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);
}
Textured polygon wont render
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
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]
you have diffuse color and texture coordinates in the wrong order. Try this
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]
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]
I remember a similar problem i had, and i solve it changing the FVF and the vertex declaration, try changing to this:
Really weird but it works for me.
Hope this help
If God with me, Who against me?
#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?
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.
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
Bad Monkey Productions
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
-dizzy
[edited by - yzzid on March 25, 2003 4:02:59 PM]
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]
Thought so to at first but since I have a camera I should be able to see the polygon from another perspective. Tried to disable culling but nothing happened :/ Well it´s back up on that horse for me I guess.
Bad Monkey Productions
Bad Monkey Productions
Hmm, it seems I get a converison warning at the creation of the vertices. If you compile the code you´ll notice this. I don´t understand why this happends. Any clues?
Bad Monkey Productions
Bad Monkey Productions
LOL! Got it now. I forgot to unlock the vert. buf
Thanks for the help anyways.
Bad Monkey Productions
Thanks for the help anyways.
Bad Monkey Productions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement