views:

253

answers:

1

This is still an outstanding issue.

I am trying to get a point sprites system workign render a sun in my world. I noticed another user asking a similar question (with the same code, presumably from my class :) ) but they were not able to complete this. My current code for this is as follows:

 float fPointSize = 10.0f,fPointScaleB = 100.0f;

IDirect3DDevice9 *m_Device = LudoRenderer::GetInstance()->GetDevice(); m_Device->SetRenderState(D3DRS_POINTSPRITEENABLE,true); m_Device->SetRenderState(D3DRS_POINTSCALEENABLE,true);

 m_Device->SetRenderState(D3DRS_POINTSIZE,
                                  *((DWORD*)&fPointSize));
    m_Device->SetRenderState(D3DRS_POINTSCALE_B,
                                  *((DWORD*)&fPointScaleB));

    m_Device->SetRenderState(D3DRS_ALPHABLENDENABLE,true);
    m_Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_ONE);
    m_Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE);


    std::wstring hardcoded = L"..\\Data\\sun.png";
 m_SunTexture = LudoTextureManager::GetInstance()->GetTextureData(hardcoded.c_str()).m_Texture;

  m_Device->SetTexture(0,m_SunTexture);
     m_Device->DrawPrimitive(D3DPT_POINTLIST,0,12);

I do not see my sun on the screen, and it seems to be doing the alpha blend on the rest of my world, rather than on any sun I'm trying to load. Could this be because of which devices I'm using? Any help would be greatly appreciated :)

+3  A: 

You don't actually seem to have a draw call in there. Have you missed posting some code, or is this perhaps your problem?

If you're missing the draw call, I would suggest the DrawPrimitiveUP() call is likely the one you want. You'll also need to set the stream format to match your vetex structure ( setFVF() ). Something along these lines:

#define D3DFVF_SUNVERTEX (D3DFVF_XYZ|D3DFVF_DIFFUSE)

struct SUNVERTEX
{
  float x,y,z;
  DWORD colour;
};

D3DVECTOR pos = { 0.f, 0.f, 0.f }; // Set this to the position you want
SUNVERTEX sunVert = { pos.x, pos.y, pos.z, D3DCOLOR_RGBA( 255, 255, 0, 255 ) };

IDirect3DDevice9& device = LudoRenderer::GetInstance()->GetDevice();
device->SetFVF( D3DFVF_SUNVERTEX );
device->DrawPrimitiveUP( D3DPT_POINTLIST, 1, sunVert, sizeof(SUNVERTEX) );

If you have time I'd strongly recommend reading the "Programming Guide" from the DirectX SDK documentation (you should have it installed). It's not much of a tutorial, but it does cover the basics of DirectX architecture.

Andy J Buchanan
This might be my problem! This isn't all that well documented.. The only resource I could find was http://www.two-kings.de/tutorials/dxgraphics/dxgraphics17.html
Mark
i have added the draw call from the tutorial linked to. still no dice.
Mark
Yes, but you haven't set the stream source ( or used the DrawPrimitiveUP varient ) or the vertex format.
Andy J Buchanan
Thanks for your edit. I appreciate your time. Could you possibly assist me with putting the correct data into the parameters for DrawPrimitiveUP? In the meantime, I will check out the recommended programming guide.
Mark
Answer expanded
Andy J Buchanan
Mucho thanks for the extended explanation. Only issue is sunVert in DrawPrimitiveUP is causing compiler errors, where it can't be converted to const void *?
Mark
Ok, just cast it then:device->DrawPrimitiveUP( D3DPT_POINTLIST, 1, (void*)sunVert, sizeof(SUNVERTEX) );
Andy J Buchanan
this was my hunch, but unfortunately yields the same compiler error. It can't seem to cast it. 'cannot convert from type SUNVERTEX to void *'. No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called.
Mark
Oh yeah, sunVert is not a pointer, DOH! Use the address-of operator:device->DrawPrimitiveUP( D3DPT_POINTLIST, 1, (void*)
Andy J Buchanan