skovv Temat założony przez niniejszego użytkownika |
[DevIL]Wyświetlanie 2D » 2012-01-13 21:32:02 Witam. Mam problem z wyświetleniem textury z użyciem DevIL. Wszystko robię tak: ... #include <IL/il.h> #pragma comment(lib, "DevIL.lib" ) ...
glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( 0, W, H, 0, 0, 1 ); glDisable( GL_TEXTURE_2D ); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glTranslatef( 0.375, 0.375, 0 ); ...
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() ); 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(); } };
Sprite Spr; ... Spr.Load( "DevIL.jpg" ); ...
Spr.Free(); ...
Spr.Draw( 10, 10, 1.0f );
I wyświetla się biały kwadrat o wymiarach wczytanego obrazka, na podanej pozycji( czyli chyba dobrze się wczytało ) jednak nie wyświetla grafiki tylko biały kwadrat :| Co robię nie tak? |
|
DejaVu |
» 2012-01-14 13:52:00 Sprite Spr; Spr.Load( "DevIL.jpg" ); Spr.Free(); Spr.Draw( 10, 10, 1.0f );
Hm... otwórz lodówkę, zamknij lodówkę, wyjmij mleko... hm... :) |
|
skovv Temat założony przez niniejszego użytkownika |
» 2012-01-16 14:27:44 Lol... oczywiście zwalniam na koniec, a nie od razu po załadowaniu -.- |
|
« 1 » |