Video functions
Functions for graphical output to the game-window.
- Structures and Enumerations
- Images
- Creating images
- VG3_image_create()
Create a new empty image. - VG3_image_text()
Create a new image containing text. - VG3_image_clone()
Clone an image as a new image (copy), also useful for saving as file. - VG3_image_clone_reference()
Clone an image as a reference, that is no new image, but returns the original image. - VG3_image_load()
Load an image from disk, must be a BMP-File. - Querying images
- VG3_image_getsize()
Get size of an image. - Copying images
- VG3_image_copy()
Copy an image onto the window or another image. - Unloading images
- VG3_image_unload()
Unload an image resp. decrement it's references incremented by VG3_image_clone_reference(). - Fonts
Fonts are defined in special fontfiles, like the standard fontfile 8x8.font located below share/.
- VG3_font_highdouble()
Set or remove default double-zooming of fonts when using VGAG3_VGAVERSION_HIGH. - VG3_fontsize()
Get fontsize and padding of a font. - VG3_fontchar_from_name()
Return a character-number from 0 to 255 of a symbol-fontfile via a defined name in the fontfile. - Simple drawing onto images or the window
- VG3_draw_clear()
Clear an image or the window. - VG3_draw_point()
Draw a pixel onto an image or the window. - VG3_draw_line()
Draw a line onto an image or the window. - VG3_draw_rect()
Draw a rectangle onto an image or the window. - VG3_draw_text()
Draw a text onto an image or the window.
(see also Complexer handling with text and input) - VG3_draw_colorchange()
Replace pixels of one color with another. - VG3_draw_colorize()
Colorize an image. - Miscellaneous
- VG3_replace_colormap()
Replace the colormap (for a window with 256 colors (VGAG3_VGAVERSION_LOW)).
This affects only images created/loaded after this function call. - VG3_image_attr_sum()
Get the sum of two image-attribute structures.
Image-attributes can be passed to some image-functions to act with a modified image, e.g. zooming or brightness.
Example
/* create an image with a text
* draw this image onto the window waiting for pressing space-key
*/
struct vg3_window *wstruct;
int winw, winh;
/* open window */
wstruct = VG3_window_new(argv[0], VGAG3_VGAVERSION_LOW, VGAG3_WINSCALE_BESTSCALE);
if (wstruct == NULL) { fprintf(stderr, "%s\n", VG3_error()); exit(1); }
/* get the size of the window */
VG3_window_getsize(wstruct, &winw, &winh);
/* draw text to an image and copy it onto the window */
{ const int do_i_want_a_corrected_rectangle = 0; /* set this to 0 or 1 */
struct vg3_image *imgptr;
struct vg3_text stxt;
struct vg3_rect rect;
int imgw, imgh;
/* +++ create an image and print a text to it +++ */
/* create an empty image with width+height 150x80 pixels */
imgw = 150;
imgh = 80;
imgptr = VG3_image_create(wstruct, imgw, imgh);
if (imgptr == NULL) { fprintf(stderr, "%s\n", VG3_error()); goto byebye; }
/* draw a rectangle to the borders of the image */
rect.x = 0;
rect.w = imgw;
rect.y = 0;
rect.h = imgh;
VG3_draw_rect(wstruct, imgptr, &rect, 0, VGAG3_COLOR_RED);
/* prepare the text structure,
* we want to display "Press space to exit"
* with the shipped fontfile "10x17.font"
*/
VGAG3_TEXT_ATTRIBUTES_SET(&stxt, "10x17.font", '\n', 0, "Press space to exit");
/* set the destination rectangle,
* we want to have a border of minimal 10 pixels on each side
*/
rect.x = 10;
rect.w = imgw - 20;
rect.y = 10;
rect.h = imgh - 20;
/* now we could do a dry-run drawing to get the corrected destination rectangle */
if (do_i_want_a_corrected_rectangle) {
rect = VG3_draw_text(wstruct, imgptr, &rect, ' ', &stxt, VGAG3_COLOR_RED, VGAG3_COLOR_BLUE, 1);
}
/* draw the text to the image */
VG3_draw_text(wstruct, imgptr, &rect, ' ', &stxt, VGAG3_COLOR_RED, VGAG3_COLOR_BLUE, 0);
/* +++ copy the image onto the window and wait for pressing space-key +++ */
/* copy the image right aligned and vertically centered to the window */
VG3_image_copy(wstruct, NULL, imgptr, winw - (imgw / 2), winh / 2, NULL, 0);
/* update window contents and wait for pressing space-key */
VG3_discard_input(wstruct);
for (;;) {
if (VG3_inputevent_update(wstruct) > 0) { break; }
if (VG3_key_ispressed(wstruct, VGAG3_KEY_SPACE, VGAG3_IS_NEW_PRESSED)) { break; }
VG3_window_update(wstruct, 0, 0);
VG3_wait_time(50);
}
VG3_discard_input(wstruct);
/* free the image */
VG3_image_unload(wstruct, imgptr);
}
/* if an error occurred after creating the window, close it before exiting */
byebye:
/* close window */
VG3_window_free(wstruct);