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.