Partage
  • Partager sur Facebook
  • Partager sur Twitter

OpenGL - Tentative d'overlay avec SDL_ttf

    18 juillet 2007 à 21:29:47

    Bonjour à tous
    En m'inspirant de la fonction loadTexture de Kayl, j'ai créela suivante :
    GLuint loadSurface(const SDL_Surface* picture_surface ,bool useMipMap = true);

    Et cette fonction fonctionne parfaitement.
    Voulant afficher du texte dans un rectangle créé par OpenGL j'ai donc fais ceci:
    .................
        GLuint texture;
        SDL_Surface *texte = NULL;
        SDL_Color couleurGrise = {127, 127, 127};

        TTF_Font* police = TTF_OpenFont("../tahoma.ttf", 65);
        texte = TTF_RenderText_Blended(police, "pouet" , couleurGrise);
        TTF_CloseFont(police);
       
        // texture = loadTexture("stainedglass05.jpg");
        texture = loadSurface(texte);

        .........
        while(true){
            .....
            glBindTexture(GL_TEXTURE_2D, texture);
            glBegin(GL_QUADS);

            glTexCoord2i(0,0);
            glVertex2d(-0.75,-0.75);
           
            glTexCoord2i(1,0);
            glVertex2d(-0.75,0.75);
           
            glTexCoord2i(1,1);
            glVertex2d(0.75,0.75);
           
            glTexCoord2i(0,1);
            glVertex2d(0.75,-0.75);
           
            glEnd();
        }
    .............

    Ce qui, il me semble devrait afficher le texte dans le carré créé. Cependant j'obtiens un laid rectangle gris. Comment se fait-ce ? Si je décommente la ligne commentée, et que je commente celle du dessous, la texture s'affiche parfaitement.

    Merci de m'aider
    • Partager sur Facebook
    • Partager sur Twitter
      18 juillet 2007 à 21:47:15

      Et si tu nous montrais ta fonction GLuint loadSurface(const SDL_Surface* picture_surface ,bool useMipMap = true); ? :-°
      • Partager sur Facebook
      • Partager sur Twitter
        18 juillet 2007 à 23:06:26

        Sans problème.
        La voici:
        GLuint loadSurface(const SDL_Surface *picture_surface ,bool useMipMap)

        {

            GLuint glID;
            //SDL_Surface * picture_surface = NULL;
            SDL_Surface *gl_surface = NULL;
            SDL_Surface * gl_fliped_surface = NULL;
            Uint32 rmask, gmask, bmask, amask;



            //picture_surface = IMG_Load(filename);
            if (picture_surface == NULL)
                return 0;



        #if SDL_BYTEORDER == SDL_BIG_ENDIAN

            rmask = 0xff000000;
            gmask = 0x00ff0000;
            bmask = 0x0000ff00;
            amask = 0x000000ff;

        #else

            rmask = 0x000000ff;
            gmask = 0x0000ff00;
            bmask = 0x00ff0000;
            amask = 0xff000000;

        #endif

            SDL_PixelFormat format = *(picture_surface->format);

            format.BitsPerPixel = 32;

            format.BytesPerPixel = 4;

            format.Rmask = rmask;

            format.Gmask = gmask;

            format.Bmask = bmask;

            format.Amask = amask;

            gl_surface = SDL_ConvertSurface((SDL_Surface*) picture_surface,&format,SDL_SWSURFACE);

            gl_fliped_surface = flipSurface(gl_surface);

            glGenTextures(1, &glID);

            glBindTexture(GL_TEXTURE_2D, glID);

            if (useMipMap)    {

                gluBuild2DMipmaps(GL_TEXTURE_2D, 4, gl_fliped_surface->w,
                                  gl_fliped_surface->h, GL_RGBA,GL_UNSIGNED_BYTE,
                                  gl_fliped_surface->pixels);

                glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,
                                GL_LINEAR_MIPMAP_LINEAR);

            }else{

                glTexImage2D(GL_TEXTURE_2D, 0, 4, gl_fliped_surface->w,
                             gl_fliped_surface->h, 0, GL_RGBA,GL_UNSIGNED_BYTE,
                             gl_fliped_surface->pixels);
                glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

            }
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

            SDL_FreeSurface(gl_fliped_surface);
            SDL_FreeSurface(gl_surface);
            SDL_FreeSurface((SDL_Surface*) picture_surface);

            return glID;

        }


        J'ai au passage modifié la fonction de Kayl. Mais elle marche et a le même effet que l'originale:
        GLuint loadTexture(const char * filename,bool useMipMap){

            SDL_Surface * picture_surface = NULL;



            picture_surface = IMG_Load(filename);

            if (picture_surface == NULL)

              return 0;

            return loadSurface(picture_surface , useMipMap);

        }
        • Partager sur Facebook
        • Partager sur Twitter

        OpenGL - Tentative d'overlay avec SDL_ttf

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown