DevIL - wyświetlanie obrazu.

0

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

0

Z pomoca jakiej dokumentacji?
http://www.opengl.org/sdk/docs/man2/xhtml/glTexCoord.xml

Slowem skrotu, jesli masz kwadrat 20x20, to i tak do glTexCoord podajesz wartosci 0-1.

Nawet masz jakis przyklad tego co chcesz zrobic: http://www.opengl.org.ru/docs/pg/0901.html

0

Trochę poprawiłem kod. Napisałem klasę i funkcję(jej będę używał), ładującą i wyświetlającą obraz.
Oto klasa:

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 );

	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() );
    //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
    //glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
	// ustalenie parametrów tekstury
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	// ustalenie trybu teksturowania
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);	
	// włączenie teksturowania
    return 1;
}
void Image::DisplayImage(int x, int y)
{
	glColor3f( 0.0, 0.0, 0.0 );

	glBegin( GL_QUADS );
	  //glTexCoord2f( x, y );
	  //glTexCoord2f( 0, 0 );
      glVertex2f( x, y );

	  //glTexCoord2f( x + WidthImage, y );
	  //glTexCoord2f( 0, 1 );
      glVertex2f( x + WidthImage, y );

      //glTexCoord2f( x + WidthImage, y + HeightImage );
	  //glTexCoord2f( 1, 1 );
      glVertex2f( x + WidthImage, y + HeightImage );

	  //glTexCoord2f( x, y + HeightImage );
	  //glTexCoord2f( 1, 0 );
      glVertex2f( x, y + HeightImage );
	glEnd();
}
Image::~Image()
{
	 ilBindImage(0);
     ilDeleteImage(ImgID);
}

Jednak powstaje coś takiego "Klasa.png" (w załączniku).

O to funkcja:

int DrawImage(char* Path, int x, int y)
{
	ilInit();
	ILuint ImgID;
	ILuint WidthImage = ilGetInteger(IL_IMAGE_WIDTH); 
	ILuint HeightImage = ilGetInteger(IL_IMAGE_HEIGHT);

	ilGenImages(1, &ImgID); 
	ilBindImage(ImgID);
	ilLoadImage(Path);

	if(ilGetError() != IL_NO_ERROR)return ilGetError();

	glGenTextures( 1, & ImgID );
    glBindTexture( GL_TEXTURE_2D, ImgID );

	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() );

	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
   	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	// ustalenie trybu teksturowania
	glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);

	glColor3f( 0.0, 0.0, 0.0 );

	glBegin( GL_QUADS );
	  //glTexCoord2f( x, y );
	  //glTexCoord2f( 0, 0 );
      glVertex2f( x, y );

	  //glTexCoord2f( x + WidthImage, y );
	  //glTexCoord2f( 0, 1 );
      glVertex2f( x + WidthImage, y );

      //glTexCoord2f( x + WidthImage, y + HeightImage );
	  //glTexCoord2f( 1, 1 );
      glVertex2f( x + WidthImage, y + HeightImage );

	  //glTexCoord2f( x, y + HeightImage );
	  //glTexCoord2f( 1, 0 );
      glVertex2f( x, y + HeightImage );
	glEnd();

	return 1;
}

Jednak powstaje takie coś "Funkcja.png".

Skąd różnica wielkości wczytanego obrazu i dlaczego ta figura z tyłu jest też żółta jak obraz?

0

Dla obrazów "ABC.bmp" i ABC.png" w załączniku dzieje się "Cos takiego.png" .
Może mi to ktoś wytłumaczyć? Obrazy wczytałem funkcją wyżej.
Ma ktoś pomysł dlaczego jest ta różnica w wielkości i kolor tego graniastosłupa jest taki sam jak wczytanego obrazu?

EDIT:
Nie mogłem dodać w załączniku "ABC.bmp" ale daje on ten sam efekt.

0

Nie wiem co mam nie tak z tymi teksturami więc może spróbuje innej biblioteki.

1 użytkowników online, w tym zalogowanych: 0, gości: 1