
#ifndef H_CTEXTE
#define H_CTEXTE

#include <math.h>
#include <SDL/SDL_ttf.h>

class Ctexte
{

	private :
        GLuint surface[38];
        int giveLettre(char lettre);

    public :
        Ctexte();
        ~Ctexte();

        void LoadFont();
        void DessineTexte(const char * texte, int taille, int PosX, int PosY, char red, char green, char blue);


};

Ctexte::Ctexte()
{

}

void Ctexte::LoadFont()
{

    surface[0] = loadTexture("./Images/Font/A.png");
    surface[1] = loadTexture("./Images/Font/B.png");
    surface[2] = loadTexture("./Images/Font/C.png");
    surface[3] = loadTexture("./Images/Font/D.png");
    surface[4] = loadTexture("./Images/Font/E.png");
    surface[5] = loadTexture("./Images/Font/F.png");
    surface[6] = loadTexture("./Images/Font/G.png");
    surface[7] = loadTexture("./Images/Font/H.png");
    surface[8] = loadTexture("./Images/Font/I.png");
    surface[9] = loadTexture("./Images/Font/J.png");
    surface[10] = loadTexture("./Images/Font/K.png");
    surface[11] = loadTexture("./Images/Font/L.png");
    surface[12] = loadTexture("./Images/Font/M.png");
    surface[13] = loadTexture("./Images/Font/N.png");
    surface[14] = loadTexture("./Images/Font/O.png");
    surface[15] = loadTexture("./Images/Font/P.png");
    surface[16] = loadTexture("./Images/Font/Q.png");
    surface[17] = loadTexture("./Images/Font/R.png");
    surface[18] = loadTexture("./Images/Font/S.png");
    surface[19] = loadTexture("./Images/Font/T.png");
    surface[20] = loadTexture("./Images/Font/U.png");
    surface[21] = loadTexture("./Images/Font/V.png");
    surface[22] = loadTexture("./Images/Font/W.png");
    surface[23] = loadTexture("./Images/Font/X.png");
    surface[24] = loadTexture("./Images/Font/Y.png");
    surface[25] = loadTexture("./Images/Font/Z.png");
    surface[26] = loadTexture("./Images/Font/DeuxPoints.png");
    surface[27] = loadTexture("./Images/Font/0.png");
    surface[28] = loadTexture("./Images/Font/1.png");
    surface[29] = loadTexture("./Images/Font/2.png");
    surface[30] = loadTexture("./Images/Font/3.png");
    surface[31] = loadTexture("./Images/Font/4.png");
    surface[32] = loadTexture("./Images/Font/5.png");
    surface[33] = loadTexture("./Images/Font/6.png");
    surface[34] = loadTexture("./Images/Font/7.png");
    surface[35] = loadTexture("./Images/Font/8.png");
    surface[36] = loadTexture("./Images/Font/9.png");
    surface[37] = loadTexture("./Images/Font/Espace.png");


}

Ctexte::~Ctexte()
{

}

void Ctexte::DessineTexte(const char * texte, int taille, int PosX, int PosY, char red = 255, char green = 255, char blue = 255)
{
    char nbtex;

    //glEnable(GL_ALPHA_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_BLEND);
    glAlphaFunc(GL_LESS, 1);
    glEnable(GL_TEXTURE_2D);

    for(int i = 0; texte[i] != '\0'; i++)
    {
        nbtex = giveLettre(toupper(texte[i]));
        glBindTexture(GL_TEXTURE_2D, surface[nbtex]);

        glBegin(GL_QUADS);
            glColor3ub(red, green, blue);

            glTexCoord2f (0, 0);
            glVertex2f(PosX + i * taille, PosY);

            glTexCoord2f (0, 1);
            glVertex2f(PosX + i * taille, PosY + taille);

            glTexCoord2f (1, 1);
            glVertex2f(PosX + (i+1) * taille, PosY + taille);

            glTexCoord2f (1, 0);
            glVertex2f(PosX + (i+1) * taille, PosY);
        glEnd();
    }

    //glDisable(GL_ALPHA_TEST);
    glDisable(GL_BLEND);
    glDisable(GL_TEXTURE_2D);

}

int Ctexte::giveLettre(char lettre)
{
    if(lettre == 'A') return 0;
    if(lettre == 'B') return 1;
    if(lettre == 'C') return 2;
    if(lettre == 'D') return 3;
    if(lettre == 'E') return 4;
    if(lettre == 'F') return 5;
    if(lettre == 'G') return 6;
    if(lettre == 'H') return 7;
    if(lettre == 'I') return 8;
    if(lettre == 'J') return 9;
    if(lettre == 'K') return 10;
    if(lettre == 'L') return 11;
    if(lettre == 'M') return 12;
    if(lettre == 'N') return 13;
    if(lettre == 'O') return 14;
    if(lettre == 'P') return 15;
    if(lettre == 'Q') return 16;
    if(lettre == 'R') return 17;
    if(lettre == 'S') return 18;
    if(lettre == 'T') return 19;
    if(lettre == 'U') return 20;
    if(lettre == 'V') return 21;
    if(lettre == 'W') return 22;
    if(lettre == 'X') return 23;
    if(lettre == 'Y') return 24;
    if(lettre == 'Z') return 25;
    if(lettre == ':') return 26;
    if(lettre == '0') return 27;
    if(lettre == '1') return 28;
    if(lettre == '2') return 29;
    if(lettre == '3') return 30;
    if(lettre == '4') return 31;
    if(lettre == '5') return 32;
    if(lettre == '6') return 33;
    if(lettre == '7') return 34;
    if(lettre == '8') return 35;
    if(lettre == '9') return 36;
    if(lettre == ' ') return 37;

    return 37;
}

#endif
