mgsLib  1.3
Mermaja's Graphic Screen. A simple C library to build Windows graphic applications from console programs.
images.c

This example shows how to use a background image for the screen and to load and display other bmp images, rotated and scaled. It has been used to create the fourth image of the documentation.

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <math.h>
#include "mgsLib.h"
int main()
{
int scr, imgSeagull, imgCrab;
// Create a screen with a nice seaside background
if ((scr = mgsCreateScreen(800, 600, "Using images", MGS_CWHITE, "seaside.bmp")) < 0)
exit(EXIT_FAILURE);
// Load the image of a seagull. Show an error if anything goes wrong
if ((imgSeagull = mgsLoadImage("seagull.bmp")) < 0)
mgsShowError(imgSeagull, "Error loading seagull image", MGS_EFWIN);
// Load now the image of a crab. Show an error if anything goes wrong
if ((imgCrab = mgsLoadImage("crab.bmp")) < 0)
mgsShowError(imgCrab, "Error loading crab image", MGS_EFWIN);
// Show the original seagull images, with and without background, near the right upper corner
mgsDisplayImage(scr, imgSeagull, 10, 10, 0);
mgsDisplayImage(scr, imgSeagull, 10, 100, 1);
// Place two rotated, big seagulls with the sky as background
mgsDisplayRotatedImage(scr, imgSeagull, 220, 102, 1.3, 1.3, -10, 1);
mgsDisplayRotatedImage(scr, imgSeagull, 480, 180, 1.2, 1.2, 45, 1);
// Place two more rotated seagulls on the sky
mgsDisplayRotatedImage(scr, imgSeagull, 250, 50, 1.0, 1.0, 30, 1);
mgsDisplayRotatedImage(scr, imgSeagull, 400, 80, 1.0, 1.0, -5, 1);
// End with two more small rotated seagulls to end the flock
mgsDisplayRotatedImage(scr, imgSeagull, 650, 30, 0.7, 0.7, -45, 1);
mgsDisplayRotatedImage(scr, imgSeagull, 460, 60, 0.7, 0.7, 60, 1);
// Show the original crab images, with and without background, near the right lower corner
mgsDisplayImage(scr, imgCrab, 10, 500, 0);
mgsDisplayImage(scr, imgCrab, 10, 420, 1);
// And place some crabs to feed the gulls
mgsDisplayRotatedImage(scr, imgCrab, 460, 360, 0.5, 0.5, 0, 1);
mgsDisplayRotatedImage(scr, imgCrab, 420, 340, 0.2, 0.2, 0, 1);
mgsDisplayRotatedImage(scr, imgCrab, 310, 350, 0.4, 0.4, 5, 1);
// Show the created image
// Wait for S to be pressed
puts("Press S to exit");
while(!mgsKeyPressed('S'));
}