freetype
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ft] Drawing filled shapes with FreeType2


From: Marco Wertz
Subject: Re: [ft] Drawing filled shapes with FreeType2
Date: Sat, 25 Oct 2014 12:20:15 +0200

Tried it, but it still doesn't work correctly. FreeType2 is actually drawing something now but not in the correct way. The following code tries to draw a filled 320x240 rectangle into a 640x480 grayscale buffer. But it doesn't work correctly. The code below will fill the complete 640x480 buffer with 0xFF pixels although it's only supposed to fill 320x240 pixels. As you can see, I'm converting the coordinates to fixed point:
 
---------------------------------------------------------------------------------------
#define WIDTH 640
#define HEIGHT 480
 
FT_Stroker stroker;
FT_Outline outline;
FT_Vector v;
FT_Bitmap bm;
void *buffer = malloc(WIDTH * HEIGHT);
 
FT_Stroker_New(freetype_library, &stroker);

v.x = 0; v.y = 0; FT_Stroker_BeginSubPath(stroker, &v, FALSE);   
v.x = 320<<16; FT_Stroker_LineTo(stroker, &v);
v.y = 240<<16; FT_Stroker_LineTo(stroker, &v);   
v.x = 0; FT_Stroker_LineTo(stroker, &v);    
v.y = 0; FT_Stroker_LineTo(stroker, &v);
FT_Stroker_EndSubPath(stroker);
    
FT_Outline_New(freetype_library, 1024, 512, &outline);
FT_Stroker_Export(stroker, &outline);    
    
memset(&bm, 0, sizeof(FT_Bitmap));
bm.rows = HEIGHT;
bm.width = WIDTH;
bm.pitch = WIDTH;
bm.buffer = buffer;
bm.num_grays = 256;
bm.pixel_mode = FT_PIXEL_MODE_GRAY;

FT_Outline_Get_Bitmap(freetype_library, &outline, &bm);
---------------------------------------------------------------------------------------
 
Any further ideas?
 
Gesendet: Samstag, 25. Oktober 2014 um 03:13 Uhr
Von: "Mark Speir" <address@hidden>
An: "Marco Wertz" <address@hidden>, "address@hidden" <address@hidden>
Betreff: RE: [ft] Drawing filled shapes with FreeType2
It has been quite a while since I made anything with freetype, but I seem to remember the vector format being fixed point. If that is the case, you'll need to convert the coordinates.

From: Marco Wertz
Sent: 10/24/2014 14:55
To: address@hidden
Subject: [ft] Drawing filled shapes with FreeType2
 
Hi,
 
I'd like to use FreeType2 to draw some filled shapes (graphics primitives). To get started, I thought let's just try something very simple and have FreeType2 draw a filled rectangle. Unfortunately, it doesn't work. The code is supposed to draw a 640x480 filled rectangle into a memory buffer. However, FreeType2 draws only a very small rectangle that is maybe 16x16 into my memory buffer.
 
Here's my code:
 
---------------------------------------------------------------------------------------
#define WIDTH 640
#define HEIGHT 480
 
FT_Stroker stroker;
FT_Outline outline;
FT_Vector v;
FT_Bitmap bm;
void *buffer = malloc(WIDTH * HEIGHT);
 
FT_Stroker_New(freetype_library, &stroker);

v.x = 0; v.y = 0; FT_Stroker_BeginSubPath(stroker, &v, FALSE);   
v.x = WIDTH; FT_Stroker_LineTo(stroker, &v);
v.y = HEIGHT; FT_Stroker_LineTo(stroker, &v);   
v.x = 0; FT_Stroker_LineTo(stroker, &v);    
v.y = 0; FT_Stroker_LineTo(stroker, &v);
FT_Stroker_EndSubPath(stroker);
    
FT_Outline_New(freetype_library, 1024, 512, &outline);
FT_Stroker_Export(stroker, &outline);    
    
memset(&bm, 0, sizeof(FT_Bitmap));
bm.rows = HEIGHT;
bm.width = WIDTH;
bm.pitch = WIDTH;
bm.buffer = buffer;
bm.num_grays = 256;
bm.pixel_mode = FT_PIXEL_MODE_GRAY;

FT_Outline_Get_Bitmap(freetype_library, &outline, &bm);
---------------------------------------------------------------------------------------
 
Can anybody say what's wrong there? I've checked out the documentation already but I don't see what's wrong there... I've also checked the outline's boundaries using FT_Outline_Get_BBox() and it returns the correct dimensions, i.e. 0/0/640/480. However, FreeType2 only draws a few pixels.... why?
 
Thanks!
 
Marco

reply via email to

[Prev in Thread] Current Thread [Next in Thread]