- To get your colors from the vertices, you need to set the renderstate D3DRS_DIFFUSEMATERIALSOURCE (or DIFFUSECOLORSOURCE, something along these lines) to D3DMCS_COLOR1 (or 2, one of them specifies "get the color from the vertex" and the other says "get the color from the material").
Alternatively, you can just disable the lighting before rendering your sprites. This''ll force d3d to take colors from your point-sprites (and I think the point-size works in SpacePirates, by the way).
- I''ve not been able to find why the texture doesn''t show up yet (haven''t inspected it enough). It''s loading correctly, though.
- Regarding smart COM pointers, here''s a blurb (the weird syntax is because this was written for a wiki):
[begin blurb]
== Smart COM pointers ==
Often, programmers do not manage the lifetime of COM objects properly. For example, one could forget to Release() an interface, or forgets to AddRef() an interface on copying, ...etc. This introduces MemoryLeaks.
Smart COM pointers greatly simplify the lifetime-management burden.
To make your life much easier, there are many smart COM pointers out there, that do the management jobs automatically. We''ll examine the CComPtr smart pointer, defined in atlbase.h - part of the ATL (Active Template Library). It comes with Visual C++, though I''m not sure if ATL is shipped with other compilers. In case you don''t have the ATL, and can''t download it (if it''s downloadable), you''ll have to find yourself a smart COM pointer (and there''s got to be lots of these around. You can even use a boost::shared_ptr with a custom deleter, or whatever it''s called).
CComPtr offers a lot of functionality, of which we''re interested in:
* It AddRef()''s the interface it holds when copied
* It Release()''s the interface it holds when destroyed, or assigned to NULL
Note that CComPtr hides the methods AddRef() and Release() of the interface pointer, because you''ll no longer need them. It forces you to use a replacement Release() instead, on the smart pointer itself.
To access the methods of CComPtr, you use the dot operator ''.'', and to access the interface methods you use the arrow operator ''->''.
So, the above code example would look like this with smart pointers:
class A{public: A( IDirect3D9 *pD3D ) { // Keep a copy of the d3d interface, ref count incremented automatically m_d3d = pD3D; } void DoSomething() { // Do something with the d3d interface UINT numAdapters = m_d3d->GetAdapterCount(); } void Destroy() { m_d3d.Release(); // m_d3d->Release() illegal, because Release() has been // been hidden by CComPtr }// No need for the destructor here. The default constructor generated by the compiler// will call CComPtr''s destructor, which in turn will release the interface// ~A()// {// Destroy();// } private: CComPtr m_d3d;};class B{public:// Same goes for B...};CComPtr d3d = Direct3DCreate9( D3D_SDK_VERSION );// CComPtr is automatically cast to IDirect3D9A objA( d3d );B objB( d3d );// Release the d3d interface// This only decrements the reference count - it doesn''t actually destroy the objectd3d.Release();// The following functions will work OKobjA.DoSomething();objB.DoAnotherThing();objB.Destroy(); // decrement ref countobjA.Destroy(); // decrement ref count, and destroy the object
I cannot stress enough the importance of smart COM pointers. In short, use them. I''ve forgotten about DirectX MemoryLeaks since I''ve started using smart COM pointers.
[/end blurb]
Muhammad Haggag
Bitwise account: MHaggag -