// create the font, bitmap, hdc, etc.
hfont = CreateFont( 16x16 );
hbitmap = CreateBitmap( 256x256 monochrome );
hdc = CreateCompatibleDC( NULL );
SelectObject( hdc, hbitmap );
SelectObject( hdc, hfont );
SetTextColor( hdc, white );
SetBkColor( hdc, black );
SetTextAlign( hdc, top-left );
// fill the bitmap with blackness.
hbrush = GetStockObject( BLACK_BRUSH );
rect.right = rect.bottom = max_size;
FillRect( hdc, &rect, hbrush );
DeleteObject( hbrush );
// draw all 256 characters for the font.
for ( i = 0; i < 256; i++ )
{
x = i - ( i / 16 * 16 );
y = i / 16 * 16;
TextOut( hdc, x, y, ( char * )&i, 1 );
}
pbits = new unsigned char[256 * 256 / 8];
bmi.bmiHeader.biSize = sizeof( bmi.bmiHeader );
bmi.bmiHeader.biWidth = 256;
bmi.bmiHeader.biHeight = -256;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biSizeImage = 256 * 256 / 8; // its monochrome
bmi.bmiHeader.biXPelsPerMeter = 0;
bmi.bmiHeader.biYPelsPerMeter = 0;
bmi.bmiHeader.biClrUsed = 0;
bmi.bmiHeader.biClrImportant = 0;
GetDIBits( hdc, hbitmap, 0, 256, pbits, &bmi, DIB_RGB_COLORS );
DeleteDC( hdc );
DeleteObject( hfont );
DeleteObject( hbitmap );
now pbits should contain the monochrome bits for the font texture. However, the bitmap is messy with blotches all over the place, in a different manner each time I run the program.
Any ideas?
Thanks,
BlueGrass
win32 font texture creation
Hey. I''m trying to create a font texture, but the texture always comes out blotchy and messy, and memory ends up getting overwritten. Take a look at my (pseudo-pseudo-code) if you want. Everything that is pseudoish has already been checked out and has been found to work perfectly.
pbits = new unsigned char[256 * 256 / 8];
bmi.bmiHeader.biSizeImage = 256 * 256 / 8;
That''s technically the right way to allocate exactly enough memory for a 256x256 monochromeimage, but then you''d have to fill it by setting each bit, which GetDIBits does not, it sets each BYTE as filled or not, so remove the / 8 part and you''ll have enough memory
------------
- outRider -
bmi.bmiHeader.biSizeImage = 256 * 256 / 8;
That''s technically the right way to allocate exactly enough memory for a 256x256 monochromeimage, but then you''d have to fill it by setting each bit, which GetDIBits does not, it sets each BYTE as filled or not, so remove the / 8 part and you''ll have enough memory
------------
- outRider -
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement