Texture.h

Go to the documentation of this file.
00001 /* -*- Mode: CC; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 5 -*- */
00002 
00003 /*
00004  *   The Texture class contains methods for loading textures from disk and 
00005  *   binding textures in OpenGL. The class also provides a mechanism for
00006  *   mapping textures to names (strings) for easy reference.
00007  */
00008  
00009 /*
00010 -----BEGIN PGP SIGNED MESSAGE-----
00011 Hash: SHA1
00012 
00013 Created by Daniel Aarno on Tue Mar 11 2003.
00014 Copyright (c) 2004 by Daniel Aarno - <macbishop@users.sf.net>
00015 M. Sc. in Electrical Engineering - http://www.e.kth.se/~e98_aar
00016 
00017 All Rights Reserved
00018 ATTRIBUTION ASSURANCE LICENSE (adapted from the original BSD license)
00019 Redistribution and use in source and binary forms, with or without
00020 modification, are permitted provided that the conditions below are met.
00021 These conditions require a modest attribution to  (the
00022 "Author"), who hopes that its promotional value may help justify the
00023 thousands of dollars in otherwise billable time invested in writing
00024 this and other freely available, open-source software.
00025 
00026 1. Redistributions of source code, in whole or part and with or without
00027 modification (the "Code"), must prominently display this GPG-signed
00028 text in verifiable form.
00029 2. Redistributions of the Code in binary form must be accompanied by
00030 this GPG-signed text in any documentation and, each time the resulting
00031 executable program or a program dependent thereon is launched, a
00032 prominent display (e.g., splash screen or banner text) of the Author's
00033 attribution information, which includes:
00034 (a) Name ("Daniel Aarno"),
00035 (b) Professional identification ("M. Sc. in Electrical Engineering"), and
00036 (c) URL ("http://www.e.kth.se/~e98_aar").
00037 3. Neither the name nor any trademark of the Author may be used to
00038 endorse or promote products derived from this software without specific
00039 prior written permission.
00040 4. Users are entirely responsible, to the exclusion of the Author and
00041 any other persons, for compliance with (1) regulations set by owners or
00042 administrators of employed equipment, (2) licensing terms of any other
00043 software, and (3) local regulations regarding use, including those
00044 regarding import, export, and use of encryption software.
00045 
00046 THIS FREE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND
00047 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00048 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
00049 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
00050 EVENT SHALL THE AUTHOR OR ANY CONTRIBUTOR BE LIABLE FOR
00051 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00052 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00053 EFFECTS OF UNAUTHORIZED OR MALICIOUS NETWORK ACCESS;
00054 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00055 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00056 AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00057 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00058 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
00059 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00060 -----BEGIN PGP SIGNATURE-----
00061 Version: GnuPG v1.2.4 (GNU/Linux)
00062 
00063 iD8DBQFB+7fLi6ECThHTSIkRAgkHAKCMWiHVfcdkw4/MXn7WWPSi0+a8YgCfX7YS
00064 EEoRDC0I5wLQ0QsnNe9/9I4=
00065 =SOFw
00066 -----END PGP SIGNATURE-----
00067 */
00068 
00069 #ifndef _TEXTURE_
00070 #define _TEXTURE_
00071 
00072 #if defined(__APPLE__) || defined(MACOSX)
00073 #ifndef OPENGL_IN_PREFIX_HEADER
00074 #include <OpenGL/gl.h>
00075 #endif
00076 #else
00077 #include <GL/gl.h>
00078 #endif
00079 
00080 #include <tiffio.h>
00081 #include <string>
00082 #include <map>
00083 
00084 typedef std::map< std::string, int, std::less<std::string> > IntNameMap;
00085 
00093 class ImageHandle
00094 {
00095 friend class Texture;
00096 
00097 protected:
00098      char* data;
00099      short width, height;
00100      size_t blockSize;
00101 
00102 public:
00103      ImageHandle() : data(NULL), width(0), height(0) {}
00104      ~ImageHandle() { if(data) delete[] data; }
00105 
00113      void CopyData(char* dest);
00114      
00115      //Query functions
00117      short GetWidth() { return width; }
00119      short GetHeight() { return height; }
00121      short GetBlockSize() { return blockSize; }
00122 };
00123 
00137 class Texture
00138 {
00139 protected:
00140      static IntNameMap textureMap;
00141           
00142 public:
00154      static int LoadTIFFImage(ImageHandle& image, const char path[]);
00155 
00168      static int LoadAndBindTexture(GLuint *tex, const char path[]);
00169 
00170 
00185      static int LoadAndBindTexture(GLuint *tex, 
00186                                    const char path[], 
00187                                    GLuint mode);
00188 
00202      static int LoadTextureForName(const char name[], const char path[]);
00203 
00212      static int GetTextureByName(const char name[]);
00213 
00219      static void FreeTextureForName(const char name[]);
00220 };
00221 
00222 #endif //_TEXTURE_

Generated on Sun Mar 11 15:33:24 2007 for MetalWarriors by  doxygen 1.4.7