1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
#include "main.h"
void Ctext::LoadFont(char police[], int size, int R, int G, int B)
{
color.r=R;
color.g=G;
color.b=B;
font=TTF_OpenFont(police, size);
rectsrc.x = 0;
rectsrc.y = 0;
rectsrc.w = 300;
rectsrc.h = 70;
}
void Ctext::DrawText(char message[])
{
//Création de la texture du sprite
SDL_Surface *temp;
glGenTextures (1, & surface);
glBindTexture (GL_TEXTURE_2D, surface);
// Paramétrage de la texture.
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
temp = TTF_RenderText_Solid(font, message, color);
SDL_Surface *temp2=SDL_CreateRGBSurface(
SDL_HWSURFACE,
512,
512,
32,
temp->format->Rmask,
temp->format->Gmask,
temp->format->Bmask,
temp->format->Amask);
SDL_BlitSurface(temp, &rectsrc, temp2, &rectsrc);
// Jonction entre OpenGL et SDL.
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGB, temp2->w, temp2->h, 0,
GL_RGB, GL_UNSIGNED_BYTE, temp2-> pixels);
SDL_FreeSurface(temp);
SDL_FreeSurface(temp2);
glEnable(GL_ALPHA_TEST);
glBegin(GL_QUADS);
glTexCoord2f (0, 0);
glVertex2f(rectdest.x, rectdest.y);
glTexCoord2f (0, 1);
glVertex2f(rectdest.x, rectdest.y + rectsrc.h);
glTexCoord2f (1, 1);
glVertex2f(rectdest.x + rectsrc.w, rectdest.y + rectsrc.h);
glTexCoord2f (1, 0);
glVertex2f(rectdest.x + rectsrc.w, rectdest.y);
glEnd();
}
void Ctext::SetPosition(int x, int y)
{
rectdest.x = x;
rectdest.y = y;
} |