Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

pge::TextureFactory Class Reference

#include <TextureFactory.h>


Static Public Member Functions

TexturecreateTexture2D (const std::string &filename, const std::string &name, bool mipmap)
TexturecreateTexture2D (const std::string &filename, const std::string &name, bool mipmap, bool alpha, int ar, int ag, int ab, unsigned int minFilter, unsigned int magFilter, unsigned int wrapS, unsigned int wrapT)
TexturecreateTexture2D (unsigned char *image, const std::string &name, int width, int height, int bits, Image::ImageType type, bool mipmap, bool alpha, unsigned int minFilter, unsigned int magFilter, unsigned int wrapS, unsigned int wrapT)
unsigned int createCubemapTexture (const std::string &base)


Member Function Documentation

unsigned int pge::TextureFactory::createCubemapTexture const std::string &  base  )  [static]
 

Definition at line 133 of file TextureFactory.cpp.

References pge::Image::getWidth(), and pge::Image::isLoaded().

00133                                                                                {
00134                 //
00135                 // Variables
00136                 //
00137                 int i;
00138                 std::string files[6];
00139                 Image *images[6];
00140                 unsigned int cubeTargets[6];
00141                 //Texture *texture = NULL;
00142                 unsigned int textureDescriptor;
00143                 int width = 0;
00144                 int height = 0;
00145 
00146 
00147                 //images = new Image*[6];
00148 
00149                 files[0] = base + "_back.jpg";
00150                 files[1] = base + "_front.jpg";
00151                 files[2] = base + "_left.jpg";
00152                 files[3] = base + "_right.jpg";
00153                 files[4] = base + "_bottom.jpg";
00154                 files[5] = base + "_top.jpg";
00155 
00156                 cubeTargets[0] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
00157                 cubeTargets[1] = GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
00158                 cubeTargets[2] = GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
00159                 cubeTargets[3] = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
00160                 cubeTargets[4] = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
00161                 cubeTargets[5] = GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
00162 
00163                 // Load 6 cubemap images.
00164                 for(i = 0; i < 6; i++) {
00165                         images[i] = new Image(files[i]);
00166                         if(!images[i]->isLoaded()) {
00167                                 // TODO: here is a memory leak, delete all loaded images first.
00168                                 return 0;
00169                         }
00170                 }
00171 
00172                 // Enable cubemapping and create the opengl texture descriptor.
00173                 glEnable(GL_TEXTURE_CUBE_MAP);
00174                 glGenTextures(1, &textureDescriptor);
00175                 glBindTexture(GL_TEXTURE_CUBE_MAP, textureDescriptor);
00176 
00177                 // Set some parameters.
00178                 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
00179                 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
00180 
00181                 // Create textures.
00182                 for(i = 0; i < 6; i++) {
00183                         width = images[i]->getWidth();
00184                         height = images[i]->getHeight();
00185 
00186                         if(images[i]->getType() == Image::RGBA) {
00187                                 glTexImage2D(cubeTargets[i], 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, images[i]->getImage());
00188                         } else if(images[i]->getType() == Image::RGB) {
00189                                 glTexImage2D(cubeTargets[i], 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, images[i]->getImage());
00190                         }
00191                 }
00192                 glDisable(GL_TEXTURE_CUBE_MAP);
00193 
00194                 return textureDescriptor;
00195         }

Here is the call graph for this function:

Texture * pge::TextureFactory::createTexture2D unsigned char *  image,
const std::string &  name,
int  width,
int  height,
int  bits,
Image::ImageType  type,
bool  mipmap,
bool  alpha,
unsigned int  minFilter,
unsigned int  magFilter,
unsigned int  wrapS,
unsigned int  wrapT
[static]
 

Definition at line 92 of file TextureFactory.cpp.

References pge::Texture::createTexture2D(), pge::Image::isLoaded(), and pge::Texture::setAlphaBlending().

