src/text.c

changeset 253
6ab35fcb8676
parent 239
3b78ad115ccd
child 255
0e0a0bf4f7e4
equal deleted inserted replaced
252:42e8695372f7 253:6ab35fcb8676
32 #include "ascension/constants.h" 32 #include "ascension/constants.h"
33 33
34 #include <assert.h> 34 #include <assert.h>
35 #include <cx/printf.h> 35 #include <cx/printf.h>
36 36
37 #include <SDL3_ttf/SDL_ttf.h>
38
37 typedef struct asc_text_shader_s { 39 typedef struct asc_text_shader_s {
38 AscShaderProgram program; 40 AscShaderProgram program;
39 asc_uniform_loc tex; 41 asc_uniform_loc tex;
40 } AscTextShader; 42 } AscTextShader;
41 43
62 if (font == NULL) { 64 if (font == NULL) {
63 // cannot load font - hide the text node to avoid errors when trying to draw 65 // cannot load font - hide the text node to avoid errors when trying to draw
64 asc_set_flag(node->flags, ASC_SCENE_NODE_HIDDEN); 66 asc_set_flag(node->flags, ASC_SCENE_NODE_HIDDEN);
65 return; 67 return;
66 } 68 }
67 static int alignments[] = { 69 static TTF_HorizontalAlignment alignments[] = {
68 TTF_WRAPPED_ALIGN_LEFT, 70 TTF_HORIZONTAL_ALIGN_LEFT,
69 TTF_WRAPPED_ALIGN_CENTER, 71 TTF_HORIZONTAL_ALIGN_CENTER,
70 TTF_WRAPPED_ALIGN_RIGHT 72 TTF_HORIZONTAL_ALIGN_RIGHT
71 }; 73 };
72 TTF_SetFontWrappedAlign( 74 TTF_SetFontWrapAlignment(
73 font, alignments[text->base.flags & ASC_TEXT_ALIGNMENT_MASK]); 75 font, alignments[text->base.flags & ASC_TEXT_ALIGNMENT_MASK]);
74 SDL_Surface *surface = TTF_RenderUTF8_Blended_Wrapped( 76 // TODO: it looks like TTF_RenderText_Blended_Wrapped is broken in SDL 3
75 font, text->text.ptr, asc_col_sdl(text->color), text->max_width 77 SDL_Surface *surface = TTF_RenderText_Blended(
78 font, text->text.ptr, text->text.length, asc_col_sdl(text->color)//, text->max_width
76 ); 79 );
77 if (surface == NULL) { 80 if (surface == NULL) {
78 asc_error("Rendering TTF surface failed: %s", SDL_GetError()); 81 asc_error("Rendering TTF surface failed: %s", SDL_GetError());
79 return; 82 return;
80 } 83 }
95 .uv_scale = uv_scale 98 .uv_scale = uv_scale
96 ); 99 );
97 } 100 }
98 101
99 // Free the surface 102 // Free the surface
100 SDL_FreeSurface(surface); 103 SDL_DestroySurface(surface);
101 104
102 // Schedule for transform update 105 // Schedule for transform update
103 asc_scene_node_update_transform(node); 106 asc_scene_node_update_transform(node);
104 } 107 }
105 108

mercurial