Changeset 103 for trunk/src/gfx
- Timestamp:
- 06/04/13 19:10:57 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/gfx/texture_font.cc
r95 r103 71 71 } 72 72 73 static uint8* convert_to_rgba(uint8* rgb, const int lines, const int line_count, const int line_bpitch ) 74 { 75 uint8* result = new uint8[ lines * line_count * 4 ]; 76 uint8* rgba = result; 77 for(int l=0; l<lines; ++l) 78 { 79 for(int c=0; c<line_count; ++c) 80 { 81 for(int j=0; j<3; ++j) { 82 rgba[j] = rgb[j]; 83 } 84 rgba[3] = uint8( uint16( rgb[0] + rgb[1] + rgb[2] ) / 3 ); 85 rgba += 4; 86 rgb += 3; 87 } 88 rgb += line_bpitch - ( 3 * line_count ); 89 } 90 return result; 91 } 92 73 93 bool texture_font::load_glyphs( const std::string& codes ) 74 94 { … … 87 107 } 88 108 89 if( m_atlas->get_depth() == 3 )109 if( m_atlas->get_depth() >= 3 ) 90 110 { 91 111 FT_Library_SetLcdFilter( (FT_Library)(m_rlibrary), FT_LCD_FILTER_LIGHT ); … … 115 135 int ft_glyph_top = slot->bitmap_top; 116 136 int ft_glyph_left = slot->bitmap_left; 137 int reg_width = ft_bitmap_width / (depth > 3 ? 3 : depth); 117 138 118 glm::ivec2 gsize( ft_bitmap_width/depth + 1, ft_bitmap_rows + 1 );139 glm::ivec2 gsize( reg_width + 1, ft_bitmap_rows + 1 ); 119 140 region r = m_atlas->get_region( gsize ); 120 141 if ( r.pos.x < 0 ) … … 126 147 NV_THROW( std::runtime_error, error_msg.str().c_str() ); 127 148 } 128 r.size.x -= 1; 129 r.size.y -= 1; 130 m_atlas->set_region( r, ft_bitmap.buffer, ft_bitmap.pitch ); 149 if (depth == 4) 150 { 151 r.size.x -= 1; 152 r.size.y -= 1; 153 uint8* data = convert_to_rgba(ft_bitmap.buffer, r.size.y, r.size.x, ft_bitmap.pitch ); 154 m_atlas->set_region( r, data ); 155 delete data; 156 } 157 else 158 { 159 r.size.x -= 1; 160 r.size.y -= 1; 161 m_atlas->set_region( r, ft_bitmap.buffer, ft_bitmap.pitch ); 162 } 131 163 132 164 m_glyphs[ c ] = texture_glyph();
Note: See TracChangeset
for help on using the changeset viewer.