Thread: Loading BMP's to be used as textures.

  1. #1
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669

    Loading BMP's to be used as textures.

    I'm using linux... how would I go about loading BMP's for textures in linux. I mean the actual loading part, not the texture mapping, binding etc. Are there any libraries for this? I tried openil but that didn't seem to install.

  2. #2
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    if you want to link to glaux, i think the function name is:

    auxdibimagload

    (dib = device independent bitmap)

    of course, if you're rendering with OpenGL

  3. #3
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669
    Thanks

  4. #4
    Or you can say screw BMP's large, bloated format and use an alternative format. Think about it, you have access to a million formats, thanks to the GIMP. For gaming, BMP has a lot of useless information.

  5. #5
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    I would suggest BMPs for beginners - once you learn more, however, try testing your own file format.
    Do not make direct eye contact with me.

  6. #6
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669
    I tried using the auxdibimageload function, in various cases and styles... However, it is undeffined in the glaux header files. Where is it?

  7. #7
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    auxDIBImageLoad(char*FileName);

    freaking cases

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    This is how I did it. Found most of the info from www.gamedev.net.

    Textures.h
    Code:
    #ifndef _TEXTURES_
    #define _TEXTURES_
    
    #include <ddraw.h>
    #include <d3d.h>
    #include "DXEngine.h"
    
    
    class BasicTexture
    {
      LPDIRECTDRAWSURFACE7 Surface;
      LPDIRECTDRAWSURFACE7 Texture;
      public:
        BasicTexture(void) {};
        ~BasicTexture(void);
        void LoadTexture(char * filename, LPDIRECT3DDEVICE7 D3DDevice, LPDIRECTDRAW7 DirectDraw);
        LPDIRECTDRAWSURFACE7 GetSurface(void) {return Surface;};
    };
    Textures.cpp
    Code:
    TileTexture::TileTexture(void) 
    {
      Width = 64;
      Height = 64;
    }
    
    HRESULT CALLBACK EnumTextures( LPDDPIXELFORMAT DDPixelFormat, LPVOID pDDDesiredPixelFormat )  
    {  
      if( DDPixelFormat->dwFlags & DDPF_ALPHAPIXELS && DDPixelFormat->dwRGBBitCount == 16 )  
      {  
        if( DDPixelFormat->dwRGBAlphaBitMask == 1 || 
    			DDPixelFormat->dwRGBAlphaBitMask == 0x8000 )  
          {  
              memcpy( pDDDesiredPixelFormat, DDPixelFormat, sizeof(DDPIXELFORMAT) );  
              return D3DENUMRET_CANCEL;  
          }  
      }  
      return D3DENUMRET_OK;  
    }
    
    
    void BasicTexture::LoadTexture(char * filename, LPDIRECT3DDEVICE7 D3DDevice, LPDIRECTDRAW7 DirectDraw) 
    {
    	
      DDPIXELFORMAT TexturePixelFormat;
    
      if (FAILED(D3DDevice->EnumTextureFormats(( LPD3DENUMPIXELFORMATSCALLBACK )EnumTextures, ( void* )&TexturePixelFormat))) 
      {
        exit(10);
      };
    
    
      DDSURFACEDESC2 Desc;  
      ZeroMemory( &Desc, sizeof( DDSURFACEDESC2 ));  
      Desc.dwSize = sizeof( Desc );  
      Desc.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS | DDSD_CKSRCBLT;  
      Desc.dwWidth = 64;  
      Desc.dwHeight = 64;  
      Desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;  
      Desc.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;  
      Desc.ddpfPixelFormat = TexturePixelFormat;
    
      Desc.ddckCKSrcBlt.dwColorSpaceHighValue = _RGB16BIT565(128,0,128);
      Desc.ddckCKSrcBlt.dwColorSpaceLowValue = _RGB16BIT565(128,0,128);
    	
      DirectDraw->CreateSurface( &Desc, &Surface, 0 );  
    
    	
      HBITMAP hBM;  
      BITMAP BM;  
      HDC hDCImage, hDC;  
      hBM = ( HBITMAP ) LoadImage(NULL, filename, IMAGE_BITMAP, 0, 0,LR_LOADFROMFILE | LR_CREATEDIBSECTION );
      if (hBM == NULL) 
      {
        exit(10);
      };
    	
      GetObject( hBM, sizeof( BM ), &BM );  
      hDCImage = CreateCompatibleDC( NULL );  
      SelectObject( hDCImage, hBM );  
    	
      if( SUCCEEDED( Surface->GetDC( &hDC )))  
      {  
        BitBlt( hDC, 0, 0, 64, 64, hDCImage, 0, 0, SRCCOPY );  
        Surface->ReleaseDC( hDC );  
      } else exit(10);
    		
      DeleteDC( hDCImage );  
      DeleteObject( hBM );
    }
    
    BasicTexture::~BasicTexture(void) 
    {
    
      Surface->Release();
      Texture->Release();
    }
    This sets the transparent color to bright purple and all textures are assumed to be 64x64 pixels. You can remove these constraints quite easily.
    Last edited by VirtualAce; 12-23-2003 at 01:39 AM.

  9. #9
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669
    Silvercord: I tried that set of cases... still undefined.

    Bubba: I'll see how this works.

  10. #10
    Student drdroid's Avatar
    Join Date
    Feb 2002
    Location
    Montreal, Quebec
    Posts
    669
    are there any other ways or a reason why auxdibimageload still remains undefined?

  11. #11
    Registered User grady's Avatar
    Join Date
    Oct 2003
    Posts
    27
    You can't use what bubba is using because he's using Window's API and Directx. You could google for bitmap header format and figure out how to open the file yourself.

    Since you are using linux, you have or can get GIMP which can edit .tga files. I would recommend switching to .tga. First off, the header is darn simple. Second, the targa file can store an 8 bit alpha channel.
    Last edited by grady; 12-23-2003 at 11:18 AM.

  12. #12
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well it uses Windows GDI and DirectX which you are not using. Perhaps I mis-posted or didn't read your post completely. It was very late at night when I posted.



Popular pages Recent additions subscribe to a feed

Similar Threads

  1. loading textures from resources (dx8/9)
    By X PaYnE X in forum Game Programming
    Replies: 1
    Last Post: 12-25-2005, 04:44 PM
  2. Loading textures to screen
    By mindofpoison in forum Game Programming
    Replies: 2
    Last Post: 11-30-2005, 03:03 PM
  3. OpenGL Again, Loading Textures onto Quads
    By Shamino in forum Game Programming
    Replies: 7
    Last Post: 05-07-2005, 08:14 PM
  4. OpenGL, loading BMP Textures?
    By Zeusbwr in forum Game Programming
    Replies: 12
    Last Post: 12-09-2004, 05:16 PM
  5. the effects of textures on my frame rate
    By DavidP in forum Game Programming
    Replies: 37
    Last Post: 10-03-2003, 11:24 AM