00095                                                                                 {
00096                         //
00097                         // Variables
00098                         //
00099                         Image *img;
00100                         Texture *texture;
00101 
00102 
00103                         // Create the image
00104                         img = new Image(image, width, height, bits, type, alpha);
00105                         if(!img->isLoaded()) {
00106                                 // TODO
00107                                 printf("Error\n");
00108                                 return NULL;
00109                         }
00110 
00111                         // Create the texture
00112                         texture = new Texture(img, name);
00113 
00114                         // Create the OpenGL stuff
00115                         texture->createTexture2D(mipmap, minFilter, magFilter, wrapS, wrapT);
00116 
00117                         texture->setAlphaBlending(alpha);
00118 
00119                         // Now delete the image data
00120                         delete img;
00121                         img = NULL;
00122 
00123                         // Return created texture
00124                         return texture;  
00125         }

Here is the call graph for this function:

Texture * pge::TextureFactory::createTexture2D const std::string &  filename,
const std::string &  name,
bool  mipmap,
bool  alpha,
int  ar,
int  ag,
int  ab,
unsigned int  minFilter,
unsigned int  magFilter,
unsigned int  wrapS,
unsigned int  wrapT
[static]
 

Definition at line 57 of file TextureFactory.cpp.

References pge::Texture::createTexture2D(), pge::Image::isLoaded(), and pge::Texture::setAlphaBlending().

00059                                                                                {
00060                         //
00061                         // Variables
00062                         //
00063                         Image *image;
00064                         Texture *texture;
00065 
00066 
00067                         // Create the image.
00068                         image = new Image(filename, alpha, ar, ag, ab);
00069                         if(!image->isLoaded()) {
00070                                 printf("ERROR: [%s] Error loading image %s.\n", __FILE__, filename.c_str());
00071                                 return NULL;
00072                         }
00073 
00074                         // Create the texture.
00075                         texture = new Texture(image, name);
00076 
00077                         // Create the OpenGL stuff
00078                         texture->createTexture2D(mipmap, minFilter, magFilter, wrapS, wrapT);
00079 
00080                         texture->setAlphaBlending(alpha);
00081 
00082                         // Return created texture.
00083                         return texture;
00084         }

Here is the call graph for this function:

Texture * pge::TextureFactory::createTexture2D const std::string &  filename,
const std::string &  name,
bool  mipmap
[static]
 

Definition at line 17 of file TextureFactory.cpp.

References pge::Texture::createTexture2D(), pge::Image::isLoaded(), pge::Texture::setAlphaBlending(), TEXTURE_MAGFILTER, TEXTURE_MINFILTER, TEXTURE_MINFILTER_MIPMAP, TEXTURE_WRAPS, and TEXTURE_WRAPT.

00017                                                                                                               {
00018                 //
00019                 // Variables
00020                 //
00021                 Image *image;
00022                 Texture *texture;
00023 
00024 
00025                 // Create the image.
00026                 image = new Image(filename, false);
00027                 if(!image->isLoaded()) {
00028                         // TODO: log message
00029                         printf("Error loading image %s.\n", filename.c_str());
00030                         return NULL;
00031                 }
00032 
00033                 // Create the texture.
00034                 texture = new Texture(image, name);
00035 
00036                 // Create the OpenGL stuff
00037                 if(mipmap) {
00038                         texture->createTexture2D(mipmap, TEXTURE_MINFILTER_MIPMAP, TEXTURE_MAGFILTER,
00039                                 TEXTURE_WRAPS, TEXTURE_WRAPT);
00040                 } else {
00041                         texture->createTexture2D(mipmap, TEXTURE_MINFILTER, TEXTURE_MAGFILTER,
00042                                 TEXTURE_WRAPS, TEXTURE_WRAPT);
00043                 }
00044 
00045                 texture->setAlphaBlending(false);
00046 
00047                 // Return created texture.
00048                 return texture;
00049         }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Mon Oct 16 12:09:48 2006 for Phobosengine by doxygen 1.3.4