Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[DevIL]Wyświetlanie 2D

Ostatnio zmodyfikowano 2012-01-16 14:27
Autor Wiadomość
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:
C/C++
...
#include <IL/il.h>
#pragma comment(lib, "DevIL.lib" )
...
// tworze okno i:
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 );
...
// Dla textury stworzyłem sobię klasę, w niej:
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();
    }
};

// w kodzie:
Sprite Spr;
...
Spr.Load( "DevIL.jpg" );
...
//przy zwalnianiu
Spr.Free();
...
// Przy rysowaniu:
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?
P-48118
DejaVu
» 2012-01-14 13:52:00
C/C++
Sprite Spr;
Spr.Load( "DevIL.jpg" ); //Wczytaj
Spr.Free(); //Usuń
Spr.Draw( 10, 10, 1.0f ); //Wyświetl
Hm... otwórz lodówkę, zamknij lodówkę, wyjmij mleko... hm... :)
P-48159
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 -.-
P-48366
« 1 »
  Strona 1 z 1