Probleme d'alpha avec SDL_ttf

vladisback Messages postés 61 Date d'inscription dimanche 19 novembre 2000 Statut Membre Dernière intervention 5 août 2008 - 4 mai 2006 à 00:27
vladisback Messages postés 61 Date d'inscription dimanche 19 novembre 2000 Statut Membre Dernière intervention 5 août 2008 - 5 août 2008 à 18:43
Je suis entrain de m'arracher les cheuveux avec SDL_ttf, j'essai simplement d'afficher du texte de n'importe quelle couleur opaque sur un fond transparent, cela fonctionne parfaitement avec TTF_RenderText_Solid, mais dés que j'utilise TTF_RenderText_Blended pour avoir une meilleur qualité ça ne fonctionne plus, apparament dans ce cas la au lieu que seul le fond soit transparent c'est tout qui disparait... pourtant il me semble que ça fonctionne de la même façon...
est-ce que je me trompe?
d'ou peut venir le probleme s'il y en a réellement un?

mon code:
intialisation avec ça:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);

(pour utiliser le canal alpha)

et puis le principal pour rendre le texte:

void SDL_GL_RenderText(char *text,
TTF_Font *font,
SDL_Color color,
SDL_Rect *location)
{
SDL_Surface *initial;
SDL_Surface *intermediary;
SDL_Rect rect;
int w,h;
GLuint texture;

/* Use SDL_TTF to render our text */
initial = TTF_RenderText_Blended(font, text, color);
// remplacer si dessus pas TTF_RenderText_Solid et ça fonctionne...

/* Convert the rendered text to a known format */
w = nextpoweroftwo(initial->w);
h = nextpoweroftwo(initial->h);

intermediary = SDL_CreateRGBSurface(0, w, h, 32,
0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000);


SDL_BlitSurface(initial, 0, intermediary, 0);

/* Tell GL about our new texture */
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, 4, w, h, 0, GL_RGBA,
GL_UNSIGNED_BYTE, intermediary->pixels );

/* GL_NEAREST looks horrible, if scaled... */
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);


/* prepare to render our texture */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f, 1.0f, 1.0f);

/* Draw a quad at location */
glBegin(GL_QUADS);
/* Recall that the origin is in the lower-left corner
That is why the TexCoords specify different corners
than the Vertex coors seem to. */
glTexCoord2f(0.0f, 1.0f);
glVertex2f(location->x , location->y);
glTexCoord2f(0.0f, 0.0f);
glVertex2f(location->x , location->y + h);
glTexCoord2f(1.0f, 0.0f);
glVertex2f(location->x + w, location->y + h);
glTexCoord2f(1.0f, 1.0f);
glVertex2f(location->x + w, location->y);



glEnd();

/* Bad things happen if we delete the texture before it finishes */
glFinish();

/* return the deltas in the unused w,h part of the rect */
location->w = initial->w;
location->h = initial->h;

/* Clean up */
SDL_FreeSurface(initial);
SDL_FreeSurface(intermediary);
glDeleteTextures(1, &texture);
}

2 réponses

jeanbono_2 Messages postés 1 Date d'inscription jeudi 15 février 2007 Statut Membre Dernière intervention 5 août 2008
5 août 2008 à 12:14
Je suis confronté au même problème ... Est-ce que ce problème a fini par être résolu ? Si oui, comment ?
Merci !

Nicolas Michel -
0
vladisback Messages postés 61 Date d'inscription dimanche 19 novembre 2000 Statut Membre Dernière intervention 5 août 2008
5 août 2008 à 18:43
Désolé, mais je n'ai aucun souvenir si j'avais trouvé une solution ou pas.
Il faut dire aussi que je programme un peu moins maintenant et que je n'utilise plus SDL.
J'espère que tu trouvera la solution.
++
0
Rejoignez-nous