| 125 | } |
| 126 | |
| 127 | void TextDrawerGL::Print( |
| 128 | const int x, const int y, |
| 129 | const char* text, |
| 130 | const unsigned int scale, |
| 131 | const FontColor color, |
| 132 | const Alignment alignment ) |
| 133 | { |
| 134 | const int scale_i= int(scale); |
| 135 | const int d_tc_v= int(color) * int(FontParams::atlas_height); |
| 136 | |
| 137 | Vertex* v= vertex_buffer_.data(); |
| 138 | int current_x= x; |
| 139 | int current_y= viewport_size_.Height() - y - scale * FontParams::letter_height; |
| 140 | |
| 141 | Vertex* last_newline_vertex_index= v; |
| 142 | while( 1 ) |
| 143 | { |
| 144 | const unsigned int code= static_cast<unsigned char>(*text); // Convert to unsigned - allow chars with codes 128 - 255. |
| 145 | if( code == '\n' || code == '\0' ) |
| 146 | { |
| 147 | if( alignment == Alignment::Center ) |
| 148 | { |
| 149 | const int center_x= ( last_newline_vertex_index->xy[0] + current_x ) / 2; |
| 150 | const int delta_x= x - center_x; |
| 151 | while( last_newline_vertex_index < v ) |
| 152 | { |
| 153 | last_newline_vertex_index->xy[0]+= delta_x; |
| 154 | last_newline_vertex_index++; |
| 155 | } |
| 156 | } |
| 157 | else if( alignment == Alignment::Right ) |
| 158 | { |
| 159 | const int delta_x= last_newline_vertex_index->xy[0] - current_x; |
| 160 | while( last_newline_vertex_index < v ) |
| 161 | { |
| 162 | last_newline_vertex_index->xy[0]+= delta_x; |
| 163 | last_newline_vertex_index++; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | current_x= x; |
| 168 | current_y-= int(FontParams::letter_height * scale); |
| 169 | text++; |
| 170 | |
| 171 | if( code == '\0' ) break; |
| 172 | else continue; |
| 173 | } |
| 174 | |
| 175 | const unsigned int tc_u= ( code & 15u ) * FontParams::letter_place_width + FontParams::letter_u_offset; |
| 176 | const unsigned int tc_v= ( code >> 4u ) * FontParams::letter_place_height + FontParams::letter_v_offset + d_tc_v; |
| 177 | const unsigned char letter_width= letters_width_[code]; |
| 178 | |
| 179 | v[0].xy[0]= current_x; |
| 180 | v[0].xy[1]= current_y; |
| 181 | v[0].tex_coord[0]= tc_u; |
| 182 | v[0].tex_coord[1]= tc_v + FontParams::letter_height; |
| 183 | |
| 184 | v[1].xy[0]= current_x + letter_width * scale_i; |