0
\$\begingroup\$

I was trying to implement a particle system using PointSprites. Draw calls return D3D_OK but I don't see any particle on the screen. I'm not using Vertex Buffer for the particles, but I use two vectors of vertices and I call the DrawPrimitiveUP function. This is my code:

            CreatePntVertices();

            pD3DD -> SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
            pD3DD -> SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
            pD3DD -> SetRenderState(D3DRS_DESTBLEND, D3DBLEND_ONE);

            pD3DD -> SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
            pD3DD -> SetRenderState(D3DRS_ZENABLE, FALSE);

            pD3DD -> SetRenderState(D3DRS_LIGHTING, FALSE);

            pD3DD -> SetFVF(FVF_PNTVERTEX);
            pD3DD -> SetTexture(0, pTex[TEX_POINT]);

            pD3DD -> SetRenderState(D3DRS_POINTSPRITEENABLE, TRUE);
            pD3DD -> SetRenderState(D3DRS_POINTSCALEENABLE, TRUE);

            pD3DD -> SetRenderState(D3DRS_POINTSCALE_A, 0.0f);
            pD3DD -> SetRenderState(D3DRS_POINTSCALE_B, 0.0f);
            pD3DD -> SetRenderState(D3DRS_POINTSCALE_C, 1.0f);

            pD3DD -> SetRenderState(D3DRS_POINTSIZE, 20.0f);
            pD3DD -> SetRenderState(D3DRS_POINTSIZE_MIN, 3.0f);
            pD3DD -> SetRenderState(D3DRS_POINTSIZE_MAX, 50.0f);

            D3DXMatrixIdentity(&mWorld);
            pD3DD -> SetTransform(D3DTS_WORLD, &mWorld);

            pD3DD -> DrawPrimitiveUP(D3DPT_POINTLIST, pntPlanets.size(), (PVOID)pntPlanets.data(), sizeof(PNTVERTEX));

            pD3DD -> SetRenderState(D3DRS_POINTSIZE, 40.0f);
            pD3DD -> SetRenderState(D3DRS_POINTSIZE_MIN, 9.0f);
            pD3DD -> SetRenderState(D3DRS_POINTSIZE_MAX, 70.0f);

            pD3DD -> DrawPrimitiveUP(D3DPT_POINTLIST, pntStars.size(), (PVOID)pntStars.data(), sizeof(PNTVERTEX));

            pD3DD -> SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);

            pD3DD -> SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
            pD3DD -> SetRenderState(D3DRS_POINTSPRITEENABLE, FALSE);
            pD3DD -> SetRenderState(D3DRS_POINTSCALEENABLE, FALSE);

CreatePntVertices() is a function that set the position of objects and their color into two vectors of PNTVERTEX (pntStars and pntPlanets). pTex is an array of textures. mWorld is a D3DXMATRIX. pD3DD is the Device. FVF_PNTVERTEX is set as (D3DFVF_XYZ | D3DFVF_DIFFUSE). I really don't know why it doesn't work, I tried everything to make it work. Maybe, should I use a dynamic vertex buffer instead?

\$\endgroup\$
3
  • \$\begingroup\$ Have you confirmed your hardware actually supports point-sprites? D3DCAPS9.MaxPointSize has to be something other than 1.0 or 0.0. See MSDN. \$\endgroup\$ Commented Feb 16, 2015 at 0:50
  • \$\begingroup\$ @ChuckWalbourn D3DCAPS9.MaxPointSize returned 8192... \$\endgroup\$
    – Ale
    Commented Feb 16, 2015 at 17:00
  • \$\begingroup\$ I compiled another program which used point-sprites, and it worked... so the problem shouldn't be the hardware, but something in the code which I may have forgotten. I'm not able to find out the problem. Could someone tell me which other parameters I have to set? Also I tried to use dynamic VB but the result is the same. I have to add that I draw other things (like spheres or quads) and I don't know if it changes anything if I put this code at the end or at the beginning. \$\endgroup\$
    – Ale
    Commented Feb 17, 2015 at 16:14

1 Answer 1

0
\$\begingroup\$

I found out the source of the problem. After days and days, I understood (at last) that with SetRenderState (in DirectX9), floats have to be converted into DWORDs in this way:

*((DWORD*)&f)

where f is the floating point. I already used this method for fog, but I forgot it and it took me other weeks to learn it again. I hope this answer will help other guys with the same problem!

\$\endgroup\$
2
  • 1
    \$\begingroup\$ I'm amazed you were able to compile your program, passing a float to a function that takes a DWORD. You didn't even get a warning for that? Additionally, the documentation clearly states that you must binary convert the float to a DWORD to pass the float value to SetRenderState(). Always remember to read the docs, and read your compiler output. Aiming for 0 warnings can be a good practice. \$\endgroup\$ Commented Feb 25, 2015 at 7:30
  • \$\begingroup\$ @PandaPajama No, I didn't receive any error! That was the real problem. If I got a message, probably I wouldn't lose so much time searching for the bug. I don't know why, but the program were compiled without warnings. I read the documentation, but I didn't find the statement (although I may have been more careful reading it). I found the problem comparing my program with another program which uses PointSprites. In fact, the difficulty was to find what was going wrong - It's relatively easy to fix a bug if you know what caused it ;) \$\endgroup\$
    – Ale
    Commented Feb 25, 2015 at 17:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .