home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / MacWT 0.9 / wt Source / framebuf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-18  |  2.1 KB  |  104 lines  |  [TEXT/CWIE]

  1. /*
  2. **  MacWT -- a 3d game engine for the Macintosh
  3. **  © 1995, Bill Hayden and Nikol Software
  4. **  Free for non-commercial use - address questions to the e-mail address below
  5. **
  6. **  Mail:           afn28988@freenet.ufl.edu (Bill Hayden)
  7. **    MacWT FTP site: ftp.circa.ufl.edu/pub/software/ufmug/mirrors/LocalSW/Hayden/
  8. **  WWW Page:       http://grove.ufl.edu:80/~nikolsw
  9. **
  10. **    All of the above addresses are due to changes sometime in 1996, so stay tuned
  11. **
  12. **  based on wt, by Chris Laurel
  13. **
  14. **  This program is distributed in the hope that it will be useful,
  15. **  but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  17. */
  18.  
  19.  
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include "wt.h"
  23. #include "error.h"
  24. #include "wtmem.h"
  25. #include "framebuf.h"
  26. #include "graphics.h"
  27. #include "StringUtils.h"
  28. #include "MacWT.h"
  29.  
  30.  
  31. static void    SetShortMem(void *vptr, unsigned short c, unsigned long len);
  32.  
  33.  
  34.  
  35. Framebuffer *NewFramebuffer(short width, short height)
  36. {
  37.     Framebuffer *fb;
  38.  
  39.  
  40.     fb = (Framebuffer *)wtmalloc(sizeof(Framebuffer));
  41.     
  42.     fb->fb_width = width;
  43.     fb->fb_height = height;
  44.     
  45.     if (gTrueColor)
  46.         {
  47.         fb->pixels = nil;
  48.         fb->pixels16 = GetFramebufferMemory();
  49.         }
  50.     else
  51.         {
  52.         fb->pixels = GetFramebufferMemory();
  53.         fb->pixels16 = nil;
  54.         }
  55.      
  56.     return fb;
  57. }
  58.  
  59.  
  60. void ClearFramebuffer(Framebuffer *fb)
  61. {
  62.     short    rb=fb->fb_rbytes;
  63.     long    iterations = fb->fb_height * rb;
  64.  
  65.     if (!gTrueColor)
  66.         {
  67.         Pixel    *p=fb->pixels;
  68.  
  69.         if (gDrawFC)
  70.             SetMem(p, 0xd2, iterations);                // Reset fb to 8-bit cyan
  71.         else
  72.             {
  73.             iterations >>= 1;
  74.             SetMem(p, 0xfd, iterations);                // Reset fb to lt/dk gray
  75.             p += iterations;
  76.             SetMem(p, 0xfa, iterations);
  77.             }    
  78.         }
  79.     else
  80.         {
  81.         Pixel16    *p=fb->pixels16;
  82.  
  83.         if (gDrawFC)
  84.             SetShortMem(p, 0x001f, iterations);            // Reset fb to 16-bit cyan
  85.         else
  86.             {
  87.             iterations >>= 1;
  88.             SetShortMem(p, 0x2108, iterations);            // Reset fb to lt/dk gray
  89.             p += iterations;
  90.             SetShortMem(p, 0x6318, iterations);
  91.             }
  92.         }
  93. }
  94.  
  95.  
  96. static void    SetShortMem(void *vptr, unsigned short c, unsigned long len)
  97. {
  98.     short    *ptr;
  99.  
  100.     ptr = (short *)vptr;
  101.     while (len--) *ptr++ = c;
  102. }
  103.  
  104.