IDirect3DTexture9

Started by
13 comments, last by Evil Steve 18 years, 7 months ago
It WORKS :)))))) instead of D3DXCreateTexture() i puted CreateTexture(...,D3DUSAGE_DYNAMIC,...,D3DPOOL_DEFAULT,...) and it works.
Advertisement
i wish to control the color by time. Pntr in this case is rapresenting the color and is unsigned int, but my time is float, how can i convert float to unsigned int??
That depends on what you want to do. The reason ptr is an unsigned int (32-bit value) is because your pixel data is 32-bit (A8R8G8B8). So, the data at ptr is in the format 0xaarrggbb.
If you want your texture to change from black to red, and your time ranges from 0.0f to 1.0f, then you'd do something like:
float fTime; // your time in the range 0..1Pntr=(unsigned int *)Rc.pBits;// Calculate the colour to useDWORD dwIntensity = ((DWORD)fTime*255.0f);DWORD dwColour = dwIntensity << 16;// Fill the texturefor(int y=0; y<texture_height; ++y){   pRow = Pntr[y*Rc.Pitch]; // Get a pointer to the start of this row of texels   for(int x=0; x<texture_width; ++x)      *pRow++ = dwColour;}


However, if you're doing this every frame, you'd be far better using the texture stages to adjust your triangle colour, since it'll be far more efficient.
thx, theats what i meant.

DWORD dwColour = dwIntensity << 16;

what does this mean << 16; ??
Quote:Original post by ryt
thx, theats what i meant.

DWORD dwColour = dwIntensity << 16;

what does this mean << 16; ??

Because the colour is packed as 0xaarrggbb (D3DFMT_A8R8G8B8 means you have the bits in that order, it'll be different for other texture formats), you need to get the dwIntensity value (which is between 0 and 255, which is 0x00 -> 0xff) into the red bits. Because the red bits are 16 bits away from the right, you need to shift left by 16 bits. "<< 16" means "Shift left by 16 bits".
I don't mean to sound patronising, but it's fairly basic C/C++, and you should perhaps consider learning or going back and revising some of the more basic stuff before you move onto DirectX.

Edit: Actually, the D3DCOLOR_ARGB macro would be better to use in this case. Using it, you'd replace the line with:
DWORD dwColour = D3DCOLOR_ARGB(0,dwIntensity,0,0);
Which is much easier to read and understand. Obviously you can put other values (variables or constants) in for alpha, green and blue instead of the zeros.

This topic is closed to new replies.

Advertisement