DevIL - błąd

0

Przykładowa klasa z internetu wczytująca kod:

class Sprite
{
public:
    ILuint ImageName;
    ILuint texture;
    ILubyte * Data;
    ILenum Error;
    int W;
    int H;
    bool Load( char * sciezka )
    {
        ilGenImages( 1, & ImageName );
        ilBindImage( ImageName );
        ilLoadImage( sciezka );
        Error = ilGetError();
        if( Error != IL_NO_ERROR ) return false;
       
        W = ilGetInteger( IL_IMAGE_WIDTH );
        H = ilGetInteger( IL_IMAGE_HEIGHT );
        Data = ilGetData();
        if( !ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE ) ) return false;
       
        glGenTextures( 1, & ImageName );
        glBindTexture( GL_TEXTURE_2D, ImageName );
        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 ), W, H, 0, ilGetInteger( IL_IMAGE_FORMAT ), GL_UNSIGNED_BYTE, ilGetData() );
        //ilDeleteImages(1, &ImageName);
        return true;
    }
    void Free()
    {
        ilDeleteImages( 1, & ImageName );
    }
    int GetW()
    {
        ilBindImage( ImageName );
        return ilGetInteger( IL_IMAGE_WIDTH );
    }
    int GetH()
    {
        ilBindImage( ImageName );
        return ilGetInteger( IL_IMAGE_HEIGHT );
    }
    void Draw( int X, int Y, float A )
    {
        glBindTexture( GL_TEXTURE_2D, texture );
        glColor4f( 1.0, 1.0, 1.0, A );
        glBegin( GL_POLYGON );
        glTexCoord2f( 0.0, 0.0 );
        glVertex2i( X, Y );
        glTexCoord2f( 1.0, 0.0 );
        glVertex2i( X + W, Y );
        glTexCoord2f( 1.0, 1.0 );
        glVertex2i( X + W, Y + H );
        glTexCoord2f( 0.0, 1.0 );
        glVertex2i( X, Y + H );
        glEnd();
    }
};

Wywoływana tak (cała funkcja Display):

void Display()
{
	// Tekturowanie
    //tekstura();
	Sprite Spr;

	// kolor tła - zawartość bufora koloru
    glClearColor( 0.0, 1.0, 1.0, 1.0 );
   
    // czyszczenie bufora koloru
    glClear( GL_COLOR_BUFFER_BIT );
   
    // wybór macierzy modelowania
    glMatrixMode( GL_MODELVIEW );
   
    // macierz modelowania = macierz jednostkowa
    glLoadIdentity();
   
    // ustawienie obserwatora
    gluLookAt( eyex, eyey, eyez, centerx, centery, centerz, 0, 1, 0 );
   
    // kolor krawędzi sześcianu
    glColor3f( 0.0, 0.0, 0.0 );
   
    // początek definicji krawędzi sześcianu
    glBegin( GL_LINES );
   
    // wspólrzędne kolejnych krawędzi sześcianu
    glVertex3f( 1.0, 1.0, 1.0 );
    glVertex3f( 1.0, - 1.0, 1.0 );
   
    glVertex3f( 1.0, - 1.0, 1.0 );
    glVertex3f( 1.0, - 1.0, - 1.0 );
   
    glVertex3f( 1.0, - 1.0, - 1.0 );
    glVertex3f( 1.0, 1.0, - 1.0 );
   
    glVertex3f( 1.0, 1.0, - 1.0 );
    glVertex3f( 1.0, 1.0, 1.0 );
   
    glVertex3f( - 1.0, 1.0, 1.0 );
    glVertex3f( - 1.0, - 1.0, 1.0 );
   
    glVertex3f( - 1.0, - 1.0, 1.0 );
    glVertex3f( - 1.0, - 1.0, - 1.0 );
   
    glVertex3f( - 1.0, - 1.0, - 1.0 );
    glVertex3f( - 1.0, 1.0, - 1.0 );
   
    glVertex3f( - 1.0, 1.0, - 1.0 );
    glVertex3f( - 1.0, 1.0, 1.0 );
   
    glVertex3f( 1.0, 1.0, 1.0 );
    glVertex3f( - 1.0, 1.0, 1.0 );
   
    glVertex3f( 1.0, - 1.0, 1.0 );
    glVertex3f( - 1.0, - 1.0, 1.0 );
   
    glVertex3f( 1.0, - 1.0, - 1.0 );
    glVertex3f( - 1.0, - 1.0, - 1.0 );
   
    glVertex3f( 1.0, 1.0, - 1.0 );
    glVertex3f( - 1.0, 1.0, - 1.0 );
   
    // koniec definicji prymitywu
    glEnd();

	//Prism();

    // Zapisz macierzy rzutowania
    glMatrixMode (GL_PROJECTION);
    glPushMatrix ();
   
    // wybór macierzy modelowania
    //glMatrixMode( GL_MODELVIEW );
   //glMatrixMode(GL_TEXTURE);
    // macierz modelowania = macierz jednostkowa
    //glLoadIdentity();
    // Przełączenie do projekcji ortograficznej
	//glViewport(0,0,width,height);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	if (width<=height) glOrtho(-width,width,-height*(width/height),height*(width/height),-1000,1000);
	else glOrtho(-1000*(width/height),1000*(width/height),-1000,1000,-1000,1000);

	// obrócenie sceny o 40 stopni w osi X i Y
	//glRotated(40, 1.0, 1.0, 0.0);
	/*
	glBegin(GL_QUAD_STRIP);
		// pierwszy czworokąt
		glTexCoord2i(0,0);
		glVertex3i(-600,-300,-600);
		glTexCoord2i(0,2);
		glVertex3i(-600, 300,-600);
		glTexCoord2i(4,0);
		glVertex3i( 600,-300,-600);
		glTexCoord2i(4,2);
		glVertex3i( 600, 300,-600);
		// drugi czworokąt
		glTexCoord2i(0,0);
		glVertex3i( 60,-30, 60);
		glTexCoord2i(0,2);
		glVertex3i( 60, 30, 60);
		// trzeci czworokąt
		glTexCoord2i(4,0);
		glVertex3i(-60,-30, 60);
		glTexCoord2i(4,2);
		glVertex3i(-60, 30, 60);
		// czwarty czworokąt
		glTexCoord2i(0,0);
		glVertex3i(-60,-30,-60);
		glTexCoord2i(0,2);
		glVertex3i(-60, 30,-60);
		
	glEnd();
	*/
	//Spr.Load( "DevIL.jpg" );

    // Przy rysowaniu:
    Spr.Draw( 1, 1, 1.0 );
    
    // Powrót do trybu macierzy ModelView
    glMatrixMode (GL_MODELVIEW);

   // Powrót starego prespective macierzy rzutowania
   glMatrixMode(GL_PROJECTION);
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);

    // skierowanie poleceń do wykonania
    glFlush();
   
    // zamiana buforów koloru
    glutSwapBuffers();
}

