include/textures.h

Go to the documentation of this file.
00001 /***************************************************************************
00002  *            textures.h
00003  *
00004  *  Thu Dec  1 17:46:28 2005
00005  *  Copyright  2005  Joe Venzon
00006  *  joe@venzon.net
00007  ****************************************************************************/
00008 
00009 /*
00010  *  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU General Public License for more details.
00019  *
00020  *  You should have received a copy of the GNU General Public License
00021  *  along with this program; if not, write to the Free Software
00022  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00023  */
00024  
00025 #ifndef _TEXTURES_H
00026 
00027 #include <stdio.h>
00028 #include <stdlib.h>
00029 #include <GL/gl.h>
00030 #include <GL/glu.h>
00031 #include <GL/glext.h>
00032 #include <SDL/SDL.h>
00033 #ifdef __APPLE__
00034 #include <SDL_image/SDL_image.h>
00035 #else
00036 #include <SDL/SDL_image.h>
00037 #endif
00038 #include <math.h>
00039 #include <string>
00040 #include <fstream>
00041 #include <iostream>
00042 
00043 #include <list>
00044 
00045 #include "utility.h"
00046 
00047 #include "globals.h"
00048 
00049 using namespace std;
00050 
00051 class TEXTURE
00052 {
00053 private:
00054         GLuint tex_id;
00055         bool loaded;
00056         
00057 public:
00058         TEXTURE() { file = ""; mipmap = loaded = false; tex_id = 0; w = h = 0; references = 0;}
00059         //TEXTURE( string filename, GLuint id ) { TEXTURE( filename, id, true ); }
00060         //TEXTURE( string filename, GLuint id, bool mip ) { file = filename; tex_id = id; mipmap = mip; loaded = true; }
00061         ~TEXTURE() { Unload(); }
00062         
00063         int references;
00064         int w, h;
00065         bool mipmap;
00066         string file;
00067         
00068         //void SetTexID(GLuint new_tex_id) { tex_id = new_tex_id; loaded=true;}
00069         //void Set(string filename, GLuint id, bool mip) { file = filename; tex_id = id; mipmap = mip; loaded = true; }
00070         //void Unload() {if( loaded ) {glDeleteTextures( 1, &tex_id );loaded=false;}}
00071         void Load();
00072         void Unload();
00073         void Activate();
00074 };
00075 
00076 class TEXTURE_HANDLE
00077 {
00078 private:
00079         TEXTURE * tex;
00080         
00081 public:
00082         TEXTURE_HANDLE() {tex = NULL;}
00083         TEXTURE_HANDLE(const TEXTURE_HANDLE & other);
00084         ~TEXTURE_HANDLE();
00085         
00086         bool Load( string new_tex_file ) { return Load( new_tex_file, true ); }
00087         bool Load( string new_tex_file, bool mipmap ) { int w, h; return Load( new_tex_file, mipmap, w, h ); }
00088         bool Load( string new_tex_file, bool mipmap, int &w, int &h );
00089         
00090         void Unload();
00091         void Activate();
00092         
00093         TEXTURE_HANDLE & CopyFrom(const TEXTURE_HANDLE & other);
00094         TEXTURE_HANDLE & operator=(const TEXTURE_HANDLE & other) {return CopyFrom(other);}
00095 };
00096 
00097 class TEXTURES
00098 {
00099 private:
00100         list <TEXTURE> textures;
00101 
00102         TEXTURE * FindTexture(string texname);
00103         
00104 public:
00105         //TEXTURES() { }
00106         //~TEXTURES() {}
00107         //void DeleteAll();
00108         //void Delete( GLuint tex_id );
00109         //void Delete( string file );
00110         
00111         /*GLuint Load( string new_tex_file ) { return Load( new_tex_file, true ); }
00112         GLuint Load( string new_tex_file, bool mipmap ) { int w, h; return Load( new_tex_file, mipmap, w, h ); }
00113         GLuint Load( string new_tex_file, bool mipmap, int &w, int &h );*/
00114         
00115         //GLuint Load( string new_tex_file ) { return Load( new_tex_file, true ); }
00116         //GLuint Load( string new_tex_file, bool mipmap ) { int w, h; return Load( new_tex_file, mipmap, w, h ); }
00117         TEXTURE * LoadTexture( string new_tex_file, bool mipmap, int &w, int &h );
00118         void UnloadTexture(TEXTURE * textodel);
00119         
00120         void ReloadAll();
00121 };
00122 
00123 #define _TEXTURES_H
00124 #endif /* _TEXTURES_H */

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6