22 for(
unsigned int y= 0; y < 16; y++)
23 for(
unsigned int x= 0; x < 8; x++)
25 unsigned int starty= 16 *7;
26 unsigned int startx= 8 *2;
27 Color color= font(startx + x, starty + y);
29 font(startx + x, starty + y)= color;
33 for(
unsigned int y= 0; y < 16; y++)
34 for(
unsigned int x= 0; x < 8; x++)
36 unsigned int starty= 16 *7;
37 unsigned int startx= 8 *1;
39 font(startx + x, starty + y)= color;
52 GLint index= glGetUniformBlockIndex(text.
program,
"textData");
53 glUniformBlockBinding(text.
program, index, 0);
56 glGenVertexArrays(1, &text.
vao);
57 glGenBuffers(1, &text.
ubo);
58 glBindBuffer(GL_UNIFORM_BUFFER, text.
ubo);
59 glBufferData(GL_UNIFORM_BUFFER,
sizeof(text.buffer), text.buffer, GL_STATIC_DRAW);
67 glDeleteVertexArrays(1, &text.
vao);
68 glDeleteBuffers(1, &text.
ubo);
69 glDeleteTextures(1, &text.
font);
74 for(
int y= 0; y < 24; y++)
75 for(
int x= 0; x < 128; x++)
76 text.buffer[y][x]=
' ';
81 void print(
Text& text,
const int px,
const int py,
const int background,
const char *message )
86 for(
int i= 0; message[i] != 0; i++)
88 unsigned char c= message[i];
89 if(x >= 128 || c ==
'\n')
94 if(c ==
'\n')
continue;
96 if(x < 0 || y < 0)
break;
97 if(x >= 128 || y >= 24)
break;
100 text.buffer[y][x]= (int) c | (background << 8);
110 if(x < 0 || y < 0)
return;
111 if(x >= 128 || y >= 24)
return;
114 text.buffer[y][x]= (int) c | (background << 8);
119 print(text, px, py, 2, message);
122 void print(
Text& text,
const int px,
const int py,
const char *message )
124 print(text, px, py, 0, message);
129 char tmp[24*128+1] = { 0 };
132 va_start(args, format);
133 vsnprintf(tmp,
sizeof(tmp), format, args);
137 print(text, px, py, 2, tmp);
140 void printf(
Text& text,
const int px,
const int py,
const char *format, ... )
142 char tmp[24*128+1] = { 0 };
145 va_start(args, format);
146 vsnprintf(tmp,
sizeof(tmp), format, args);
150 print(text, px, py, 0, tmp);
158 void draw(
const Text& text,
const int width,
const int height )
160 glBindVertexArray(text.
vao);
168 glBindBufferBase(GL_UNIFORM_BUFFER, 0, text.
ubo);
169 glBufferSubData(GL_UNIFORM_BUFFER, 0,
sizeof(text.buffer), text.buffer);
171 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
173 glDisable(GL_DEPTH_TEST);
175 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
178 glEnable(GL_DEPTH_TEST);
Text create_text()
cree une console. a detruire avec release_text( ).
void release_text(Text &text)
detruit une console.
representation d'une couleur (rgba) transparente ou opaque.
GLuint make_texture(const int unit, const Image &im, const GLenum texel_type)
void program_uniform(const GLuint program, const char *uniform, const unsigned int v)
affecte une valeur a un uniform du shader program. uint.
void program_use_texture(const GLuint program, const char *uniform, const int unit, const GLuint texture, const GLuint sampler)
configure le pipeline et le shader program pour utiliser une texture, et des parametres de filtrages...
GLuint program
shader pour afficher le texte.
void default_color(Text &text, const Color &color)
choisit une couleur par defaut pour le texte.
Color White()
utilitaire. renvoie une couleur blanche.
int program_print_errors(const GLuint program)
affiche les erreurs de compilation.
Color color
couleur du texte.
GLuint read_program(const char *filename, const char *definitions)
GLuint font
texture contenant les caracteres.
Image read_image(const char *filename)
void printf(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y. meme utilisation que printf().
void draw(const Text &text, const int width, const int height)
dessine la console.
int release_program(const GLuint program)
detruit les shaders et le program.
representation d'une image.
void clear(Text &text)
efface le contenu de la console.
void printf_background(Text &text, const int px, const int py, const char *format,...)
affiche un texte a la position x, y sur un fond par defaut.
void print_background(Text &text, const int px, const int py, const int background, const char c)
affiche un caractere c sur un fond background.
GLuint ubo
uniform buffer object, pour transferrer le texte a afficher
void print(Text &text, const int px, const int py, const char *message)
affiche un texte a la position x, y.
GLuint vao
vertex array object.