home *** CD-ROM | disk | FTP | other *** search
/ Merciful 5 / Merciful - Disc 5.iso / software / r / rtg_master / rtgmasterv21.0drivers.lha / driver / example1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-03-30  |  10.4 KB  |  287 lines

  1. /**************************************************
  2. * The C Version of the Example of the Generic     *
  3. * rtgmaster game videodriver. The Generic         *
  4. * rtgmaster videodriver is a linkable object file *
  5. * that works together with any C or ASM code and  *
  6. * should work okay as video driver for most       *
  7. * games. It already opens all needed libraries    *
  8. * and all that stuff. It is coded in C, but       *
  9. * internally calls a lot of ASM functions. It is  *
  10. * in fact used by some of the games mentioned     *
  11. * in the rtgmaster docs. This example is a simple *
  12. * example about how to use this driver.           *
  13. * The driver does not give you all features of    *
  14. * rtgmaster, but it is more easy to use for       *
  15. * people who never used libraries before.         *
  16. * You have to install the rtgmaster includes      *
  17. * to use it.                                      *
  18. **************************************************/
  19.  
  20. #include "vid_rtgm.h"
  21. #include <stdio.h>
  22.  
  23. /**************************************************
  24. * viddef_t describes the Screenmode structure of  *
  25. * the Display that is opened by the driver        *
  26. * (width, height, depth,...)                      *
  27. **************************************************/
  28.  
  29. viddef_t lvid;
  30.  
  31. /**************************************************
  32. * vmode_t contains data about ALL available modes.*
  33. **************************************************/
  34.  
  35. vmode_t *modes;
  36.  
  37. /**************************************************
  38. * vrect_t defines the rectangle for the CopyBuffer*
  39. **************************************************/
  40.  
  41. vrect_t myrect;
  42.  
  43. /**************************************************
  44. * This example uses the rtgmaster Screenmode      *
  45. * Requester. If you want to have an example of    *
  46. * how to use this driver WITHOUT a Screenmode     *
  47. * Requester, look at the ASM example. The ASM     *
  48. * example does not use a Screenmode-Requester.    *
  49. **************************************************/
  50.  
  51. /**************************************************
  52. * We want Screens listed in the requester from    *
  53. * 320x200 to 640x480, we want only Chunky8 (this  *
  54. * is 512 in the rtgmaster.library, look at        *
  55. * vid_rtgm.h or vid_rtgm.i to see a list of all   *
  56. * values.                                         *
  57. **************************************************/
  58.  
  59. struct MyMode mymode={320,200,640,480,512};
  60.  
  61. /**************************************************
  62. * 3*256 colorvalues of type 8 Bit R-value, 8 Bit  *
  63. * G value, 8 Bit B value, after them 1 Byte with  *
  64. * 0 to indicate end of structure.                 *
  65. **************************************************/
  66.  
  67. UBYTE pal[769];
  68.  
  69. /**************************************************
  70. * For Input Handling                              *
  71. **************************************************/
  72.  
  73. struct MyEvent *myevent;
  74.  
  75. int quit=0;
  76.  
  77. /**************************************************
  78. * Some variables to initialize the Backbuffer to  *
  79. * have something to play around with in the       *
  80. * example.                                        *
  81. **************************************************/
  82.  
  83. int f,g;
  84. UBYTE *test=0;
  85. UBYTE tester[9]={1,1,1,1,1,1,1,1,1};
  86.  
  87. void main()
  88. {
  89.  int x;
  90.  
  91. /**************************************************
  92. * We want to copy a 320x200 rectangle, later.     *
  93. **************************************************/
  94.  
  95.  myrect.x=192;
  96.  myrect.y=100;
  97.  myrect.width=64;
  98.  myrect.height=100;
  99.  
  100. /**************************************************
  101. * Init the modes. We want only LUT8 modes (8 Bit  *
  102. * modes. If we would like for example LUT8 or     *
  103. * RGB16 or RGB15 modes, we would provide          *
  104. * LUT8+RGB16+RGB15 as parameter. Look at          *
  105. * vid_rtgm.h for the possible constants. These    *
  106. * constants show you all colortypes available     *
  107. * on Amiga GFX Boards. Only 8 Bit is the same     *
  108. * on all boards. We want to use an invisible      *
  109. * pointer. We don't want to use an extra vram     *
  110. * buffer to be allocated (if we would want that,  *
  111. * the extra buffer would be available with the    *
  112. * variable extravram.                             *
  113. **************************************************/
  114.  
  115. /**************************************************
  116. * types :                                         *
  117. * MOVE16 = use Move16 for 8 Bit, rtgmaster        *
  118. * CopyRtgPixelArray for 15/16/24 Bit.             *
  119. * RTGMASTER = use rtgmaster CopyRtgPixelArray for *
  120. * all depths. (Move16 does not run on all hard-   *
  121. * ware, so be sure to allow this option. rtgmaster*
  122. * function is not much slower than the other      *
  123. * possible functions.                             *
  124. * MOVEM = use COPY_MOVEM_MOVEM                    *
  125. * BLITTER = Use the GFX Board Blitter to fake     *
  126. * Doublebuffering. This is quite slow.            *
  127. * DOUBLEBUFFER = Use Doublebuffering. This does   *
  128. * flicker on some machines.                       *
  129. * MOVE16 and MOVEM use RTGMASTER for 15/16/24 Bit,*
  130. * as MOVE16 and MOVEM do not yet support >8 Bit.  *
  131. **************************************************/
  132.  
  133. /**************************************************
  134. * Speed :                                         *
  135. * RTGMASTER = 1.0 (higher value = faster)         *
  136. * COPY_MOVE_MOVE without Src/Destination Offset   *
  137. * = 1.002                                         *
  138. * COPY_MOVEM_MOVEM = 1.215                        *
  139. * FCOPY = 1.227                                   *
  140. * Source of this driver is provided, so if you    *
  141. * want to change the copy function to be used,    *
  142. * simply modify the vid_rtgm.c and fcopy.s        *
  143. * files.                                          *
  144. **************************************************/
  145.  
  146. /**************************************************
  147. * 0 is no extra vram buffer, 1 is use extra vram  *
  148. * buffer. This buffer is free to do everything    *
  149. * with it you want to do with it.                 *
  150. **************************************************/
  151.  
  152. /**************************************************
  153. * Move16 and Rtgmaster use a Fastcopy Buffer for  *
  154. * lvid.buffer, the other two methods use a slower *
  155. * Videoram Buffer.                                *
  156. **************************************************/
  157.  
  158. /**************************************************
  159. * This function returns a list of all Screenmodes.*
  160. * The first screenmode will be overwritten by the *
  161. * data of the Screenmode chosen by the user. So   *
  162. * you can just use this data. If you give 0       *
  163. * instead of &mymode, no Screenmoderequester will *
  164. * be used and you get a list of ALL available     *
  165. * Screenmodes instead.                            *
  166. **************************************************/
  167.  
  168.  modes=RTGM_Init(LUT8,MOVEM,NOPOINTER,0,&mymode);
  169.  
  170. /**************************************************
  171. * Init the example Palette.                       *
  172. **************************************************/
  173.  
  174.  
  175.  for (x=0;x<=769;x++) pal[x]=0;
  176.  pal[3]=255;
  177.  
  178. /**************************************************
  179. * This driver only uses GFX Board Screens. If it  *
  180. * returns 0, probably no GFX Board Screenmode     *
  181. * was found (Pure AGA System ?)                   *
  182. **************************************************/
  183.  
  184.  if (modes!=0)
  185.     {
  186.  
  187.      lvid.width=modes->width;
  188.      lvid.height=modes->height;
  189.      lvid.rowbytes=modes->rowbytes;
  190.  
  191. /**************************************************
  192. * Set the Mode, open the Screen, set the Palette. *
  193. **************************************************/
  194.  
  195.      modes->setmode(&lvid,modes);
  196.  
  197.      modes->setpalette(&lvid,modes,pal);
  198.  
  199. /**************************************************
  200. * The Mainloop of this example consists of a      *
  201. * Buffer-Swapping (MOVE16 and RTGMASTER use       *
  202. * CPU-Copy, BLITTER uses Blitter-Copy,            *
  203. * DOUBLEBUFFER uses Doublebuffering (which does   *
  204. * not run flickerfree on some GFX Boards, support *
  205. * at least RTGMASTER !!!) To render the offscreen *
  206. * Buffer, render to lvid.buffer !!!               *
  207. * If you provide the parameter VID_WAIT_NONE, no  *
  208. * synching will be done. Synching is only needed  *
  209. * for DOUBLEBUFFERING, MOVE16, RTGMASTER and      *
  210. * BLITTER do not need it.                         *
  211. * I paint a red screen to use it in this example. *
  212. **************************************************/
  213.  
  214.  for (f=0;f<320;f++)
  215.  {
  216.   for (g=0;g<200;g++)
  217.   {
  218.    test=lvid.buffer+f+g*320;
  219.    *test=1;
  220.   }
  221.  }
  222.  
  223. /**************************************************
  224. * BeginDirectRect and EndDirectRect are used for  *
  225. * "Loading..." symbols and such stuff. They       *
  226. * backup the Display before writing to it. Max.   *
  227. * resolution for those two functions is 24x24.    *
  228. * They use simple Longword-Copy, so do not use    *
  229. * them for speed-relevant things.                 *
  230. * In the example a 3x3 symbol is painted.         *
  231. * They work in 8/15/16/24 Bit.                    *
  232. **************************************************/
  233.  
  234.  modes->begindirectrect(&lvid,modes,160,100,tester,3,3);
  235.  Delay(300);
  236.  modes->enddirectrect(&lvid,modes,160,100,3,3);
  237.  
  238.  while (quit==0)
  239.  {
  240.   modes->swapbuffers(&lvid,modes,&myrect,VID_WAIT_VSYNC);
  241.  
  242. /**************************************************
  243. * Sys_SendKeyEvent only reacts on Keypresses. If  *
  244. * you also want Mouseevents, you have to modify   *
  245. * the vid_rtgm.c or use rtgmaster functions to do *
  246. * so. Sys_SendKeyEvent returns RawKey codes or 0. *
  247. * It includes the KeyUp/KeyDown information.      *
  248. **************************************************/
  249.  
  250.   myevent=modes->sendkeyevents();
  251.  
  252. /***************************************************
  253. * Quit, if user presses CTRL q                     *
  254. ***************************************************/
  255.  
  256.   if ((myevent->rawkey==16)&&(myevent->qualifier&CONTROL)) quit=1;
  257.   if (myevent->mouse==MENUDOWN) printf("You pressed the Menukey!!!\n");
  258.   printf("X %i Y %i\n",myevent->x,myevent->y);
  259.  
  260.  }
  261.  
  262. /**************************************************
  263. * Before quitting, free all allocated resources.  *
  264. **************************************************/
  265.  
  266.   modes->closemode(&lvid,modes);
  267.  
  268.  }
  269.  
  270.  
  271. }
  272.  
  273. /**************************************************
  274. * NOTE:                                           *
  275. * This example is for 8 Bit. The 15/16/24 Bit     *
  276. * SwapBuffer work in the same way though.         *
  277. * There also are two more sets of functions.      *
  278. * BeginDirectRect copies a small rectangle to the *
  279. * Screen and saves the overwritten stuff to a     *
  280. * Backingbuffer. EndDirectRect writes the saved   *
  281. * rectangle back. This is for displaying a loading*
  282. * symbol (max. 24x24 pixel). These two functions  *
  283. * use a simple Longword-Copy.                     *
  284. * Look at the source for more information.        *
  285. **************************************************/
  286.  
  287.