src/text.c

changeset 45
18de2af03531
parent 44
b3da4096c607
child 48
6e5b5ba2752c
equal deleted inserted replaced
44:b3da4096c607 45:18de2af03531
40 // Obtain shader 40 // Obtain shader
41 AscShaderSprite *shader = &asc_context.active_window->glctx.shader.sprite; 41 AscShaderSprite *shader = &asc_context.active_window->glctx.shader.sprite;
42 42
43 // Upload model matrix 43 // Upload model matrix
44 glUniformMatrix4fv(shader->base.model, 1, 44 glUniformMatrix4fv(shader->base.model, 1,
45 GL_FALSE, node->base.final_transform); 45 GL_FALSE, node->base.world_transform);
46 46
47 // Upload surface 47 // Upload surface
48 glActiveTexture(GL_TEXTURE0); 48 glActiveTexture(GL_TEXTURE0);
49 glBindTexture(GL_TEXTURE_RECTANGLE, node->tex_id); 49 glBindTexture(GL_TEXTURE_RECTANGLE, node->tex_id);
50 glUniform1i(shader->surface, 0); 50 glUniform1i(shader->surface, 0);
52 // Apply depth 52 // Apply depth
53 glUniform1f(shader->depth, (float)(node->base.depth)); 53 glUniform1f(shader->depth, (float)(node->base.depth));
54 54
55 // Draw mesh 55 // Draw mesh
56 asc_primitives_draw_plane(); 56 asc_primitives_draw_plane();
57 }
58
59 static void asc_text_update_transform(AscText *node) {
60 asc_transform_scale2i(node->base.local_transform, node->dimension);
61 asc_transform_translate2i(node->base.world_transform, node->position);
62 } 57 }
63 58
64 static void asc_text_update(AscText *node) { 59 static void asc_text_update(AscText *node) {
65 // short circuit if fully transparent or hidden, we don't need anything 60 // short circuit if fully transparent or hidden, we don't need anything
66 if (node->color.alpha == 0 || node->hidden) { 61 if (node->color.alpha == 0 || node->hidden) {
85 ); 80 );
86 if (surface == NULL) { 81 if (surface == NULL) {
87 asc_error(SDL_GetError()); 82 asc_error(SDL_GetError());
88 return; 83 return;
89 } 84 }
90 node->dimension.width = surface->w; 85 node->base.scale.width = (float) surface->w;
91 node->dimension.height = surface->h; 86 node->base.scale.height = (float) surface->h;
92 asc_node_update_transform((AscSceneNode *) node); 87 asc_update_transform((AscSceneNode *) node);
93 88
94 // Transfer Image Data 89 // Transfer Image Data
95 // TODO: move the image data transfer to a separate function - we will need it more often 90 // TODO: move the image data transfer to a separate function - we will need it more often
96 glBindTexture(GL_TEXTURE_RECTANGLE, node->tex_id); 91 glBindTexture(GL_TEXTURE_RECTANGLE, node->tex_id);
97 glPixelStorei(GL_UNPACK_ROW_LENGTH, surface->pitch / surface->format->BytesPerPixel); 92 glPixelStorei(GL_UNPACK_ROW_LENGTH, surface->pitch / surface->format->BytesPerPixel);
111 } 106 }
112 107
113 node->base.render_group = ASC_RENDER_GROUP_SPRITE_BLEND; 108 node->base.render_group = ASC_RENDER_GROUP_SPRITE_BLEND;
114 node->base.free_func = (asc_scene_free_func) asc_text_free; 109 node->base.free_func = (asc_scene_free_func) asc_text_free;
115 node->base.update_func = (asc_scene_update_func) asc_text_update; 110 node->base.update_func = (asc_scene_update_func) asc_text_update;
116 node->base.transform_update_func = (asc_scene_update_func) asc_text_update_transform;
117 node->base.draw_func = (asc_scene_draw_func) asc_text_draw; 111 node->base.draw_func = (asc_scene_draw_func) asc_text_draw;
118 112
119 node->position.x = x; 113 node->base.position.x = (float) x;
120 node->position.y = y; 114 node->base.position.y = (float) y;
121 node->font = asc_context.active_font; 115 node->font = asc_context.active_font;
122 node->color = asc_context.ink; 116 node->color = asc_context.ink;
123 if (text != NULL) { 117 if (text != NULL) {
124 node->text = strdup(text); 118 node->text = strdup(text);
125 } 119 }
126 120
127 // initialize 121 // initialize
128 asc_text_update(node); 122 asc_text_update(node);
129 asc_text_update_transform(node);
130 123
131 return &node->base; 124 return &node->base;
132 } 125 }
133 126
134 void asc_text_free(AscText *node) { 127 void asc_text_free(AscText *node) {

mercurial