home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Supreme Volume 6 #1
/
swsii.zip
/
swsii
/
099
/
TGE101.ZIP
/
TGEDEMO.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-02-04
|
8KB
|
292 lines
#include <alloc.h>
#include <conio.h>
#include <dir.h>
#include <process.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "tge.h"
#ifndef __TURBOC__
#define random(num) (rand() % num)
#define randomize() srand((unsigned)time(NULL))
#endif
#define ESC 27
void lineDemo(void);
void putPixelDemo(void);
void putImageDemo(void);
void drawRectDemo(void);
void filledRectDemo(void);
void paletteDemo(void);
void cycleColour(int *colour, int *increment);
void forceExtension(char *filename, char *extension);
void signOff(void);
unsigned char tgeLogo[] = {
24,0,9,0,
0,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,
0,0,0,1,1,0,0,0,0,1,1,0,0,0,0,0,0,1,1,0,0,0,0,0,
0,0,1,1,0,0,0,0,1,1,0,0,1,1,1,0,1,1,1,1,1,0,0,0,
0,0,1,1,0,0,0,0,1,1,0,0,0,1,1,0,1,1,1,1,0,0,0,0,
0,1,1,0,0,0,0,1,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0,0,
0,1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,0,
1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,0,0,0
};
int count;
int colour;
int maxx, maxy;
int colours;
void far *bground;
void main(int argc, char *argv[])
{
if (argc < 2) /* Parse command line */
{
printf("TGEDEMO v1.1 Copyright (c) 1993 by Matthew Hildebrand\n\n"
" Usage: TGEDEMO driver\n\n");
exit(1);
}
forceExtension(argv[1], ".DRV"); /* Load the specified driver */
if (!loadGraphDriver(argv[1]))
{
printf("Error loading \"%s\".\n\n", argv[1]);
exit(1);
}
maxx = _grSystemDrv->maxx; /* set up variables */
maxx++;
maxy = _grSystemDrv->maxy;
maxy++;
colours = _grSystemDrv->colours;
colours++;
bground = farmalloc(imageSize(0,0,23,8));
if (!initGraphics()) /* initialize graphics mode */
{
printf("Unable to initialize graphics hardware.\n\n");
exit(1);
}
lineDemo(); /* run the demos */
putPixelDemo();
putImageDemo();
drawRectDemo();
filledRectDemo();
paletteDemo();
deInitGraphics(); /* restore text and quit */
unloadGraphDriver();
signOff();
}
void lineDemo(void)
{
randomize();
for (; !kbhit();)
line(random(maxx), random(maxy), random(maxx), random(maxy), random(colours));
if (getch() == ESC)
{
deInitGraphics();
exit(0);
}
colour = random(colours);
for (count=maxx-1; count>-1; count-=2) {
line(0, 0, maxx-count-1, maxy-1, colour);
line(maxx-1, maxy-1, count, 0, colour);
}
clearGraphics(random(colours));
}
void putPixelDemo(void)
{
randomize();
for (; !kbhit();)
{
for (count=0; count<2000; count++)
putPixel(random(maxx), random(maxy), random(colours));
}
if (getch() == ESC)
{
deInitGraphics();
exit(0);
}
}
void putImageDemo(void)
{
int x, y;
x = maxx / 2;
y = maxy / 2;
randomize();
while (!kbhit())
{
getImage(x, y, x+23, y+8, bground);
putImage(x, y, tgeLogo);
putImage(x, y, bground);
if (random(201) >= 100)
x = x<maxx-1 ? x+1 : x;
else
x = x ? x-1 : x;
if (random(201) >= 100)
y = y<maxy-1 ? y+1 : y;
else
y = y ? y-1 : y;
}
if (getch() == ESC)
{
deInitGraphics();
exit(0);
}
clearGraphics(random(colours));
}
void drawRectDemo(void)
{
randomize();
for (; !kbhit();)
drawRect(random(maxx), random(maxy), random(maxx), random(maxy), random(colours));
if (getch() == ESC)
{
deInitGraphics();
exit(0);
}
clearGraphics(random(colours));
}
void filledRectDemo(void)
{
randomize();
for (; !kbhit();)
filledRect(random(maxx), random(maxy), random(maxx), random(maxy), random(colours));
if (getch() == ESC)
{
deInitGraphics();
exit(0);
}
clearGraphics(0);
}
#define MAXINC 7
void paletteDemo(void)
{
int redInc, greenInc, blueInc;
int red=0, green=0, blue=0;
colour = 1;
redInc = random(MAXINC);
redInc++;
greenInc = random(MAXINC);
greenInc++;
blueInc = random(MAXINC);
blueInc++;
randomize();
for (count=maxx-1; count>-1; count-=2) {
line(0, 0, maxx-count-1, maxy-1, colour);
line(maxx-1, maxy-1, count, 0, colour);
cycleColour(&red, &redInc);
cycleColour(&green, &greenInc);
cycleColour(&blue, &blueInc);
setPaletteReg(0, red, green, blue);
if (kbhit())
break;
}
if (kbhit())
getch();
}
void cycleColour(int *colour, int *increment)
{
*colour += *increment;
if (*colour < 0)
{
*colour = 0;
*increment = random(MAXINC) + 1;
}
else if (*colour > 255)
{
*colour = 255;
*increment *= -1;
}
}
void forceExtension(char *filename, char *extention)
{
char fileDrive[MAXDRIVE];
char fileDir[MAXDIR];
char fileFile[MAXFILE];
char fileExt[MAXEXT];
fnsplit(filename, fileDrive, fileDir, fileFile, fileExt);
if (strcmpi(fileExt, extention))
fnmerge(filename, fileDrive, fileDir, fileFile, extention);
}
void signOff(void)
{
#ifndef __POWERC
static char notice[] = {
"┌──────────────────────────────────────────────────────────────────────────────┐"
"│ The Graphics Engine v1.01 Demo Copyright (c) 1993 by Matthew Hildebrand │"
"╞══════════════════════════════════════════════════════════════════════════════╡"
"│ Although this demo is not particularly gripping, the power of The Graphics │"
"│ Engine can be seen when it is run with different drivers: the demo uses the │"
"│ same code to access different graphics modes. │"
"│ │"
"│ Even if you don't want device-independence, but only one graphics mode, The │"
"│ Graphics Engine's optimized assembler routines may be used. │"
"│ │"
"│ The Graphics Engine costs a mere $20; paid users are entitled to use any or │"
"│ all of the code, without royalties. Refer to TGE.DOC for details. │"
"╞══════════════════════════════════════════════════════════════════════════════╡"
"│ Matthew Hildebrand, 4 College St., St. Catharines, Ontario, Canada, L2R 2W7 │"
"└──────────────────────────────────────────────────────────────────────────────┘"
"\n"
};
printf(notice);
#else
printf("┌──────────────────────────────────────────────────────────────────────────────┐");
printf("│ The Graphics Engine v1.01 Demo Copyright (c) 1993 by Matthew Hildebrand │");
printf("╞══════════════════════════════════════════════════════════════════════════════╡");
printf("│ Although this demo is not particularly gripping, the power of The Graphics │");
printf("│ Engine can be seen when it is run with different drivers: the demo uses the │");
printf("│ same code to access different graphics modes. │");
printf("│ │");
printf("│ Even if you don't want device-independence, but only one graphics mode, The │");
printf("│ Graphics Engine's optimized assembler routines may be used. │");
printf("│ │");
printf("│ The Graphics Engine costs a mere $20; paid users are entitled to use any or │");
printf("│ all of the code, without royalties. Refer to TGE.DOC for details. │");
printf("╞══════════════════════════════════════════════════════════════════════════════╡");
printf("│ Matthew Hildebrand, 4 College St., St. Catharines, Ontario, Canada, L2R 2W7 │");
printf("└──────────────────────────────────────────────────────────────────────────────┘\n");
#endif
}