Tips and Tricks
Table of contents
- Ways to determine the version of VgaGames3
- How to compile a game with required files of VgaGames3 onboard
- How to save a screenshot of the current window
Contents
- Ways to determine the version of VgaGames3
-
Via command-shell with vgagames3-config --version
-
On compiling with the definition VGAG3_VERSION
-
On runtime with the function VG3_version()
- How to compile a game with required files of VgaGames3 onboard
If the game shall run on a computer without having installed VgaGames3,
the required VgaGames3-files must be copied locally and shipped with the game.
Following must be done:
- compile with vgagames3-config --libs, not with --libspath
- the files must be copied using vgagames3-config --copylocal
- the game needs two environment variables before being executed: VGAG3_PREFIX and LD_LIBRARY_PATH
With vgagames3-config --copylocal a new directory vgag3
will be created at the local path, which contains all required files.
To execute the game, VGAG3_PREFIX must contain the local path to this directory vgag3
and LD_LIBRARY_PATH must contain the lib-directory beneath this directory vgag3.
E.g. if the game-excutable is located in the path containing vgag3, execute game with:
export VGAG3_PREFIX=vgag3 export LD_LIBRARY_PATH=vgag3/lib ./game
See also Tutorial 1. - How to save a screenshot of the current window
To make a screenshot into a new image, use function VG3_image_clone(),
using the parameters rmem and rsize.
Following function creates a bitmap-file (.bmp) and writes the current window-content into it:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <vgagames3.h> /* make a screenshot of actual window and save it into BMP-file * @param wstruct window-struct * @param filename to save screenshot into * * (without error checking because of code-clarity) */ void make_screenshot(void *wstruct, const char *filename) { char *rmem; size_t rsize; void *img; /* clone window into image and get image data into rmem with size=rsize */ img = VG3_image_clone(wstruct, NULL, NULL, &rmem, &rsize); if (img != NULL) { FILE *ffp; /* write image data into file */ ffp = fopen(filename, "w"); if (ffp != NULL) { fwrite(rmem, 1, rsize, ffp); fclose(ffp); } /* clean up */ free(rmem); VG3_image_unload(wstruct, img); } }