Thread: DrawIndexedPrimitive() Failing (DX9)

  1. #16
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Could be but I thought all RGB's were DWORDs - it's just that the BMP format puts a 0 in what would be the alpha channel.

    So 24-bit color is still 32-bit except there are 8 bits that are not used. But since it's easy to do a rep stosd using DWORDs or 4 bytes, even though 8 bits are not used, they are still written to and/from disk/memory.

    Code:
    #define RGBA(r,g,b,a)  (DWORD)( (r<<24) + (g<<16) + (b<<8) + (a) )
    #define ARGB(r,g,b,a)  (DWORD)( (a<<24) +(r<<16) + (g<<8) + (b) )
    #define RGBX(r,g,b)  (DWORD) (r<<24) + (g<<16) + (b<<8) )
    
    #define RGB(r,g,b) RGBX(r,g,b)
    #define RGBH(r,g,b,h) (RGBA(r,g,b,h))
    #define HRGB(r,g,b,h) (ARGB(r,g,b,h))
    
    
    void FastCopy32(DWORD *Source,DWORD *Dest,DWORD Length)
    {
      asm {
        mov   esi,Source
        mov   edi,Dest
        mov   ecx,Length
        rep    movsd
        //To account for Length not being a factor of 4 - hanging bytes
        and   ecx,03h
        rep    movsb
      }
    }

    Something like that. So from the assembly version you can see that even though we call it 24-bit color, it's still using 32-bits of information. Which is why I thought instead of just discarding the 8 bits, and if you do not need alpha, then put your height in those 8 extra bits. This will give you heights from 0 to 255. But you can scale these later using fixed point arithmetic or simple bit shifting and this will give you a much larger range. Ranges from 0 to 65535 should be all you need to accurately represent terrians. 0 to 255 is a bit limited and sometimes the changes in heights are quite noticeable. So just expand the data type, scale the heights, and save this information in your height map in memory. But on disk there is no need to save an unsigned short to disk when you can pack the byte equivalent of the height into the RGB structure.

    Also remember that bitmaps are stored in order BGR, not RGB.
    Last edited by VirtualAce; 09-24-2005 at 03:57 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 09-23-2008, 03:32 AM
  2. pointer comparison failing
    By Bleech in forum C Programming
    Replies: 4
    Last Post: 08-11-2007, 06:33 PM
  3. CreateDevice failing
    By MadCow257 in forum Game Programming
    Replies: 6
    Last Post: 03-14-2006, 09:03 PM
  4. initializes all components of failing to false
    By romeoz in forum C++ Programming
    Replies: 21
    Last Post: 08-01-2003, 09:30 PM
  5. DX9 and Dev-C++
    By Ashes999 in forum Windows Programming
    Replies: 5
    Last Post: 06-10-2003, 12:19 AM