Thread: DX surfaces or textures?

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    46

    DX surfaces or textures?

    Hi all,

    Here's my situation:

    I have a bitmap (background... map of europe) that's 1152 x 965. As such, some of the countries and bodies of water are greater that 256 x 256 in size.

    I'm trying to figure out a way to make a "highlighter" for when a user clicks on one country and scrolls over another. The country clicked on should change color, and the country moused over to should also change color.

    I need the background to still be visible underneath this, due to having text on it.

    I was thinking of using textures to accomplish this, by creating a bunch of bitmaps for the countries (which would be the highlight color), but the max (recommended) size of a texture is 256x256.... Should I just accept this (and scale the image when it comes to render time), or should I use a surface instead? (Is there any way to alpha blend surfaces?)

    Or... alternatively, am I being a total idiot when there's a much easier (and less memory intensive-- 256 x 256 x 32 bit = huge bitmaps!) way to do this?? :P

    thanks!

    -maxthecat

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    First of all you need to use a texture size of a power of 2. If you don't DirectX will still create one for you, this you are wasting texture space by not using the leftovers.

    Try it. Create a texture that is 125x123 and then retrieve the SurfaceDesc for it. It will be 128x128.

    Your problem can be solved by creating meshes for each country and setting the diffuse material color to the color of the country when you click on it. The click could be attained by ray picking or casting a ray into 3D space and seeing what it hits.

    For 2D, you would need to have alpha maps and/or diffuse maps for each country.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    Interesting... Yeah, it's a 2D app.... I've been blitting the background bitmap onto a surface (the entire image was never fully displayed), and I was planning on using textures to act as the highlighting....

    Alpha maps eh? How does that work? I couldn't find that mentioned in the SDK, or on these boards. Any links you have (or good books that you reccommend) would be more than appreiciated

  4. #4
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    After a bit more 'o research, the only thing I've found resembling 'alpha maps' is alpha blending... That wouldn't be a problem with this, except for the countries that are greater than 256 pixels in any direction.

    Do you think I should break up the countries into mulitple textures for ones that are bigger than 256px, or would it be better to simply live with the scaling that occurs when a texture is applied to a primitive that's bigger than 256 x 256?

    Also, with 75 countries, isn't having 18.75 MB (256 * 256 * 32 * 75 bits) worth of bitmaps just for highlighting a bit extreme?

  5. #5
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    The 256x256 limit is totally dependent on the card you have. Most modern cards support texture sizes of 1024x1024 and greater with no problem.

  6. #6
    60% Braindead
    Join Date
    Dec 2005
    Posts
    379
    Mmm bitmaps are going to be pritty big, 18.7megs is pritty big, but for 75 countries is pritty fair. Large countries should be broken into seperate peices. But what could be a better idea is break your whole map into 256x256 sections. Then just border the edges. Maybe not the easyest solution though.

    As for highliting, I have no idea :P.
    Code:
    Error W8057 C:\\Life.cpp: Invalid number of arguments in function run(Brain *)

  7. #7
    Registered User
    Join Date
    Dec 2001
    Posts
    46
    Interesting! Thanks for the help guys!

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Code:
    struct CountryVertex
    {
      D3DVECTOR3 Pos;
      D3DCOLOR Diffuse;
      D3DCOLOR Specular;
      float tu,tv;
     
      static const DWORD FVF;
      CountryVertex(void):Pos(D3DXVECTOR3(0.0f,0.0f,0.0f),Diffuse(0),Specular(0),tu(0.0f),tv(0.0f) {}
      CountryVertex(D3DXVECTOR3 _Pos,float u,float v):Pos(_Pos),tu(y),tv(v) {}
    };
      
    
    class Country
    {
      ID3DMESH9 *m_pMesh;
      D3DXVECTOR3 Pos;
      D3DMATERIAL9 m_pMaterial;
      
      public:
        Country(void):m_pMesh(NULL),Pos(&D3DXVECTOR3(0.0f,0.0f,0.0f)) {}
    
        void Create(IDirect3DDevice9 *pDevice);
        ...
    };
    Something like that would work for starters. Each country is a mesh of it's own and to change the color of it you simply change the material property of the mesh.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Textures
    By fighter92 in forum Game Programming
    Replies: 1
    Last Post: 03-21-2009, 10:57 AM
  2. loading textures from resources (dx8/9)
    By X PaYnE X in forum Game Programming
    Replies: 1
    Last Post: 12-25-2005, 04:44 PM
  3. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM
  4. Q3A textures
    By glUser3f in forum Game Programming
    Replies: 11
    Last Post: 09-04-2003, 03:40 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM