[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Freetype] Windows code displaying garbage - any help?
Jason C. Weaver
Re: [Freetype] Windows code displaying garbage - any help?
Thu, 12 Jun 2003 11:38:11 -0700 (PDT)
Thanks for taking the time to respond with such a well-written, full-of-info
note. I really
appreciate it and it has given me some good places to work on. And, yes, you
are exactly correct
- some of your code is in what I had posted (along with other posted code I
mangled together in a
Frankenstein-ist way!) In case I stepped on any toes, I apologize. My
intention was not to sell
this off as my own code. I had collected it all by reviewing the list history
in hopes of
answering my questions without the need to post to the list and bug anyone. :)
I finally did get a function working that shows a char on the screen as a
Windows BMP, with a
small amount of help from the Paul (the grief-giver). Thanks again for
pointing me in the right
direction, Paul. I was close but Paul gave me the key piece I was missing - to
face->glyph->bitmap.pitch when calculating the offset into
Let me digest all your suggestions and hopefully get this working. Again,
thank you very much for
your detailed suggestions. I will post my final working code (eventually) so
that the next person
who comes to the group with this question can find the answer the same place I
orignally looked -
in the newgroup digest and save everyone from having this converation again. ;)
Chris (aka Jason, BTW)
--- Peter Montgomery <address@hidden> wrote:
> I was looking through your code when I suddenly realized that part of it
> was mine! I recognized my macro, the comment about padding, and my
> coding and variable naming style. I hunted through my sent email and
> found the message I posted to this list regarding making a Windows BMP
> from a FreeType bitmap. Because of this, I realized I better jump in a
> see what I can do.
> 1 - Have you tried saving the bitmap that FreeType generates and loading
> it into a Paint Program as a raw image? I find this sometimes help to
> make sure that the data you have is formatted the way you think it is.
> Many paint programs let you load a raw image where there is no header,
> and you manually tell it the dimensions and the number of channels.
> 2 - You mention that it's "much bigger than you expected." How big did
> you expect it to be? I can't even find the code where you set the size
> of the FreeType bitmap. Is this all the code or just a part of it?
> 3 - Where do you actually render the font? I'm not a FreeType stud (I
> basically got it working in my app and haven't touched it since) but in
> looking over my code, there is a call to "FT_Load_Glyph( )" which does
> the actual rendering of the font letter. I find no such call in your
> 4 - You say you want to render at 300, 300. The way to do this is to
> render the font into the FreeType bitmap at offset 0,0 and then BLT the
> bitmap into the window at 300,300. It appears that you are rendering at
> 300, 300 (e.g. the calls to "pen_x = 300;" and "pen_y = 300;") and then
> BLTing at 300, 300 as well.
> 4 - Are you rendering aliased or non-aliased fonts? You are creating a
> Windows BMP that with a single channel of 8 bits per pixel, but you are
> creating a color palette that has only two entries. A two entry palette
> implies aliased font rendering. I assume that this:
> for( int h = 0; h < 2; h++ )
> i.bmiColors[h].rgbBlue = h;
> i.bmiColors[h].rgbGreen = h;
> i.bmiColors[h].rgbRed = h;
> is the code where you create the palette. Making things worse, you are
> creating a palette with the values of 0 and 1, which would make for a
> very dark image. If you re-read my original post, you'll see that I
> say, "Having said all of that, remember that even though you view it is
> a B&W image, Windows views it as a 256 color image. This means you'll
> need to create a palette with RGB entries that go from 0 to 255."
> 5 - Assuming you are rendering anti-aliased fonts, then FreeType returns
> a B&W image that has a single channel with 8 bits per pixel. Because of
> this, the "easiest" way to view it is to create a palletted BMP (as
> described above) rather than copying the data into a true RGB image.
> However, your BMP header is a bit of a mess as it is describing some
> sort of half palette/half RGB image. You set "biClrUsed" to zero, but
> this implies an image with no palette. Here's some info on the BMP
> biClrUsed Specifies the number of color indexes in the color table
> actually used by the bitmap. If this value is 0, the bitmap uses the
> maximum number of colors corresponding to the value of the biBitCount
> You need to create a palette with 256 entries and specify 256 for the
> "biClrUsed" member of the structure.
> 6 - You do a "CreateDIBSection" call and pass the parameter
> "DIB_RGB_COLORS". This means you are creating a BMP with no palette,
> but you NEED a palette to get an image that displays properly. You need
> to pass "DIB_PAL_COLORS" instead.
> In general, things are a bit of a mess. So, here's my recommended plan
> of action:
> 1 - Before you do anything else, do what I say at the top of this
> message. Either tweak your code or write a new (simple) app that
> renders a FreeType bitmap into a file (as a stream of rendered bytes)
> and then use a paint program to load it as a raw image.
> 2 - Re-read the BMP spec since it seems that you are not fully
> comprehending all the details of the file format. It's a pain, but you
> need to dot your "i"s and cross you "t"s to get a properly formatted BMP
> that will work.
> 3 - Someone suggested that you manually create a BMP and BLT that first.
> Do it. His suggestion to create a square is a good one in that you can
> write some simple code to draw two horizontal lines and then a loop to
> create the verticals. Make sure that the square is smaller than your
> entire BMP so that you can check to see if it is centered properly.
> 4 - Make the manually created image SMALL! A BMP that's 10 X 10 pixels
> with an 8 X 8 square in it should do the trick. This way you can look
> at the values in the debugger and see that they are correct if it
> doesn't BLT as you expect. With regards to the guy who gave you grief,
> regardless of how he said it, his basic point is correct - get into the
> debugger and check to make sure the image is what you think it is.
> 5 - Once you KNOW that's working, then start working on converting a
> FreeType image into a BMP image and BLT'ing it to screen.
> Tackle the job in small steps where you can verify that each step is
> working before proceeding on to the next. It seems to me that you are
> not intimately familiar with Windows BMP images and the MANY
> idiosyncrasies they have. You need to get familiar with them before you
> can be confident that your code will ever work properly.
> Freetype mailing list
Do you Yahoo!?
Yahoo! Calendar - Free online calendar with sync to Outlook(TM).
RE: [Freetype] Windows code displaying garbage - any help?, Pedriana, Paul, 2003/06/02