- GLuint TglTexManager::loadTexture(string name, GLuint format)
- {
- SDL_Surface* tex;
- GLint internalFormat;
- GLuint texID;
- string path;
- path = texturePath + name;
- tex = IMG_Load(path.c_str());
- if (!tex)
- {
- cerr << "!TglTexManager! -> Texture could not be loaded: " << path << endl;
- return 0;
- }
- glGenTextures(1,&texID);
- glBindTexture(GL_TEXTURE_2D,texID);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- if ( (format == GL_RGBA)||(format == GL_BGRA))
- internalFormat = 4;
- else internalFormat = 3;
- glTexImage2D( GL_TEXTURE_2D, 0, internalFormat,
- tex->w, tex->h, 0,
- format, GL_UNSIGNED_BYTE,
- tex->pixels);
- SDL_FreeSurface(tex);
- return texID;
- };