hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Fri Jul 31, 2009 10:28 pm Post subject: [C] Some GDI routines and fun |
|
|
Simple wrapper for CreateDibSection and handling drawing on it. Can load any 32 bit bitmap (GIMP can save these). The functions expect the XRGB padding, so you'll probably get garbage or crash if you try anything else. Can handle alpha blending and image scaling. Also has some crap I wrote to test shit in the archive, a starfield, a Sierpinski triangle and just drawing / scaling some pictures.
If you like mind numbing, nasty code, then this may be up your alley. I commented some of it, but uhhh...
http://www.filefront.com/14169499/gdi_jamboree.rar
Maybe someone will find it useful for making a trainer with pretty effects or something, I dunno.
edit: i also noticed a mistake in the creation of the starfield.
| Code: | X_RANGE = SCREEN_WIDTH << 2;
Y_RANGE = SCREEN_HEIGHT << 2 ; |
Should be a division (or a right shift)
The 3d to 2d routine assumes the center of the screen as 0, 0. You want to create the stars in a range around the center, like -64 to 64...
Also, the 3d to 2d formula should read:
| Code: | float temp_x = ((stars[index].x / stars[index].z) * FOV_X_SKEW) + (SCREEN_WIDTH >> 1);
float temp_y = ((stars[index].y / stars[index].z) * FOV_Y_SKEW) + (SCREEN_HEIGHT >> 1); |
You will probably have to crank up the FOV_..._SKEW to compensate.
The FOV_SKEW is the distance to the 45 degree mark from the center, as such, lower numbers will make it very narrow.
Half width / height (and higher) should produce a non distorted image. Maybe I should give it a more descriptive name...
edit2:
Also another stupid logic problem in the alpha blending where a value of 0 would simply function as 255... hurrr.
shoould be...
| Code: | if(alpha == 0x00)
return;
if(alpha == 0xFF)
*dst = color; |
while you're at it you can just add
| Code: | if(alpha == 0x00)
return; |
To the start of the bitmap routines so it can simply skip all the work as nothing is necessary. This was enough to bring my CPU usage while drawing a ton of images from 80% on one core to basically nothing.
Last edited by hcavolsdsadgadsg on Wed Aug 05, 2009 3:42 am; edited 4 times in total |
|