home *** CD-ROM | disk | FTP | other *** search
/ TopWare 18: Liquid / Image.iso / liquid / top1159 / demo.txt next >
Encoding:
Text File  |  1993-10-26  |  14.9 KB  |  360 lines

  1. DEMO.TXT
  2.  
  3. If you  know how  to program  using Turbo C,  you can create a demo of
  4. your own for SuperGraphix!
  5.  
  6. We recommend  you print this document out.  To print this document, at
  7. the dos prompt type:
  8.  
  9. C:\>type demo.txt>prn
  10.  
  11.  
  12. The visual  requirements for a demo are simple.  It simply must be fun
  13. to look  at,   and should take time to display.  The rule of thumb is:
  14. If it  would make  a good screen saver,  it would make a good graphics
  15. demo.
  16.  
  17. Getting Your Demo Added To SuperGraphix
  18. ---------------------------------------
  19. Write a  "driver independent" graphics demo using Turbo C 2.0 (or C++)
  20. using .BGI  (Borland  Graphics  Interface)  standard  function  calls.
  21. Examples are putpixel(), line(), circle(), clearviewport etc.  "Driver
  22. independent"  also   means  that  your  demo  should  look  the  same,
  23. regardless of the graphics mode (or resolution) used.
  24.  
  25. SuperGraphix uses  a .BGI  driver with a resolution from 320x200 up to
  26. 1024x768,  thus your demo must run on a wide variety of resolutions.
  27.  
  28. The beauty  of using standard (BGI) graphics functions is that someone
  29. with an  CGA system  can write  a CGA demo for example, then take that
  30. same source  code to a VGA machine,  compile and link it (with another
  31. .BGI driver),   and run it in VGA mode.  Again, the reason for this is
  32. that the  BGI functions  are  standard!  (i.e.  putpixel(),  circle(),
  33. line(), clearviewport()  etc.)   Another reason  is because  most .BGI
  34. graphics functions are "upward compatible".
  35.  
  36. For example:
  37.  
  38. setcolor(RED);
  39. line(0,0,maxx,maxy);
  40.  
  41. will place diagonal red line,  starting at coordinate 0,0 to maxx,maxy
  42. regardless of  the resolution  or BGI  used.   It doesn't matter which
  43. system they are compiled on, as long as (at compile/link time) a valid
  44. BGI driver is being used.
  45.  
  46. NOTE: To  say that  all BGI  functions will  work regardless,  is  not
  47. completely correct.  There are graphics functions which will only work
  48. with certain  drivers and  modes.   The function "setallpalette" is an
  49. example (will work with VGA and EGA but not CGA).  In general however,
  50. most functions  are common  to all  modes and  drivers.  Functions for
  51. changing the  palette (which  are usually  graphic mode  specific) are
  52. covered later.   Also covered later,  is a list of functions which are
  53. recommended and not recommended due to incompatibility.
  54.  
  55. SuperGraphix uses  a non-standard  superVGA VESA  driver that does not
  56. come with  Turbo C called SVGA256.BGI by Jordan Hargrave (you can look
  57. for it  on GEnie  and CompuServe,  but again,   it is not necessary to
  58. have a  superVGA driver  to create  a demo).   Look for the file title
  59. SVGABGI.ZIP or SVGABGI4.ZIP.  You can also use "VGA256.BGI" (available
  60. on many  BBSes, CompuServe  and GEnie)  for writing  256 color  demos.
  61. VGA256.BGI is  contained in VGA256.ZIP or VGA256.ARC.  VGA256.BGI is a
  62. 320x200x256 color  driver only.   SVGABGI.BGI  supports 320x200  up to
  63. 1024x768x256 colors.
  64.  
  65. Your source  code/demo,   which you  will send,  will be combined with
  66. SuperGraphix for all to see.  When the user selects your demo from the
  67. "Select Demo"  menu,   a box  will pop  up with  your name  in it,  so
  68. you'll receive all the credit for your demo.
  69.  
  70. SuperGraphix uses  a 256  color driver,   but you need not use all 256
  71. colors in  your demo,   nor even use a 256 color driver to create your
  72. demo. As  mentioned above,  you can use Turbo C's own graphics drivers
  73. to create  your demo.  When OUR  superVGA  graphics  driver  (BGI)  is
  74. initialized,   the first  16 colors (0 through 15) are set to standard
  75. colors.   You can thus program your demo on a VGA or EGA system (using
  76. only 16  colors).   The "New  York City"  demo is an example of a demo
  77. that could  have been  written using  any BGI  driver,  including  the
  78. standard VGAEGA.BGI which comes with Turbo C.
  79.  
  80.  
  81. ======================================================================
  82.  
  83. The following is a list of requirements and tips:
  84.  
  85. *   Your demo will be called from our main program.  When your demo is
  86. complete,   you will send us your source code via disk (or upload) and
  87. we will  append it  to the  end of our source code.  Your demo will be
  88. involked from  the main  program. Therefore,   a  single function call
  89. should start your demo.  Your function should be of type "void".
  90.  
  91. *  Use common graphics functions.  Examples of functions are:
  92.  
  93. putpixel();
  94. getpixel();
  95. setcolor();
  96. circle();
  97. line();
  98. lineto();
  99. setlinestyle();
  100. drawpoly();
  101. clearviewport();
  102. cleardevice();
  103. arc();
  104. bar();
  105. rectangle();
  106. pieslice();
  107. setrgbpalette();  /* In VGA256.BGI or SVGA256.BGI */
  108.  
  109. I have  not tested  the getimage();  and  putimage();  functions  with
  110. SVGA256.BGI (the  driver used  with SuperGraphix),   so I cannot vouch
  111. for them.  The following functions are not recommended:
  112.  
  113. setactivepage(); /* I don't think the SVGA modes have 2 pages anyway*/
  114. setvisualpage();
  115. setpalette();
  116. setallpalette();
  117. outtextxy();
  118.  
  119. To maintain  compatibility with  the wide  range of  video cards  that
  120. SVGA256.BGI works  with,   please do  not use  any of  your own custom
  121. functions with assembly code,  interrupts,  or direct screen writes.
  122.  
  123. *  When programming your demo,  keep your initgraph() and closegraph()
  124. functions separate from your demo.  This will make it easier for me to
  125. incorporate your  demo into  the main()  program.   One function  call
  126. should start your demo.  Our source, combined with your code will look
  127. like the following:
  128.  
  129.  
  130. main()                     /* OUR MAIN PROGRAM!!!   */
  131. { a=getch();
  132.   switch(a){
  133.    case '1':
  134.      initgraph(Gm,Gd,'');  /* OUR call to init graphics system */
  135.      yourdemo();           /* CALL TO YOUR DEMO */
  136.      closegraph();         /* OUR main program will closegraph() */
  137.      break;
  138. }
  139.  
  140. void yourdemo()            /* YOUR source code/demo */
  141. {  int x,y;
  142.    putpixel(x,y);          /* Send these functions only! */
  143. } /* End Your Demo */
  144.  
  145.  
  146. *   Your demo  should repeat until a key is pressed.  Do not handle or
  147. remove the  character from  the keyboard  buffer.  Users will have the
  148. option to  "rotate the  palette" should  they press  the "R" key.  The
  149. main() will check to see which key is pressed.
  150.  
  151. *   I recommend  that  you  do  NOT  use  specific  (absolute)  screen
  152. coordinates.   Your demo will be run on several different systems with
  153. different resolutions (from 320x200 up to 1024x768).  Your demo should
  154. look the  same regardless  of the resolution selected,  though this is
  155. not always  necessary.  To help scale your demo,  two global variables
  156. have been  defined:    maxx,  and  maxy  (both  type  int).      Since
  157. coordinates 0,0  are common  to all graphics modes,  you may use them.
  158. This should  be the  only exception however.  You can use these global
  159. variables to "scale" your demo so that it looks the same regardless of
  160. the resolution selected.
  161.  
  162. For example,   in  the "New York" demo,  I calculated a unit length as
  163. follows:
  164.  
  165. L=maxx / 20;  /* L is 1/20th of the horizontal screen. */
  166.  
  167. L (for  length) can thus be used to draw an object which will look the
  168. same,  regardless of the screen resolution selected.  For example:
  169.  
  170. circle(maxx/2,maxy/2,L);
  171.  
  172. will create  a circle  that will  look the  same,  regardless  of  the
  173. resolution selected.   Remember  however that not all demos have to be
  174. scaled.   Don't kill  yourself attempting  to get scale something that
  175. will give the same effect unscaled.
  176.  
  177. *   Those wishing  to create  256 color  demos: I  recommend that  you
  178. obtain VGA256.BGI (VGA256.ZIP) or SVGA256.BGI (SVGABGI4.ZIP) from your
  179. local BBS,   GEnie  or CompuServe.   These are true 256 color drivers.
  180. These  drivers   have  standard   BGI  functions   including   line();
  181. putpixel(); setcolor(); circle(); clearviewport(); etc.
  182.  
  183. There are  three main  differences however  that allow  you to program
  184. with 256 colors.
  185.  
  186. First,   the setcolor();  function can  take values  from 0 to 255 (in
  187. contrast to  standard VGA  which can  only be  0 to 15).  As mentioned
  188. above,   the first  16 of  the 256  colors (0-15)  are set to standard
  189. colors to provide compatibility.
  190.  
  191. The second  difference in  256 color  programming is  the  putpixel();
  192. function.   The putpixel()  function will  take values  from 0 through
  193. 255.  For example:
  194.  
  195. putpixel(0,0,255);
  196.  
  197. You may  ask yourself,   what is color number 255 anyway? This palette
  198. entry can  be any  color you  wish it  to be  and is changed using the
  199. third unique function.
  200.  
  201. The third unique function is called "setrgbpalette();".  This function
  202. allows you to change the "palette" from its default.
  203.  
  204. A "palette"  is a  look up  table that tells the computer what color a
  205. pixel is.   For  example, with the standard default palette,  color 15
  206. is white.  If you called "setcolor(15);" and then "circle(10,10,10);",
  207. a white  circle would  be displayed  centered  at  screen  coordinates
  208. 10,10.   The computer sort of "looks up" what color 15 is set to.  You
  209. can change  the actual  color that  palette entry 15 is assigned to by
  210. using the setrgbpalette() function.
  211.  
  212. For example:
  213.  
  214. setrgbpalette(15,63,0,0);
  215.  
  216. will change  palette entry  15 RED!  The general form of this function
  217. is:
  218.  
  219. setrgbpalette(i,r,g,b);
  220.  
  221. where i  is the  palette entry,  and r,g,b are the red, green and blue
  222. values for  that palette entry.  Each r,g,b value can be between 0 and
  223. 63. Note: Any subsequent call to setcolor(WHITE) will actually set the
  224. color to red.  This is because "WHITE" is #DEFINEd as the number 15.
  225.  
  226. The following statement:
  227.  
  228. setrgbpalette(1,0,0,63);
  229.  
  230. changes palette  entry 1  to BLUE since the red and green value is set
  231. to 0 and the blue value is set to 63 (its highest possible value).  If
  232. you then used the following statements:
  233.  
  234. setcolor(1);
  235. circle(10,10,10);
  236.  
  237.  
  238. a blue  circle  would  be  placed  around  screen  coordinates  10,10!
  239. Remember though,  that you do not want to use actual (absolute) screen
  240. coordinates.
  241.  
  242. Changing the  palette creates  spectacular effects.  For example,  the
  243. SuperBall demo is a simple function as follows:
  244.  
  245. void SuperBall()
  246. { int i,r,g,b;
  247.   r=0;
  248.   g=0;
  249.   b=0;
  250.   for(i=1;i<64;i++){         /* this loop will set palette entries */
  251.      setrgbpalette(i,r,g,b); /* 1 through 63 */
  252.      r=r+1;   /* an increasing r and b value makes magenta */
  253.      g=g+1;
  254.   }
  255.   while(!kbhit()){
  256.     x=random(maxx);    /* pick a random x,y */
  257.     y=random(maxy);
  258.     for(i=1;i<64;i++){ /* start at color 1 (dark magenta) and  */
  259.        setcolor(i);    /* increase to 63 (light magenta). */
  260.        circle(x,y,i);  /* close circles look like balls */
  261.     }
  262.   } /* end while */
  263. }   /* end function */
  264.  
  265. This function  will put  magenta balls  on your screen.  Note that the
  266. function only  uses 63  of the 256 palette entries.  256 color palette
  267. demos  are   achieved  through   the  use   of  these   two  functions
  268. (setrgbpalette(); and setcolor();).
  269.  
  270. Note:   Notice that setrgbpalette() will only set one palette entry at
  271. a time.   Functions  do exist  that will  set the whole palette in one
  272. shot, but these functions are not standard.  Remember that Borland, as
  273. far as  I know,  does not  make a  256 color  driver,  therefore  this
  274. function has  not been  standardized.   If  you  obtain  "VGA256.BGI",
  275. source code  is included  to set the entire palette at once (contained
  276. withing the  BGIDEMO.PAS file).  Look for the procedure "setdacblock".
  277. "SVGA256.BGI" also  includes separate  source code which allows you to
  278. set the  entire palette.  The function is called "setvgapalette256()".
  279. Since these  functions are  not standard,  try not to use them in your
  280. demo.   If you  must use these functions,  please contact the original
  281. author listed at the end of this document.
  282.  
  283. In general,   the  "setrgbpalette()" function (which is common to both
  284. VGA256.BGI AND  SVGA256.BGI) will  be fast  enough to  set  the  whole
  285. palette prior  to your  demo.   If you  would like  to  "rotate"  your
  286. palette (a process that requires the whole palette be set at once),  a
  287. function written by the author will help you do so (described next).
  288.  
  289.  
  290.  
  291. After each  call to  initgraph(),   the palette  is set to its default
  292. palette.   You may  write your  own code to change the palette to suit
  293. your demo.   Two  functions written  by the  author, are available for
  294. your use.  They are  setrainbowpal() and  setfourshadespal()  and  are
  295. contained in the file PALETTE.C.
  296.  
  297. setrainbowpal() is  used in  the "Prism" demo. Palette entry 1 through
  298. 127 are  set to  the colors of a rainbow.  Starting with palette entry
  299. 1, the  colors slowly turn from red to yellow to green to cyan to blue
  300. to magenta, and by palette entry 127, back to red. This function is of
  301. type void. To call, just use:
  302.  
  303. setrainbowpal();
  304.  
  305. This function is particularly effective when used in demos such as:
  306.  
  307. setrainbowpal();      /* set palette */
  308. for(i=1;i<128;i++){   /* set up loop */
  309.   setcolor(i);        /* cycle up palette */
  310.   DoSomthing();       /* put something on screen */
  311. }
  312.  
  313. setfourshadespal() splits  the 256  colors into 4 shades of one color.
  314. 1-63 are  various shades  of magenta  (1  being  the  darkest  and  63
  315. lightest), 64-127 are shades of green, 128-191 are shades of blue, and
  316. finally 192-256  are shades of red.  setfourshadespal() is used in the
  317. ribbon demo.
  318.  
  319. Included with  SuperGraphix is  the source code for setfourshadespal()
  320. and setrainbowpal().   You must be in a 256 color graphics mode to use
  321. these functions.
  322.  
  323. A function  is also available to "rotate" the palette.  The "Triangle"
  324. demo makes  use of this function (among others).  The palette rotation
  325. function available to you is as follows:
  326.  
  327.  
  328. void rotatep(start,end);
  329.  
  330. where start  is the first (lowest in palette) color used in your demo,
  331. and "end" is the last color used.  For example:
  332.  
  333. rotatep(1,128);
  334.  
  335. will rotate  palette entries  1 through  128.   You may call rotatep()
  336. after the  completion of  the drawing  phase of  your demo.   See  the
  337. "Triangle" demos to see how this looks as part of the demo.
  338.  
  339.  
  340. * Be original! Please do not copy someone else's work.
  341.  
  342. * The producer (me) reserves the exclusive right to accept or reject a
  343. demo.   In addition,  the producer reserves the right to change or add
  344. to the demo or source code to give the demo the best possible look.
  345.  
  346. *   Finally,  don't worry about all the details!  Though I have listed
  347. many tips  and "requirements",   if  you design  a working demo and it
  348. looks good,  send it!  The original code for "Plasma" for example, was
  349. actually programmed  in Pascal.   If  the demo is good,  I will gladly
  350. rewrite and fine tune the code.
  351.  
  352. *   If you  have any questions,  or source code you wish to send,  you
  353. can reach  the author in several ways.  Write:  Joseph W. Szarmach Jr.
  354. 2295 Nichols  Ave. Stratford,  CT 06497.   Via  GEnie: J.SZARMACH. Via
  355. CompuServe 76436,3107.   Or  can reach me voice at: (203) 933-3633.  I
  356. prefer source code via disk,  or private upload to GEnie (J.SZARMACH).
  357.  
  358. Don't  forget  to  include  your  number  or  address  (home  address,
  359. CompuServe,  or GEnie address) in case I have any questions.
  360.