☼ BitFox v1.0 BETA - 2015
Posted: Sun Feb 08, 2015 5:48 pm
Finally.
This is the only thing I can say after so long.
Sadly I had no chance to count the time elapsed during the project's development, but I am sure it varies between 2 and 3 years.
Fun Fact: I started this project, because of LcL.
________________________________________________________________________________________________________________________________________________
INTRO
Now let's get into some information.
Bitfox is not a game. It is not a header file nor source file. It is a LIBRARY a combination of header files, each one with different purpose.
We call them modules, because they are each connected to the library. Let's review quick these modules:
- The Native Module This is a module that defines all the type definitions that cannot be included in header files unless you want to crash gE. gE is more than capricious when it comes to file inclusion. It doesn't like list declarations or pointer typedefs etc.. The first thing you'll have to load is this module. You can simply load it as a source file from Game-Editor.
- The Loader The loader is what loads the "header files chain". It is a source file you load right after The Native Module. And that's it. Now you can use the full potential of Bitfox.
- Engine The engine is a helping module that contains some additional functions that don't belong to bitfox and are not dependent on it.
- Bitfox's Assertion Module Advanced error-debugging system developed internally and can be used widely to determine or notify about errors or crashes.
In the current stage of this module, it doesn't take into consideration the spam notifying.
- Foxy Graphical Interfaces or FoxyGI That library is a GUI toolkit interacting with Bitfox. The largest part of the improvement and fixing is there, because this module is very new and contains some not very well coded fragments.
- Bitfox Core Finally, the bitfox itself, containig functions for image manipulation and managment.
Since I started this project long ago, it has some serious readability issues and standard style violations, which will be handled in v2.
Of course, there is a merged version of the library. That one contains every single needed component, merged in one source file to be loaded.
Advantages and disadvantages of the merged version and the library version:
-Merged version is slow to load
-Merged version is slow to maintain
-Merged version may even crash on attempt for maintain
-Merged version is not updated with the most recent updates, but is fairly similar.
+Merged version is portable
+Merged version is less error-prone
VS.
-Library is not portable
-Library might cause some temporal complications
+Library is fast to load
+Library stores content and variables in memory. This could be a negative side too in some circumstances.
If you find yourself analyzing bitfox's core module you'll note that each line ends with a comment. This has several very positive benefits.
I even dedicated some time and efforts to create a GUI program (3rd party one, using GTK+ not gE) that advances, simplifies and automatizes the process of "Enclosing" (commending each line) files.
Benefits:
- It happens easy with the 3rd party program I've made
- I can quickly comment something wherever I feel to
- Especially if lots of comments and messages must be leaved
- Serves as a Script Editor margin, assuming you use the default size of 100 columns.
- Makes maintaining a worse experience. Yes this IS a positive side.
Bitfox is a combination of direct and data functions.
Almost all of the direct/data functions have this analogue.
The difference between data and direct is as follows:
data performs operation onto/from a buffered image.
direct performs operation directly to/from a file image.
Advantages and disadvantages of both:
-data functions don't spare memory.
-data functions are not well or not at all error checked
+data functions are faster
+some functions could be only performed using data
+data functions don't bother disk memory
+data functions are safe and don't interrupt your files.
VS.
-direct functions are slow
-direct functions don't spare disk memory
-direct functions are dangerous of affecting your data, without a restore
+direct functions are RAM-wise
+direct functions are better error-checked
+direct functions are easier for casting
________________________________________________________________________________________________________________________________________________
LICENSING
I was thinking for licensing but I've changed my mind. Do w/e you want with it. COPYRIGHT-FREE
________________________________________________________________________________________________________________________________________________
REFERENCE
A few other things you must know when developing along bitfox library.
To initialize bitfox you have to load bitfox_native.c followed by bitfox_loader.c
To remove bitfox from your game, remove the script on the contrary way. Start from bitfox_loader.c. Otherwise it'll crash.
You can't use any other global code after bitfox has been initialized, but bitfox_natives.c. At the end of bitfox_natives.c there is a dedicated place
where you global code goes.
Please, once after you load a game with initialized bitfox library, do not load any other as such, without restarting gE. This is what I mean by gE being capricious with header files inclusion.
________________________________________________________________________________________________________________________________________________
bitfox_datacpy
Syntax
- Code: Select all
void bitfox_datacpy (char *filename);
Description
Loads a bitmap image into the dynamically handled buffer BMPDATA.
The bitmap must exist in the local directory, where the .ged or .exe is located.
When you successfully load a bitmap image, the BMPCOUNT variable will increase with 1 and the resulted value-1 will be the "id" of this last successfully loaded image.
Therefore, the BMPCOUNT variable represents the number of bitmaps successfully loaded. BMPDATA[BMPCOUNT - 1]; will be the last successfully loaded image.
Return value
void
Example usage
- Code: Select all
bitfox_datacpy("picture.bmp");
________________________________________________________________________________________________________________________________________________
bitfox_dataclr
Syntax
- Code: Select all
void bitfox_dataclr (short id);
Description
Clears buffered image with id id from BMPDATA and decreases BMPCOUNT respectively. Note that when working with library instead of merged bitfox, BMPDATA will not be automatically cleared by Game-Editor.
Return value
void
Example usage
- Code: Select all
bitfox_datacpy("mypicture"".bmp"); // I want to load this
bitfox_dataclr(BMPCOUNT - 1); // But I've changed my mind
________________________________________________________________________________________________________________________________________________
bitfox_render_direct
Syntax:
- Code: Select all
void bitfox_render_direct (char *filename);
Description
Renders bitmap image directly onto canvas. The file must exist in the local directory and must be a valid x24-bit raw (non-compressed) bitmap image.
Return value
void
Example usage
- Code: Select all
bitfox_render_direct("picture.bmp");
________________________________________________________________________________________________________________________________________________
bitfox_render_data
Syntax
- Code: Select all
void bitfox_render_data (BYTE *bufferid);
Description
Renders image from BMPDATA or any other valid image buffer onto canvas.
Return value
void
Example usage
- Code: Select all
bitfox_datacpy("myimage.bmp");
bitfox_render_data(BMPDATA[BMPCOUNT - 1]);
bitfox_dataclr(BMPCOUNT - 1);
________________________________________________________________________________________________________________________________________________
bitfox_get_width_direct / bitfox_get_height_direct
Syntax
- Code: Select all
const DWORD bitfox_get_width_direct (char *filename);
const DWORD bitfox_get_width_direct (char *filename);
Description
Obtains width or height of a valid bitmap file.
Return value
width or height of bitmap specified by filename
Example usage
- Code: Select all
sprintf(text, "area is %u pixels wide and %u pixels high",
bitfox_get_width_direct("area.bmp"),
bitfox_get_height_direct("area.bmp");
________________________________________________________________________________________________________________________________________________
bitfox_get_width_data / bitfox_get_height_data
Syntax
- Code: Select all
DWORD bitfox_get_width_data (BYTE* bufferid);
Description
Obtains width or height of the buffered image bufferid.
Return value
width or height of the bufferid image given in pixels
Example usage
- Code: Select all
bitfox_datacpy("area.bmp");
sprintf(text, "area is %u pixels wide and %u pixels high",
bitfox_get_width_data(BMPDATA[BMPCOUNT - 1]),
bitfox_get_height_data(BMPDATA[BMPCOUNT - 1]));
bitfox_dataclr(BMPCOUNT - 1);
________________________________________________________________________________________________________________________________________________
bitfox_get_size_direct
Syntax
- Code: Select all
DDWORD bitfox_get_size_direct (char *filename, sz unit);
Description
Obtains size of the file provided by filename in bit, byte, kilobyte or megabyte.
Arguments
- filename name of the file from which you want to obtain size
- unit size unit. It could be: bit, byte, kbyte, mbyte
Example usage
- Code: Select all
sprintf(text, "area.bmp is %u kilobytes (%u bytes)",
bitfox_get_size_direct("area.bmp", kbyte),
bitfox_get_size_direct("area.bmp", byte));
________________________________________________________________________________________________________________________________________________
bitfox_get_pixels_direct
Syntax
- Code: Select all
DWORD bitfox_get_pixels_direct (char *filename);
Description
Obtains the number of pixels in the bitmap clarified by filename
Return value
Number of pixels of the bitmap. Which is simply its width * height.
Example usage
- Code: Select all
sprintf(text, "tree has total of %u pixels", bitfox_get_pixels_direct("tree.bmp"));
________________________________________________________________________________________________________________________________________________
bitfox_get_pixels_data
Syntax
- Code: Select all
DWORD bitfox_get_pixels_data (BYTE *bufferid);
Description
Obtains the number of pixels in the buffered bmp pointed by bufferid
Return value
Number of pixels of the bitmap. Which is simply its width * height.
Example usage
- Code: Select all
int pic;
bitfox_datacpy("pic.bmp");
pic = BMPCOUNT - 1;
sprintf(text, "pic has total of %u pixels", bitfox_get_pixels_data(BMPDATA[pic]));
bitfox_dataclr(pic);
________________________________________________________________________________________________________________________________________________
bitfox_find_xy
Syntax
- Code: Select all
DDWORD bitfox_find_xy (DWORD width, DWORD xpos, DWORD ypos);
Description
Returns the offset byte of a pixel, located on x/y of any bitmap with the width of width
Note that it has no protection against overriding, because it aims to be fast by performing only plain computations.
So please, pay attention to not give xpos higher than width and ypos higher than the height of the image you'll be applying the offset byte to.
Return value
Offset byte according to width, xpos, ypos
Example usage
- Code: Select all
int white_area;
RGB pixel = { PALE_TURQUOISE_COLOR };
bitfox_datacpy("white.bmp"); // Now BMPCOUNT has been increased with 1
white_area = BMPCOUNT - 1; // white_area becomes white.bmp's id
memcpy(&BMPDATA[white_area][bitfox_find_xy(bitfox_get_width_data(BMPDATA[white_area]), xmouse, bitfox_get_height_data(BMPDATA[white_area]) - ymouse)], pixel, sizeof pixel);
bitfox_dataclr(white_area);
This will put pixel with the color of PALE_TURQUOISE_COLOR in x/y corresponding to the mouse position. Another more cleaner version:
- Code: Select all
RGB pixel = { PALSE_TURQUOISE_COLOR };
DWORD area_id;
DWORD area_width = bitfox_get_width_direct("white.bmp");
DWORD area_height = bitfox_get_height_direct("white.bmp");
DDWORD area_xm_offset = bitfox_find_xy(area_width, xmouse, area_height - ymouse);
bitfox_datacpy("white.bmp");
area_id = BMPCOUNT - 1;
memcpy(&BMPDATA[area_id][area_xm_offset], pixel, sizeof pixel);
bitfox_render_data(BMPDATA[area_id]);
bitfox_dataclr(area_id);
________________________________________________________________________________________________________________________________________________
bitfox_getcolor_xy_direct
Syntax
- Code: Select all
RGB bitfox_getcolor_xy_direct (char *filename, DWORD xpos, DWORD ypos);
Description
Similarly to the previous function it locates the pixel at xy position, but this time, it returns the actual pixel on that position, instead of the offset byte.
Return value
RGB structure, with members R, G, B representing the pixel located at xy position in the image specified by filename
Example usage
- Code: Select all
// mycanvas - color picker - on rendered image
DWORD nature_height = bitfox_get_height_direct("nature.bmp");
RGB nature_xm_rgb;
screen_to_actor(&xmouse, &ymouse);
nature_xm_rgb = bitfox_getcolor_xy_direct ("nature.bmp", xmouse, nature_height - ymouse);
erase(nature_xm_rgb.R, nature_xm_rgb.G, nature_xm_rgb.B, 0);
This example demonstrates how you can return the color you are pointing by the cursor.
Here is how you can create this function by your own:
- Code: Select all
RGB my_getcolor_xy_direct (char filename[], DWORD xpos, DWORD ypos)
{
DWORD filename_width = bitfox_get_width_direct(filename);
FILE* fp = fopen(filename, "r");
RGB return_rgb;
if(!fp) ERROR("Error in %s | could not open %s", my_getcolor_xy, filename);
if(fseek(fp, bitfox_find_xy(filename_width, xpos, ypos), SEEK_SET)) ERROR(_ERR(7), my_getcolor_xy_direct, NULL);
if(fread(&return_rgb, sizeof return_rgb, 1, fp) != 1) ERROR("Error in %s | could not obtain pixel from %s", my_getcolor_xy, filename);
fclose(fp);
return return_rgb;
}
________________________________________________________________________________________________________________________________________________
bitfox_getcolor_xy_data
Syntax
- Code: Select all
RGB bitfox_getcolor_xy_data (BYTE *bufferid, DWORD xpos, DWORD ypos);
Description
As the direct analogue, it returns the pixel located at x/y coordinates of the buffered image pointed by bufferid
Return value
RGB structure filled with the color pointed by x/y (bitmaps are read from bottom to top, left to right - raster scan)
Example usage
Check the Collision Demo, down in the downloads section.
Open it with Game-Editor 1.4.1b, start the game. When the game starts, press space to let the ball fall down.
Move the ball with the right/left arrow keys and try to go through the entire level without falling on the platform
The ball collides with the grey color! You can use such mechanism in your games, if you want completely dataless games or advanced mechanisms where colors must be considered. Note that sometimes, for some people the ball collides with the downside grey borders instead of the upper. Must be, because of the stark FPS downfall in the moment of collision. If that happens to you, please try removing the touches counter (the canvas on the right edge)'s draw actor.
This is intended to demonstrate simple collision with color and it is achieved really easy. However.. it is created to only stop velocity (gravity) ie it will go through the walls
if you move the ball through them. If you want the ball to interact with walls as well, just modify the code a bit C:
- Code: Select all
background_color = bitfox_getcolor_xy_data(BMPDATA[0], xscreen, (level_height - yscreen)-10);
This grabs the color located near where the ball's bottom side lies. (Here instead of the constant 10, you can use bitfox_get_height_data(BMPDATA[1]);
1 is the ID of the ball.) Anyway. If you want physical response with walls, do the same with the ypos. I'll be glad to see people using bitfox to create advanced collision mechanisms and physical responses. Bitfox is powerful enough to be used in games instead of graphical files. Even animations are possible.
And while using bitfox instead of data, you'll be able to modify these graphics on many, many ways, without changing the default image file.
________________________________________________________________________________________________________________________________________________
bitfox_strtorgb
Syntax
- Code: Select all
RGB bitfox_strtorgb (char *str);
Description
Converts string, containg 3R 3G 3B into a RGB sturcture. As a very old function, it is coded really bad. A better implementation of all the functions you can expect in v2.
Return value
RGB structure, formed by the string str
Example Usage
- Code: Select all
// canvas
RGB rgb = bitfox_strtorgb("000 200 255");
erase(PIXEL(rgb), 0);
________________________________________________________________________________________________________________________________________________
bitfox_scanfor_direct
Syntax
- Code: Select all
DWORD bitfox_scanfor_direct (char *filename, BYTE r, BYTE g, BYTE b, int iDIRECTION, DWORD* counter);
Description
Returns the offset byte of the next occurrence of a pixel with the color of r, g, b in the bitmap file, specified by filename, following the direction specified by iDIRECTION and increases the DWORD variable, pointed by counter in case there is a match.
Arguments
- filename name of the bitmap file
- r, g, b pixel color to look for
- iDIRECTION whether to search forwards or backwards. Could be either backward or forward
- counter referenced integer to be increased in case of a match.
Return value
offset byte of the next match.
Example Usage
This.. is an old function that is obviously VERY bad coded. Though the idea is not bad, which is why It is not deprecated. The upcoming version will take care
for the actualization of many functions, but for now, please don't use that function or at least use the data analogue.
________________________________________________________________________________________________________________________________________________
bitfox_get_primecolor_direct
Syntax
- Code: Select all
RGB bitfox_get_primecolor_direct (char *filename);
Description
Returns the color that occurs the most in the bitmap file specified by filename. For performance and for better results use the data version. These functions throw
a big chunk of memory (about 67 megabytes) for a moment in order to perform the task on the fastest way possible. (an exponential lookup table). By the call of these functions, the variable gedMaxGameMem is set to (pow(256, 4)/2)-1;
Return value
RGB structure filled with the color "dominant"
Example Usage
- Code: Select all
RGB dominant = bitfox_get_primecolor_direct("sea.bmp");
sprintf(text, "sea.bmp has a main color of R%u G%u B%u", PIXEL(dominant));
________________________________________________________________________________________________________________________________________________
bitfox_get_primecolor_data
Considering that you've reached to read about this function, it is assumed that you already know to differ data/direct functions by their name and source argument (filename / bufferid) and apply them. To save some unneeded time, space and efforts.. I'll record the function's analogues only /if/ there is a significant different between them.
________________________________________________________________________________________________________________________________________________
bitfox_object_colorize
Syntax
- Code: Select all
void bitfox_object_colorize (Actor actor, BYTE r, BYTE g, BYTE b);
Description
This function rather belongs to foxyGI, so let's assume it just got there accidentally. It simply colorizes gE actor with the color of r, g, b
Return value
void
Example Usage
// on collision
- Code: Select all
RGB color = { INDIGO_COLOR };
bitfox_object_colorize(collide, PIXEL(color));
Colorizes the color of the actor we have collision with in the color of 75, 0, 130
________________________________________________________________________________________________________________________________________________
bitfox_create_direct
Syntax
- Code: Select all
void bitfox_create_direct (char *filename, DWORD width, DWORD height);
Description
creates a new blank image, saved as a filename with the dimensions of width and height
Return value
void
Example Usage
- Code: Select all
char *key = GetKeyState();
static bool image_created;
strcpy(text, "Press C to create a new blank image, with the dimensions of view");
if(key['C'] && image_created == FALSE) {
image_create = TRUE;
bitfox_create_direct ("view_area.bmp", view.width, view.height);
sprintf(text, "image has been created and has the size of %u kb", bitfox_get_size_direct("view_area.bmp", kbyte));
}
________________________________________________________________________________________________________________________________________________
bitfox_create_data
Syntax
- Code: Select all
void bitfox_create_data (DWORD width, DWORD height);
Description
Buffers a new blank image with the dimensions of width and height. Therefore, it Increases BMPCOUNT.
Return value
void
Example Usage
- Code: Select all
bitfox_create_data(rand(50) + 50, rand(50) + 50);
sprintf(text, "Random image has been buffered with id %u, width %u height %u", BMPCOUNT - 1, bitfox_get_width_data(BMPDATA[BMPCOUNT - 1], bitfox_get_height_data(BMPDATA[BMPCOUNT - 1]));
________________________________________________________________________________________________________________________________________________
bitfox_negate_colors_direct
Syntax
- Code: Select all
void bitfox_negate_colors_direct (char *filename);
Description
Negates the colors of the image filename
Return value
void
Example Usage
- Code: Select all
bitfox_negate_colors_direct("picture.bmp");
bitfox_render_direct("picture.bmp");
Result:
You can also use swapping if you know how to:
________________________________________________________________________________________________________________________________________________
bitfox_negate_colors_data
Considering that you've reached to read about this function, it is assumed that you already know to differ data/direct functions by their name and source argument (filename / bufferid) and apply them. To save some unneeded time, space and efforts.. I'll record the function's analogues only /if/ there is a significant different between them.
________________________________________________________________________________________________________________________________________________
bitfox_substract_colors_direct
Syntax
- Code: Select all
void bitfox_substract_colors_direct (char *filename, int method);
Description
This, also known as "desaturation" will take out the colors from the bitmap file filename. It will convert them in greyscale.
Arguments
- filename source image file
- method. Greymap method to base the desaturation on. Could be either GRAYMAP_MTD_AVE or GRAYMAP_MTD_LUM
Return value
void
Example Usage
- Code: Select all
bitfox_substract_colors_direct("picture.bmp", GRAYMAP_MTD_AVE);
bitfox_render_direct("picture.bmp");
This is the result of desaturation based on average:
And this is the result of desaturation based on luminosity.
________________________________________________________________________________________________________________________________________________
bitfox_substract_colors_data
Considering that you've reached to read about this function, it is assumed that you already know to differ data/direct functions by their name and source argument (filename / bufferid) and apply them. To save some unneeded time, space and efforts.. I'll record the function's analogues only /if/ there is a significant different between them.
________________________________________________________________________________________________________________________________________________
bitfox_colorize_direct
Syntax
- Code: Select all
void bitfox_colorize_direct (char *filename, BYTE r, BYTE g, BYTE b);
Description
Colorizes the bitmap filename with the specified color. It is similar to the desaturation except it doesn't convert to a grayscale but a specific color.
Simar visual results you can achieve by using bitfox_object_colorize on the canvas in which filename is rendered.
Return value
void
Example Usage
- Code: Select all
bitfox_colorize_direct("picture.bmp", 0, 255, 0);
bitfox_render_direct("picture.bmp");
Result:
Tips
You can use SEPIA_COLOR to apply sepia on the target image so as many othres such as GOLD_COLOR, SNOW_COLOR, ANTIQUE_WHITE_COLOR
________________________________________________________________________________________________________________________________________________
bitfox_colorize_data
Considering that you've reached to read about this function, it is assumed that you already know to differ data/direct functions by their name and source argument (filename / bufferid) and apply them. To save some unneeded time, space and efforts.. I'll record the function's analogues only /if/ there is a significant different between them.
________________________________________________________________________________________________________________________________________________
bitfox_bitfox_effect_data
Syntax
- Code: Select all
void bitfox_bitfox_effect_data (BYTE *bufferid, int color);
Description
Applies quantization over the buffered image bufferid. This function can be only applied by data.
Arguments
- bufferid the buffered source bitmap image.
- color has tobe BITFOX_STYLING(r, g, b), BITFOX_STYLING_HOT or BITFOX_STYLING_VANGOGH
Return value
void
Example Usage
- Code: Select all
bitfox_datacpy("picture.bmp");
bitfox_bitfox_effect_data( BMPDATA[0], BITFOX_STYLING_HOT );
bitfox_render_data(BMPDATA[0]);
bitfox_dataclr(0);
________________________________________________________________________________________________________________________________________________
bitfox_export_data
Syntax
- Code: Select all
char* bitfox_export_data (BYTE * extension);
Description
Exports a buffered image using EXPORT_FILE_NAME structure to leech the data from.
Arguments
- extension Reference to either the bmp or ppm member of a EXPORT_FILE_NAME structure. If you give it reference to the bmp member, that member must be initialized with 'B' or if you decide to export your image as ppm, give it reference to the ppm member that must be initialized with 'P'. The __Index member of the structure must be initialized with the id of the buffered image to be exported and the __Name with the target name of the file.
Return value
returns the name of the file successfully exported.
Example Usage
- Code: Select all
EXPORT_FILE_NAME __FN;
bitfox_datacpy("picture.bmp");
bitfox_substract_colors_data(BMPDATA[0]);
__FN.__Name = "picture_grayscale";
__FN.__Index = 0;
__FN.bmp = 'B';
__FN.PPM = 'P';
bitfox_export_data(&__FN.bmp);
bitfox_dataclr(0);
________________________________________________________________________________________________________________________________________________
bitfox_color_replace_data
Syntax
DDWORD bitfox_color_replace_data (BYTE *bufferid, BYTE source_r, BYTE source_g, BYTE source_b, BYTE target_r, BYTE target_g, BYTE target_b);
Description
Replaces the color specified by source_r, source_g and source_b in the buffered bitmap bufferid with the color specified by target_r, target_g and target_b. There is no direct analogue of this version.
Return value
Returns the pixels replaced
Example Usage
- Code: Select all
// Select by color tool example
DWORD picture_height = bitfox_get_height_data(BMPDATA[ID_OF_MY_PICTURE]);
RGB mousep_rgb, mousep_bgr;
screen_to_actor(&xmouse, &ymouse);
mousep_rgb = bitfox_getcolor_xy_data(BMPDATA[ID_OF_MY_PICTURE], xmouse, picture_height - ymouse);
mousep_bgr = RGBtoBGR(&mousep_rgb);
bitfox_color_replace_data(BMPDATA[ID_OF_MY_PICTURE], PIXEL(mousep_rgb), PIXEL(mousep_bgr));
bitfox_render_data(BMPDATA[ID_OF_MY_PICTURE]);
This example demonstrates how each color, pointed by the mouse of rendered image will be swapped from the entire image.
________________________________________________________________________________________________________________________________________________
Drawing functions
Syntax
- Code: Select all
void bitfox_setpen (BYTE r, BYTE g, BYTE b, double opacity, int pensize);
void bitfox_putpixel_direct (char * filename, int xpos, int ypos);
void bitfox_putpixel_data (BYTE *bufferid, DWORD xpos, DWORD ypos);
void bitfox_moveto (int xpos, int ypos);
void bitfox_lineto_direct (char *filename, int xpos, int ypos);
void bitfox_lineto_data (BYTE *bufferid, int xpos, int ypos);
Description
The reason why we don't explore them separately.. is basically because they behave on the same way as Game-Editor's drawing functions expect the target source is either filename or bufferid instead of canvas. One thing to note in the bitfox_setpen function is that the 4th argument is opacity NOT transparency. Which means if you want full transparent brush, use 0.
Return value
---
Example Usage
Everyone you could draw in canvas, now can be drawn from game-editor to bmps. You can draw your interface as a fixed bitmap image. You can integrate a pixel art program. Create and render a simple 200x200 nightfall gradient bitmap:
- Code: Select all
bitfox_create_data(200, 200);
{
EXPORT_FILE_NAME FN = {"gradient", 0, 'B', 'P'};
LOOP(i = 1, i < 201, i++)
{
bitfox_setpen(0, (i+1)/2, i, 1, 1);
bitfox_moveto(0, i);
bitfox_lineto_data(BMPDATA[0], 199, i);
}
bitfox_export_data(&FN.bmp);
bitfox_render_data(BMPDATA[0]);
bitfox_dataclr(0);
}
________________________________________________________________________________________________________________________________________________
Geometric Functions
bitfox_scale_data
Syntax
- Code: Select all
void bitfox_scale_data (DWORD id, DWORD destination_width, DWORD destination_height);
Description
Performs Nearest-Neighbor Interpolation (the same as the canvas's draw_from) over the buffered image with id id by scaling it to the destination_width and destination_height. Has no direct analog.
Return value
void
Example Usage
- Code: Select all
// scale picture with 50%
DWORD picture_width, picture_height;
bitfox_datacpy("picture.bmp");
picture_width = bitfox_get_width_data(BMPDATA[0]);
picture_height = bitfox_get_height_data(BMPDATA[0]);
bitfox_scale_data(0, picture_width + (picture_width / 2), picture_height + (picture_height / 2));
bitfox_render_data(BMPDATA[0]);
100%
150% Scaled
Tips:
- You can use topercent(partial, full); function to calculate how much % is partial from full
- You can use draw_from's scaling for quick scaling in real time and perform the actual scaling when the user decides to save the image.
- If you want scaling without loose of quality, you can draw your images using vectorization. Which is possible with the use of this project and soon I will write a documentation for it as well.
________________________________________________________________________________________________________________________________________________
bitfox_rotate_data
Syntax
- Code: Select all
BYTE* bitfox_rotate_data (BYTE *bufferid, float angle);
Description
Rotates the buffered image bufferid on angle angle. Has no direct analog.
Return value
a new buffered image without id represents the rotated version of the image given.
Example Usage
- Code: Select all
BYTE *rotated;
fgi_load("picture", 8);
rotated = bitfox_rotate_data(BMPDATA[0], 60.0);
fgi_render_any(rotated, 0, 0);
Check the collision demo. You can download it form the download section below. It demonstrates the implementation of a spinning slider. Completely dataless demo. Image is stored statically. Now you can do things like that, without the need to animate. The demo uses foxyGI, which will be reviewed later.
________________________________________________________________________________________________________________________________________________
bitfox_writetext_direct
Syntax
- Code: Select all
void bitfox_writetext_direct (char *filename, char *arloFont, char *string, BYTE colors[][3], int distance, int xpos, int ypos);
Description
Uses the custom-made "Arlo" method for decompression to write text with any font, size, color, position and distance. foxiGI has version for rendering it to a canvas instead, but foxyGI's functions will be documented later. While it was a great invention, it still has a bug that I previously though for fixed. Don't worry it will be handled in the next version of bitfox and this mechanism will be entirely revised.
Arguments
- filename the file name of the file you wish to apply text to
- arloFont a valid .bff font file to use. In the packet you only got "consola16.bff" but you can convert any font with the Font Converter Fiera.
Instructions inside the download. If the function doesn't find the .bff (bitfox font file) to load, gE will crash. This file uses custom compression "Arlo".
(I have even better ideas for compression - in the next version) - string String to write.
- An array of pixels. where arr[0] is the color for the first character from the string. arr[0][0] first character's red value. You can declare them as, static, because it will initialize them all to 0 (black color). See the example below.
- distance The distance between each character.
- xpos horizontal position for the text
- ypos vertical position for the text
Return value
void
Example usage
- Code: Select all
static BYTE colors[128][3] =
{
{ CYAN_COLOR }, { CYAN_COLOR }, { CYAN_COLOR }, { CYAN_COLOR }
};
bitfox_writetext_direct ("picture.bmp", "consola16.bff", "This is my picture", colors, 10, 50, 50);
________________________________________________________________________________________________________________________________________________
bitfox_writetext_data
Considering that you've reached to read about this function, it is assumed that you already know to differ data/direct functions by their name and source argument (filename / bufferid) and apply them. To save some unneeded time, space and efforts.. I'll record the function's analogues only /if/ there is a significant different between them.
________________________________________________________________________________________________________________________________________________
bitfox_draw_shapes_direct
Syntax
void bitfox_draw_shapes_direct (char *filename, char *shape, DWORD xpos, DWORD ypos, WORD xrad, float yrad);
Description
Draws a shape into the file specified by filename
Arguments
- filename a valid bitmap file
- shape "star", "square", "elipse" or "triangle"
- xpos Horizontal position for the shape
- ypos Vertical position for the shape
- xrad horizontal radius or size
- Vertical radius or angle of rotation
Return value
void
Example usage
- Code: Select all
// Creating a new blank (white) bitmao image 250x250
bitfox_create_direct("shapes.bmp", 250, 250);
// Drawing a large enough pixel to cover the entire image in black
bitfox_setpen(1, 1, 1, 1, 249);
bitfox_putpixel_direct("shapes.bmp", 1, 1);
// Drawing shapes.. Square will be drawn too huge, overriding width is intended
bitfox_setpen(255, 0, 255, 1, 1);
bitfox_draw_shapes_direct("shapes.bmp", "square", 120, 120, 15, 0.0);
bitfox_setpen(0, 255, 255, 0.2, 1);
bitfox_draw_shapes_direct("shapes.bmp", "star", 90, 90, 20, 0);
bitfox_setpen(0, 255, 255, 0.6, 2);
bitfox_draw_shapes_direct("shapes.bmp", "triangle", 150, 150, 20, 0);
bitfox_setpen(255, 255, 255, 0.2, 2);
bitfox_draw_shapes_direct("shapes.bmp", "elipse", 90, 90, 150, 150);
Result:
________________________________________________________________________________________________________________________________________________
Working on..
________________________________________________________________________________________________________________________________________________
KNOWN BUGS
Working on..
________________________________________________________________________________________________________________________________________________
TO-DO-LIST
- Putpixel is a bit slow when the pen is larger, during the way it is coded to draw the pensize pixel by pixel instead of line by line
- Readability fixing
- Styling fixing
- Re-writing Arlo compression and decompression (fixing bugs, a whole lot of optimizations..)
- Re-writing ColorPicker
- Fixing bugs related to image rendering in foxyGI
- Creating more GUI entities such as textboxes
- "Sterlic" image rendering (faster image rendering)
- Wanle SCORE implementation (Wanle is "System for Control Over the ResourcEs" that I created before. It boosts, analyzes and optimizes FPS)
- Supersampling (anti-aliasing)
- RLE and DEFLATE compression as well as png support with alpha channel
- Fragment i/o functions, part of foxyGI
- More filters
- Override protect for brushes has a dual-pixel error to be fixed
- Better shapes drawing algorithms
- Assertion Spam Control
________________________________________________________________________________________________________________________________________________
DOWNLOADS
BitFox v1.0 Beta.zip
Font Converter
Tutorial Collision.zip
Tutorial DressUp.zip
Tutorial Rotation.zip
bitfox_merged.c
picture.bmp
Foxy Graphical Interfaces.docx
sterlic.docx
(right click on a dress to change its color with the color selector in the DressUp demo/tutorial)
Note that not all the examples provided in the documentation are tested yet. I would say that most of them are not. Feel free to report if there is a problem with them, so as if you have any individual questions.