Funkcja rysująca działa (rysuje na biało) i funkcja Free() a nie działa funkcja ładująca pliki graficzne.

1>------ Build started: Project: OpenGL, Configuration: Debug Win32 ------
1> Main.cpp
1> LINK : C:\Users\Documents\Visual Studio 2010\Projects\OpenGL\Debug\OpenGL.exe not found or not built by the last incremental link; performing full link
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilConvertImage@8 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGetData@0 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGetInteger@4 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGetError@0 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilLoadImage@4 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilBindImage@4 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>Main.obj : error LNK2019: unresolved external symbol __imp__ilGenImages@8 referenced in function "public: bool __thiscall Sprite::Load(char *)" (?Load@Sprite@@QAE_NPAD@Z)
1>C:\Users\Documents\Visual Studio 2010\Projects\OpenGL\Debug\OpenGL.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Nie wiem czy to różnica ale pobrałem pakiet (tej biblioteki) 64bit.

0

1.Na pewno poprawnie linkujesz wszystko?
2.Może projekt ma ustawione 32-bity or something...

0

W opcjach projektu zalinkowałem plik DevIL.dll zamiast DevIL.lib i jest tylko ten błąd.

1>------ Build started: Project: OpenGL, Configuration: Debug Win32 ------
1> Main.cpp
1>DevIL.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2F0
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

0

pobrałem pakiet (tej biblioteki) 64bit.

Configuration: Debug Win32

WTF?!

0

Przy tej funkcji wywala mi program nie wiem czemu.

bool Load( char * sciezka )
    {
	ilGenImages( 1, & ImageName );
        ilBindImage( ImageName ); // Jak to usune to wszystko działa tylko nic nie wyświetla
        ilLoadImage( sciezka ); // a tutaj pokazuje błąd
        Error = ilGetError();
        if( Error != IL_NO_ERROR ) return false;
       
        W = ilGetInteger( IL_IMAGE_WIDTH );
        H = ilGetInteger( IL_IMAGE_HEIGHT );
        Data = ilGetData();
        if( !ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE ) ) return false;
       
        glGenTextures( 1, & ImageName );
        glBindTexture( GL_TEXTURE_2D, ImageName );
        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 ), W, H, 0, ilGetInteger( IL_IMAGE_FORMAT ), GL_UNSIGNED_BYTE, ilGetData() );
        //ilDeleteImages(1, &ImageName);
        return true;
    }
0

Jeśli nikt nie ma pomysłu to napisze te funkcje od nowa. Tylko czy ktoś zna jakiś dobry (najlepiej polski) kurs?

0

Jeżeli chodzi o Polskie artykuły na ten temat to stanowczo przestałbym się łudzić, że takowe istnieją. Ale wystarczy wrzucić frazę "devil opengl" (https://www.google.pl/#output=search&sclient=psy-ab&q=devil+opengl&oq=devil+opengl&gs_l=hp.3..35i39l2j0i30l2.355.2004.0.2540.12.12.0.0.0.0.214.1889.0j11j1.12.0...0.0...1c.1.14.psy-ab.SZAtD8kpb90&pbx=1&bav=on.2,or.r_cp.r_qf.&bvm=bv.47008514,d.bGE&fp=5942845ef8bc811&biw=1429&bih=968) i masz pełno stron z objaśnieniami i przykladami jak załadować i bindować załadowaną teksturę.

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