55#define PANGO_TEXT_SIZE 500
56#define OUTLINE_WIDTH 3
58#ifndef GL_CLAMP_TO_EDGE
59# define GL_CLAMP_TO_EDGE 0x812F
62#ifndef GL_TEXTURE_WRAP_R
63# define GL_TEXTURE_WRAP_R 0x8072
73= {{ 10, 30, 45, 50, 45, 30, 10 },
74 { 30, 65, 85, 100, 85, 65, 30 },
75 { 45, 85, 200, 256, 200, 85, 45 },
76 { 50, 100, 256, 256, 256, 100, 50 },
77 { 45, 85, 200, 256, 200, 85, 45 },
78 { 30, 65, 85, 100, 85, 65, 30 },
79 { 10, 30, 45, 50, 45, 30, 10 }};
90static void normalize_text_size (GLenum texture,
int * width,
int * height)
95 if (texture == GL_TEXTURE_2D)
97 int x =
max (* width, * height);
100 for (n = 1;
n <
x;
n =
n << 1);
102 * width = * height =
n;
120 guint8 *
row, * row_end;
125#if ! defined(GL_VERSION_1_2) && G_BYTE_ORDER == G_LITTLE_ENDIAN
126 rgb = ((guint32) (
color.x* 255.0)) |
127 (((guint32) (
color.y * 255.0)) << 8) |
128 (((guint32) (
color.z * 255.0)) << 16);
130 rgb = (((guint32) (
color.x * 255.0)) << 24) |
131 (((guint32) (
color.y * 255.0)) << 16) |
132 (((guint32) (
color.z * 255.0)) << 8);
135 p = (guint32 *) bitmap;
140 while (
row != row_end)
143 for (i = 0; i < cw; i++)
145#if ! defined(GL_VERSION_1_2) && G_BYTE_ORDER == G_LITTLE_ENDIAN
146 * p++ = rgb | (((guint32)
row[i]) << 24);
148 * p++ = rgb | ((guint32)
row[i]);
155 while (
row != row_end)
158 for (i = 0; i < cw; i++)
160#if ! defined(GL_VERSION_1_2) && G_BYTE_ORDER == G_LITTLE_ENDIAN
161 * p++ = rgb | (((guint32) (a *
row[i])) << 24);
163 * p++ = rgb | ((guint32) (a *
row[i]));
191 new_string = g_malloc0(
sizeof*new_string);
192 if (! new_string)
return NULL;
194 int csize = cwidth * cheight;
198 if (! rawbitmap)
return NULL;
201 for (j = 0; j < cheight; j++)
203 for (i = 0; i < cwidth; i++)
205 x = (GLubyte)(pixels [n])/255.0;
207 rawbitmap[n] = (int)(255.0 *
y);
214 if (! neighborhood)
return NULL;
216 for (i = 0; i < cheight; i++)
218 for (j = 0; j < cwidth; j++)
227 if (fi >= 0 && fi < cheight && fj >= 0 && fj < cwidth)
229 fn = fj + fi * cwidth;
230 neighborhood[fn] =
max (neighborhood[fn],
241 GLubyte * channels[2];
244 channels[i] = g_malloc0(csize*
sizeof*channels[i]);
245 if (! channels[i])
return NULL;
248 for (n = 0; n < csize; n++)
250 channels[1][n] = (GLubyte)rawbitmap[n];
251 i = (neighborhood[n] >> 8) + rawbitmap[n];
256 channels[0][n] = (GLubyte)i;
259 g_free (neighborhood);
261 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
278 glTexParameteri (
ogl_texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
279 glTexParameteri (
ogl_texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
285 for (i=0; i<2; i++) g_free (channels[i]);
303 PangoRectangle prect;
310 pango_layout_get_extents (
layout, NULL, & prect);
311 if (prect.width == 0 || prect.height == 0)
return NULL;
312 cheight = bitmap.rows = PANGO_PIXELS (prect.height) + 2*
OUTLINE_WIDTH;
313 cwidth = bitmap.width = PANGO_PIXELS (prect.width) + 2*
OUTLINE_WIDTH;
315 normalize_text_size (
ogl_texture, & cwidth, & cheight);
317 bitmap.pitch = cwidth;
318 csize = cheight*cwidth;
319 bitmap.buffer = g_malloc0(csize);
320 memset (bitmap.buffer, 0, csize);
322 bitmap.num_grays = 256;
323 bitmap.pixel_mode = ft_pixel_mode_grays;
325 pixels =
paint_bitmap (vec4(1.0,0.0,0.0,0.0), 1.0, cwidth, cheight, bitmap.buffer);
326 g_free (bitmap.buffer);
329 new_string = g_malloc0(
sizeof*new_string);
330 new_string -> texture = -1;
331 glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
332 glGenTextures (1, & new_string -> texture);
333 if (! new_string -> texture)
return NULL;
334 glBindTexture (
ogl_texture, new_string -> texture);
345 glTexParameteri (
ogl_texture, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
346 glTexParameteri (
ogl_texture, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
359 new_string -> num_vertices = 4;
362 float x = (float) cwidth;
363 float y = (float) cheight;
364 float twidth = (
ogl_texture == GL_TEXTURE_2D) ? 1.0 :
x;
365 float theight = (
ogl_texture == GL_TEXTURE_2D) ? 1.0 :
y;
367 new_string -> vertices[0] = -
x;
368 new_string -> vertices[1] =
y;
369 new_string -> vertices[2] = 0.0;
370 new_string -> vertices[3] = theight;
372 new_string -> vertices[4] = -
x;
373 new_string -> vertices[5] = -
y;
374 new_string -> vertices[6] = 0.0;
375 new_string -> vertices[7] = 0.0;
377 new_string -> vertices[8] =
x;
378 new_string -> vertices[9] =
y;
379 new_string -> vertices[10] = twidth;
380 new_string -> vertices[11] = theight;
382 new_string -> vertices[12] =
x;
383 new_string -> vertices[13] = -
y;
384 new_string -> vertices[14] = twidth;
385 new_string -> vertices[15] = 0.0;
387 new_string -> num_instances = this_string -> num_instances;
388 int i = (this_string -> type == 3) ? 1 : (this_string -> type == 4) ? 3 : 4;
389 new_string -> inst_buffer_size = 3*i;
390 new_string -> instances =
duplicate_float (this_string -> num_instances*3*i, this_string -> instances);
404 ColRGBA * ocol = g_malloc0(
sizeof*ocol);
405 ocol -> red = (1.0-
col.red)/2.5;
406 ocol -> green = (1.0-
col.green)/2.5;
407 ocol -> blue = (1.0-
col.blue)/2.5;
426 PangoContext * pcontext;
427 PangoLayout * playout;
428 PangoFontDescription * pfont;
430 int arr_size = (this_string -> type == 4) ? 5 : (this_string -> type == 5) ? 6 : this_string -> type;
431 int shid = (
id == 4) ? 1 : 0;
433 pcontext = pango_font_map_create_context (pango_ft2_font_map_new ());
434 playout = pango_layout_new (pcontext);
435 pango_layout_set_alignment (playout, PANGO_ALIGN_CENTER);
436 pfont = pango_font_description_from_string (
plot ->
labels[
id].font);
437 j = pango_font_description_get_size (pfont);
438 font_size = j / PANGO_SCALE;
443 l = (
wingl -> pixels[0] >
wingl -> pixels[1]) ? 1 : 0;
446 pango_font_description_set_absolute_size (pfont, font_size*PANGO_SCALE);
447 pango_layout_set_font_description (playout, pfont);
448 pango_layout_set_markup (playout, this_string -> word, strlen(this_string -> word));
450 if (string_to_render == NULL)
452 g_warning (_(
"Error in text rendering : for some reason it is impossible to render\n - this string : '%s'Â \n - using this font: %s"), this_string -> word,
plot ->
labels[
id].font);
456 for (k=0; k<3; k++) string_to_render ->
shift[k] = this_string ->
shift[k];
458 string_to_render -> quality = this_string -> type;
459 j = this_string -> id;
461 if (
id == 1 &&
plot ->
labels[0].list != NULL)
469 else if (
id == 3 ||
id == 4)
478 NULL,
string_color, GL_TRIANGLE_STRIP, arr_size, (this_string -> type == 3) ? 7 : 8, FALSE, string_to_render);
483 NULL,
string_color_2d, GL_TRIANGLE_STRIP, arr_size, (this_string -> type == 3) ? 7 : 8, FALSE, string_to_render);
493 NULL,
string_color, GL_TRIANGLE_STRIP, arr_size, (this_string -> type == 3) ? 7 : 8, FALSE, string_to_render);
497 NULL,
string_color, GL_TRIANGLE_STRIP, arr_size, (this_string -> type == 3) ? 7 : 8, FALSE, string_to_render);
504 NULL,
string_color_2d, GL_TRIANGLE_STRIP, arr_size, (this_string -> type == 3) ? 7 : 8, FALSE, string_to_render);
508 NULL,
string_color_2d, GL_TRIANGLE_STRIP, arr_size, (this_string -> type == 3) ? 7 : 8, FALSE, string_to_render);
514 pango_font_description_free (pfont);
516 g_clear_object (& pcontext);
518 g_clear_object (& playout);
530 g_debug (
"STRING:: id= %d, text:: %s", this_string ->
id, this_string -> word);
531 g_debug (
"STRING:: color:: r= %f, g= %f, b= %f, a= %f",
532 this_string ->
col.red, this_string ->
col.green, this_string ->
col.blue, this_string ->
col.alpha);
535 for (i=0; i<this_string -> num_instances; i++, j+=3)
537 g_debug (
"STRING:: %d-th :: pos[%d][x]= %f, pos[%d][y]= %f, pos[%d][z]= %f, theta[%d]= %f",
538 i, i, this_string -> instances[j], i, this_string -> instances[j+1], i, this_string -> instances[j+2], i, this_string -> instances[j+2]);
540 g_debug (
"STRING:: shift:: x= %f, y= %f, z= %f", this_string ->
shift[0], this_string ->
shift[1], this_string ->
shift[2]);
541 g_debug (
"STRING:: show :: %f", this_string ->
shift[3]);
557 while (this_string != NULL)
561 this_string = this_string -> prev;
579 while (tmp_string != NULL)
581 if (g_strcmp0 (tmp_string -> word, word) == 0)
585 tmp_string = tmp_string -> prev;
609 if (
string -> num_instances > 0)
611 float * instances =
duplicate_float (3*j*
string -> num_instances,
string -> instances);
612 g_free (
string -> instances);
613 string -> instances =
allocfloat (3*j*(
string -> num_instances+1));
614 for (i=0; i<3*j*
string -> num_instances; i++)
616 string -> instances[i] = instances[i];
623 string -> num_instances ++;
624 string -> instances[i] = pos.
x;
625 string -> instances[i+1] = pos.
y;
626 string -> instances[i+2] = pos.
z;
629 string -> instances[i+3] = at ->
x;
630 string -> instances[i+4] = at ->
y;
631 string -> instances[i+5] = at ->
z;
632 string -> instances[i+6] = bt ->
x;
633 string -> instances[i+7] = bt ->
y;
634 string -> instances[i+8] = bt ->
z;
637 string -> instances[i+9] = ct ->
x;
638 string -> instances[i+10] = ct ->
y;
639 string -> instances[i+11] = ct ->
z;
668 s_tring -> prev =
plot ->
labels[id].list -> last;
669 s_tring ->
id =
plot ->
labels[id].list -> last ->
id + 1;
672 plot ->
labels[id].list -> last -> word = g_strdup_printf (
"%s",
text);
676 for (i=0; i<3; i++)
plot ->
labels[
id].list -> last ->
shift[i] = lshift[i];
697 if (this_string == NULL)
double scale(double axe)
find appropriate major tick spacing based on axis length
float * duplicate_float(int num, float *old_val)
copy a list of float
gboolean in_movie_encoding
int * allocint(int val)
allocate an int * pointer
float * allocfloat(int val)
allocate a float * pointer
Global variable declarations Global convenience function declarations Global data structure defin...
ColRGBA * duplicate_color(int num, ColRGBA *col)
duplicate a ColRGBA pointer
void zoom(glwin *view, int delta)
zoom in or zoom out in the OpenGL window
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
#define ZOOM
Default value for the OpenGL zoom.
object_3d * free_object_3d(object_3d *obj)
free the memory allocated to create an object_3d data structure
glsl_program * init_shader_program(int object, int object_id, const GLchar *vertex, const GLchar *geometry, const GLchar *fragment, GLenum type_of_vertices, int narray, int nunif, gboolean lightning, object_3d *obj)
create an OpenGL shader program
#define GL_TEXTURE_RECTANGLE_ARB
const GLchar * string_color_2d
const GLchar * string_vertex
const GLchar * string_color
const GLchar * degree_vertex
const GLchar * angstrom_vertex
screen_string * was_not_rendered_already(char *word, screen_string *list)
check if a string was not already rendered and the corresponding screen string created
#define GL_TEXTURE_WRAP_R
void prepare_string(char *text, int id, ColRGBA col, vec3_t pos, float lshift[3], atom *at, atom *bt, atom *ct)
prepare a screen string to be rendered
ColRGBA * opposite_color(ColRGBA col)
compute the opposite color
void add_string(char *text, int id, ColRGBA col, vec3_t pos, float lshift[3], atom *at, atom *bt, atom *ct)
Add a screen string to the list of screen string to render.
const int OUTLINE_BRUSH[2 *OUTLINE_WIDTH+1][2 *OUTLINE_WIDTH+1]
void debug_string(screen_string *this_string)
debug screen string data
void add_string_instance(screen_string *string, vec3_t pos, atom *at, atom *bt, atom *ct)
add an instance to a screen string
object_3d * gl_pango_render_layout(PangoLayout *layout, GLenum texture, int id, screen_string *this_string)
OpenGL 3D pango layout object rendering.
object_3d * create_string_texture(int cwidth, int cheight, int *pixels)
OpenGL 3D string object rendering.
void render_all_strings(int glsl, int id)
render all string to be rendered for a label list
int * paint_bitmap(vec4_t color, GLfloat a, int cw, int ch, unsigned char *buff)
paint bitmap data using color
void update_string_instances(glsl_program *glsl, object_3d *obj)
Update OpenGL string texture instances.
void render_string(int glsl, int id, screen_string *this_string)
render a screen string