[SDL] Simple font resize with blend

Joby Bednar thebigcheese at jobybednar.com
Tue Jan 28 10:19:02 PST 2003


It's probably far easier to simply build a font engine that blts letters... but if you want to get crazy:

You might want to try bit manipulation of a one dimensional array of 16 bit integers.  Since you're scanning through the arrays looking for a flag or not, a 1 or 0 bit would do the same.  I'd use a Uint16 to keep things simple, and use the remaining 6 bits to hold the resized font info.  You should then be able to manipulate the integers with bit opperations and can store the new size in the remaining 6 bits.  Create another array that will be your fade affect array, and in it just store the pixels that should be shaded.  A simple bit shifting to the right and left ANDed together and then the original XORed (cut out... which ever that is... I always get my opperations confused).  You should be left with the halo of the fade, effectively.  You can then use a routine to scan the two arrays and fill in the correct colors into your surface... though pixel by pixel is a bit slow I would assume.

0000110000000000 = 0x0C00
0001111000000000 = 0x1E00
0001111000000000 = 0x1E00
0011111100000000 = etc...
0011111100000000
0011001100000000
0011001100000000
0111001110000000
0111111110000000
0111111110000000
0110000110000000
1110000111000000
1100000011000000
1100000011000000
1100000011000000
0000000000000000

Uint16 a[16]={0x0C00,0x1E00,0x1E00,etc...}

Then it's just a matter of resizing and creating another array for the fade, which rather than doing the logic like you have, can be done faster by simple bit shifting.  I'd do this during startup and simply refer to them later, rather than calculating every time.

Again, bmp image blts of letters is probably easier.

- Joby
http://jobybednar.com
Give someone a program - frustrate them for a day.
Teach them how to program - frustrate them for a lifetime.



---------- Original Message ----------------------------------
From: Riccardo <t1t0 at tiscali.it>
Reply-To: sdl at libsdl.org
Date:  28 Jan 2003 12:00:54 +0100

>but the way is long: 
>an sdl_surface  pixel have 3 colors to blend with nearest 
>
>so I have a question: 
>Is this script too slow? 
>start<<< 
>#include <iostream> 
>using namespace std; 
>
>int main(){ 
>
>char a[16][10]={ 
>{' ',' ',' ',' ','#','#',' ',' ',' ',' '}, 
>{' ',' ',' ','#','#','#','#',' ',' ',' '}, 
>{' ',' ',' ','#','#','#','#',' ',' ',' '}, 
>{' ',' ','#','#','#','#','#','#',' ',' '}, 
>{' ',' ','#','#','#','#','#','#',' ',' '}, 
>{' ',' ','#','#',' ',' ','#','#',' ',' '}, 
>{' ',' ','#','#',' ',' ','#','#',' ',' '}, 
>{' ','#','#','#',' ',' ','#','#','#',' '}, 
>{' ','#','#','#','#','#','#','#','#',' '}, 
>{' ','#','#','#','#','#','#','#','#',' '}, 
>{' ','#','#',' ',' ',' ',' ','#','#',' '}, 
>{'#','#','#',' ',' ',' ',' ','#','#','#'}, 
>{'#','#',' ',' ',' ',' ',' ',' ','#','#'}, 
>{'#','#',' ',' ',' ',' ',' ',' ','#','#'}, 
>{'#','#',' ',' ',' ',' ',' ',' ','#','#'}, 
>{' ',' ',' ',' ',' ',' ',' ',' ',' ',' '}, 
>}; 
>for (int y=0; y<16; y++){ 
>
>  for (int x=0; x<10; x++){ 
>
>    cout << a[y][x]; 
>  } 
>  cout << '\n'; 
>} 
>
>int b[8][5]={{0}}; 
>
>for (int y=0; y<8; y++){ 
>
>  for (int x=0; x<5; x++){ 
>    if (a[y*2][x*2] == '#') 
>      b[y][x]=10; 
>
>    if ( x>0 && a[y*2][x*2-1] == '#') { 
>      if (b[y][x-1] == 0) 
>        b[y][x-1]=1; 
>      else 
>        b[y][x-1]++; 
>    } 
>    if ( x<5 && a[y*2][x*2+1] == '#') { 
>      if (b[y][x+1] == 0) 
>        b[y][x+1]=1; 
>      else 
>        b[y][x+1]++; 
>    } 
>    if ( y>0 && a[y*2-1][x*2] == '#') { 
>      if (b[y-1][x] == 0) 
>        b[y-1][x]=1; 
>      else 
>        b[y-1][x]++; 
>    } 
>    if ( y<8 && a[y*2+1][x*2] == '#') { 
>      if (b[y+1][x] == 0) 
>        b[y+1][x]=1; 
>      else 
>        b[y+1][x]++; 
>    } 
>  } 
>} 
>
>for (int y=0; y<8; y++){ 
>  for (int x=0; x<5; x++){ 
>    if (b[y][x]>7) 
>      cout << '#'; 
>    else if (b[y][x]>1) 
>      cout << '+'; 
>    else 
>      cout << ' '; 
>  } 
>  cout << '\n'; 
>} 
>
>} 
>>>>end
>
>
 
               




More information about the SDL mailing list