//Init texture with SDL surface void GLTexture::init( SDL_Surface *img, bool mipmap) { _image = img; _mipmap = mipmap; _textureID = TextureManagerS::instance()->addTexture( this); bind(); glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameteri( _target,GL_TEXTURE_MAG_FILTER,GL_LINEAR); if( mipmap) { #if 0 glTexParameteri(_target,GL_TEXTURE_MIN_FILTER,GL_NEAREST_MIPMAP_LINEAR); __gluBuild2DMipmaps( _target, GL_RGBA8, _image->w, _image->h, getGLTextureFormat(), GL_UNSIGNED_BYTE, _image->pixels); #else LOG_ERROR << "midmap needs work\n"; #endif } else { glTexParameteri( _target,GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexImage2D( _target, 0, GL_RGBA8, _image->w, _image->h, 0, getGLTextureFormat(), GL_UNSIGNED_BYTE, _image->pixels); } }
void GLTextureCubeMap::init( void) { _textureID = TextureManagerS::instance()->addTexture( this); bind(); // glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for( int i=0; i<6; i++) { SDL_Surface *image = _image[i]; GLenum target = cubeMapTarget[i]; if( _mipmap) { #if 0 __gluBuild2DMipmaps( target, GL_RGBA8, image->w, image->h, getGLTextureFormat(image), GL_UNSIGNED_BYTE, image->pixels); #else LOG_ERROR << "midmap needs work\n"; #endif } else { glTexImage2D( target, 0, GL_RGBA8, image->w, image->h, 0, getGLTextureFormat(image), GL_UNSIGNED_BYTE, image->pixels); } } if( _mipmap) { glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } else { glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } int mode = GL_NORMAL_MAP_ARB; //GL_REFLECTION_MAP_ARB; //GL_NORMAL_MAP_ARB glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, mode); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, mode); glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, mode); int wrap = GL_CLAMP; //GL_REPEAT; //GL_CLAMP; glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, wrap); glTexParameteri(GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, wrap); }
GLTexture::GLTexture(GLStateCacher *_statecacher, model::IImage *image) : StateCacher(_statecacher) , Size(image->getSize()) { glGenTextures(1, &TextureId); StateCacher->bindTexture(TextureId); setGLTextureState(); GLint format; GLint interFormat; GLint type; getGLTextureFormat(image, format, interFormat, type); glTexImage2D(GL_TEXTURE_2D, 0, interFormat, (GLsizei)Size.w, (GLsizei)Size.h, 0, format, type, (GLvoid *)image->getData()); }