/** Creates a Procedural based texture * * @param x The width of the texture * @param y The height of the texture * @param numcomp The number of components in each pixel (3 = RGB, 4 = RGBA, etc) * @param proc The procedure which will create the texture * * @returns An ITexture object or NULL if the texture failed to create * * Operation: * -# Test how many textures exist, if zero, enable GL_TEXTURE_COORD_ARRAY * -# Create a new Procedural texture * -# Update the texture (this will load the image contents into the opengl texture object) * -# Store the texture pointer * -# Return the texture pointer */ ITexture * OGLGraphics::CreateTexture(int x, int y, int numcomp, ITexture::textureproc_t proc) { if(Textures.size() == 0) glEnableClientState(GL_TEXTURE_COORD_ARRAY); ITexture *texture = new OGLProceduralTexture(x,y,numcomp,proc); if(texture->UpdateTexture() >= 0){ Textures.push_back(texture); }else{ delete texture; texture = NULL; } return texture; }
/** Creates an Image based Texture * * @param image The filename containing the image to use as a texture * * @returns An ITexture object or NULL if texture failed to create * * Operation: * -# If the number of textures is zero, enable GL_TEXTURE_COORD_ARRAY * -# Loop through the current existing textures and attempt to find * a copy of the texture you are attempting to load * -# If a copy is found, return an ITexture pointer to that texture * -# If the texture is not found, Create a new ImageTexture object * -# Update the texture (this will load the image contents into the opengl texture object) * -# Store the texture pointer * -# Return the texture pointer */ ITexture * OGLGraphics::CreateTexture(std::string image) { ITexture *texture = NULL; for(unsigned int a=0;a<Textures.size();a++){ std::string test = Textures[a]->m_filename; if(image == test) texture = Textures[a]; } if(texture == NULL){ texture = new OGLImageTexture(image); if(texture->UpdateTexture() >= 0){ Textures.push_back(texture); }else{ delete texture; texture = NULL; } } return texture; }