95 |
95 |
96 // Transfer Image Data |
96 // Transfer Image Data |
97 asc_texture_from_surface(text->texture, surface); |
97 asc_texture_from_surface(text->texture, surface); |
98 |
98 |
99 // If dimensions changed, update the mesh |
99 // If dimensions changed, update the mesh |
100 if (text->dimension.x != (unsigned)surface->w || text->dimension.y != (unsigned)surface->h) { |
100 if (text->dimension.width != (unsigned)surface->w || text->dimension.height != (unsigned)surface->h) { |
101 text->dimension.x = surface->w; |
101 text->dimension.width = surface->w; |
102 text->dimension.y = surface->h; |
102 text->dimension.height = surface->h; |
103 const asc_vec2f uv_scale = asc_texture_calculate_uv_scale(text->texture, text->dimension, ASC_VEC2F_1); |
103 const asc_vec2f uv_scale = asc_texture_calculate_uv_scale(text->texture, text->dimension, ASC_VEC2F_1); |
104 asc_mesh_plane_2d(&text->mesh, |
104 asc_mesh_plane_2d(&text->mesh, |
105 .size = ASC_VEC2F(surface->w, surface->h), |
105 .size = ASC_VEC2F(surface->w, surface->h), |
106 .uv_scale = uv_scale |
106 .uv_scale = uv_scale |
107 ); |
107 ); |
114 asc_scene_node_update_transform(node); |
114 asc_scene_node_update_transform(node); |
115 } |
115 } |
116 |
116 |
117 static void asc_text_draw(const AscCamera *camera, const AscSceneNode *node) { |
117 static void asc_text_draw(const AscCamera *camera, const AscSceneNode *node) { |
118 asc_cptr_cast(AscText, text, node); |
118 asc_cptr_cast(AscText, text, node); |
|
119 |
|
120 // early exit when the text has no width |
|
121 if (text->dimension.width == 0) return; |
119 |
122 |
120 // Activate shader |
123 // Activate shader |
121 // TODO: scene should know which shader we are going to activate s.t. it can pre-sort nodes |
124 // TODO: scene should know which shader we are going to activate s.t. it can pre-sort nodes |
122 const AscShaderProgram *shader = asc_shader_lookup_or_create( |
125 const AscShaderProgram *shader = asc_shader_lookup_or_create( |
123 ASC_SHADER_TEXT, asc_text_shader_create, 0); |
126 ASC_SHADER_TEXT, asc_text_shader_create, 0); |
172 // initialize texture |
175 // initialize texture |
173 // mesh will be created in the update func |
176 // mesh will be created in the update func |
174 text->texture = cxMallocDefault(sizeof(AscTexture)); |
177 text->texture = cxMallocDefault(sizeof(AscTexture)); |
175 asc_texture_init_rectangle(text->texture, 1); |
178 asc_texture_init_rectangle(text->texture, 1); |
176 // TODO: check why we can't just wait for the first normal update to happen |
179 // TODO: check why we can't just wait for the first normal update to happen |
177 asc_text_update(node); |
180 //asc_text_update(node); |
178 |
181 |
179 return node; |
182 return node; |
180 } |
183 } |
181 |
184 |
182 void asc_text_alignment( |
185 void asc_text_alignment( |