Z pomocą tutoriali i dokumentacji napisałem własną klasę do wczytania i wyświetlania obrazów.
Wydaje mi się że wczytanie działa dobrze gorzej jest z wyświetlaniem bo gdy w folderze z programem jest plik to pojawia się takie coś.
Click
Oto kod:
class Image
{
private:
ILuint ImgID;
ILuint WidthImage;
ILuint HeightImage;
public:
enum Data
{
IWidth,
IHeight,
IData,
};
ILubyte* DataImage;
Image();
int GetDataImage(char* Path, enum Data Image);
int LoadImage(char* Path);
void DisplayImage(int x, int y);
~Image();
};
Image::Image()
{
ilInit();
ImgID = NULL;
WidthImage = NULL;
HeightImage = NULL;
DataImage = NULL;
}
int Image::GetDataImage(char* Path, enum Data Image)
{
ilGenImages(1, &ImgID);
ilBindImage(ImgID);
ilLoadImage(Path);
if(ilGetError() != IL_NO_ERROR)return ilGetError();
WidthImage = ilGetInteger(IL_IMAGE_WIDTH);
HeightImage = ilGetInteger(IL_IMAGE_HEIGHT);
DataImage = ilGetData();
if(Image == 0)return WidthImage;
if(Image == 1)return HeightImage;
if(Image == 2)return *DataImage;
return 1;
}
int Image::LoadImage(char* Path)
{
ilGenImages(1, &ImgID);
ilBindImage(ImgID);
ilLoadImage(Path);
if(ilGetError() != IL_NO_ERROR)return ilGetError();
WidthImage = ilGetInteger(IL_IMAGE_WIDTH);
HeightImage = ilGetInteger(IL_IMAGE_HEIGHT);
DataImage = ilGetData();
glGenTextures( 1, & ImgID );
glBindTexture( GL_TEXTURE_2D, ImgID );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexImage2D( GL_TEXTURE_2D, 0, ilGetInteger( IL_IMAGE_BPP ), ilGetInteger( IL_IMAGE_WIDTH ),
ilGetInteger( IL_IMAGE_HEIGHT ), 0, ilGetInteger( IL_IMAGE_FORMAT ), GL_UNSIGNED_BYTE, ilGetData() );
return 1;
}
void Image::DisplayImage(int x, int y)
{
glColor3f( 0.0, 0.0, 0.0 );
glBegin( GL_QUADS );
glTexCoord3f( x, y, -0.0 );
glVertex3f( x, y, -0.0 );
glTexCoord3f( x + WidthImage, y, -0.0 );
glVertex3f( x + WidthImage, y, -0.0 );
glTexCoord3f( x + WidthImage, y + HeightImage, -0.0 );
glVertex3f( x + WidthImage, y + HeightImage, -0.0 );
glTexCoord3f( x, y + HeightImage, -0.0 );
glVertex3f( x, y + HeightImage, -0.0 );
glEnd();
}
Image::~Image()
{
ilBindImage(0);
ilDeleteImage(ImgID);
}
Dodałem "cudzysłowy" w trzeciej linijce (inaczej link nie działał) - msm