13 bool VART::Texture::notInitalized =
true;
14 bool VART::Texture::hasWhiteTexture =
false;
15 unsigned int VART::Texture::whiteTextureId = 0;
18 : hasTexture(false), textureId(0)
30 LoadFromFile(fileName);
35 this->operator=(texture);
39 cerr <<
"\aWarning: Texture::HasTextureLoad() is deprecated.\n";
45 textureId = texture.textureId;
46 hasTexture = texture.hasTexture;
61 ilGenImages(1, &ilTextName);
62 ilBindImage(ilTextName);
63 ilEnable(IL_ORIGIN_SET);
64 ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
65 ilLoadImage( fileName.c_str() );
66 ILenum error = ilGetError();
67 if (error != IL_NO_ERROR)
69 cerr <<
"Error while loading image file in Texture::LoadFromFile.\n"
70 <<
"ilLoadImage returned " << error <<
"\n";
73 unsigned int width = ilGetInteger(IL_IMAGE_WIDTH);
74 unsigned int height = ilGetInteger(IL_IMAGE_HEIGHT);
75 ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
76 ILubyte* imageData = ilGetData();
78 if (error == IL_NO_ERROR)
80 clog <<
"Image data from " << fileName <<
" loaded successfully.\n";
84 cerr <<
"Error while getting image data in Texture::LoadFromFile.\n"
85 <<
"Caught error: " << error <<
"\n";
89 #error No image handling library defined. Try compiling with -DIL_LIB.
97 glGenTextures(1, &textureId);
98 glBindTexture(GL_TEXTURE_2D, textureId);
99 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
100 glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
101 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);
102 assert(glGetError()==GL_NO_ERROR);
106 cerr <<
"Error binding texture in Texture::LoadFromFile.\n"
107 <<
"Texture file: '" << fileName <<
"'\n"
108 <<
"imageData: " << imageData <<
"\n";
112 #error No rendering library defined. Try compiling with -DVART_OGL.
117 ilDeleteImages(1, &ilTextName);
137 static bool textureIsEnabled =
false;
138 if (textureIsEnabled)
142 glBindTexture(GL_TEXTURE_2D, textureId);
147 glDisable(GL_TEXTURE_2D);
149 textureIsEnabled =
false;
156 glEnable(GL_TEXTURE_2D);
157 textureIsEnabled =
true;
158 glBindTexture(GL_TEXTURE_2D, textureId);
165 void VART::Texture::WhiteTexture()
167 if( VART::Texture::hasWhiteTexture )
170 unsigned char data[3]={255,255,255};
171 glGenTextures( 1, &whiteTextureId );
172 glBindTexture( GL_TEXTURE_2D, whiteTextureId );
173 glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR );
174 glTexParameteri( GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR );
175 glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, data );
176 VART::Texture::hasWhiteTexture=
true;
180 void VART::Texture::Initialize()
182 notInitalized =
false;
185 clog <<
"libDevIL Initialized.\n";
189 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
190 glBlendEquation(GL_FUNC_ADD);
192 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
193 clog <<
"OpenGL texture Initialized.\n";
bool DrawOGL() const
Sets the texture to draw with the next object.
Header file for V-ART class "Texture".
2D image to use as texture.
Texture & operator=(const Texture &texture)
Copies texture data.
Texture()
Creates an unitialized texture.
virtual ~Texture()
Destructor class.
bool HasTextureLoad() const
Indicates if a texture has been loaded previously.
bool LoadFromFile(const std::string &fileName)
Loads a texture from a file.