Main Page | Data Structures | File List | Data Fields | Globals

ex10.c

00001 /*=========================================================================
00002 
00003 GFX EXAMPLE CODE - #10
00004         "shaded triangle"
00005 
00006 Copyright (C) 2004  Rafael de Oliveira Jannone
00007 
00008 This example's source code is Public Domain.
00009 
00010 WARNING: The author makes no guarantees and holds no responsibility for 
00011 any damage, injury or loss that may result from the use of this source 
00012 code. USE IT AT YOUR OWN RISK.
00013 
00014 Contact the author:
00015         by e-mail : rafael AT jannone DOT org
00016         homepage  : http://jannone.org/gfxlib
00017         ICQ UIN   : 10115284
00018 
00019 =========================================================================*/
00020 
00021 #include <stdlib.h>
00022 #include "line.h"
00023 
00024 int low[MODE2_HEIGHT];
00025 int high[MODE2_HEIGHT];
00026 u_char *buf;
00027 
00028 main() {
00029         int c, l;
00030         u_char i;
00031         surface_t surf;
00032 
00033         buf = (u_char*)malloc(MODE2_MAX);
00034         surf.data.ram = buf;
00035 
00036         set_color(15, 1, 1);
00037         set_mode(mode_2);
00038         fill(MODE2_ATTR, 0x31, MODE2_MAX);
00039 
00040         c = 0;
00041 
00042         // paint polygon
00043         for (;;) {      
00044                 memset(buf, MODE2_MAX, 0);      // yeah... crap
00045                 memset(low, MODE2_HEIGHT << 1, 64);     // yeah... crap
00046                 memset(high, MODE2_HEIGHT << 1, 0);     // yeah... crap
00047 
00048                 // calculate polygon
00049                 calculate_side(128 + c, c + 20, 40, 180 - c, low, high);
00050                 calculate_side(128 + c, c + 20, 255 - c, 96, low, high);
00051                 calculate_side(255 - c, 96, 40, 180 - c, low, high);
00052                 c = (c + 4) & 63;
00053                 i = (c + 15) >> 4;
00054 
00055                 for (l = 20; l < 180; l++) {
00056                         surface_hline(&surf, low[l], l, high[l], DITHER(i, l));
00057                 }
00058                 vwrite(surf.data.ram, 0, MODE2_MAX);
00059                 if (get_trigger(0))
00060                         break;
00061         }
00062 
00063         set_mode(mode_0);
00064 }

Generated on Thu Mar 3 19:55:01 2005 for GFX lib by  doxygen 1.4.1