dos3d
diff src/test.c @ 1:0b7f840afe4a
palette management
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 21 Nov 2011 08:35:58 +0200 |
parents | f04884489bad |
children | 0e781cc43178 |
line diff
1.1 --- a/src/test.c Mon Nov 21 06:14:01 2011 +0200 1.2 +++ b/src/test.c Mon Nov 21 08:35:58 2011 +0200 1.3 @@ -24,10 +24,7 @@ 1.4 #include "mingl.h" 1.5 #include "timer.h" 1.6 #include "mouse.h" 1.7 - 1.8 -#define ROFFS 64 1.9 -#define GOFFS 128 1.10 -#define BOFFS 192 1.11 +#include "palman.h" 1.12 1.13 static int init(void); 1.14 static void shutdown(void); 1.15 @@ -42,6 +39,9 @@ 1.16 1.17 static unsigned char *fbuf; 1.18 1.19 +static int white_base, red_base, green_base, blue_base; 1.20 +static int grad_range; 1.21 + 1.22 static int use_vsync = 1; 1.23 static int under_windows = 0; 1.24 static unsigned long num_frm; 1.25 @@ -98,6 +98,7 @@ 1.26 static int init(void) 1.27 { 1.28 int i; 1.29 + struct palm_color *pal; 1.30 1.31 init_timer(under_windows ? 0 : 100); 1.32 1.33 @@ -109,12 +110,21 @@ 1.34 signal(SIGILL, sighandler); 1.35 signal(SIGABRT, sighandler); 1.36 1.37 - for(i=0; i<64; i++) { 1.38 - int x = i << 2; 1.39 - set_palette(i, x, x, x); 1.40 - set_palette(i + ROFFS, x, 0, 0); 1.41 - set_palette(i + GOFFS, 0, x, 0); 1.42 - set_palette(i + BOFFS, 0, 0, x); 1.43 + palm_add_color(255, 255, 255); 1.44 + palm_add_color(255, 0, 0); 1.45 + palm_add_color(0, 255, 0); 1.46 + palm_add_color(0, 0, 255); 1.47 + palm_build(); 1.48 + 1.49 + white_base = palm_color_base(255, 255, 255); 1.50 + red_base = palm_color_base(255, 0, 0); 1.51 + green_base = palm_color_base(0, 255, 0); 1.52 + blue_base = palm_color_base(0, 0, 255); 1.53 + grad_range = palm_color_range(); 1.54 + 1.55 + pal = palm_palette(); 1.56 + for(i=0; i<palm_palette_size(); i++) { 1.57 + set_palette(i, pal[i].r, pal[i].g, pal[i].b); 1.58 } 1.59 1.60 if(mgl_init(320, 200) == -1) { 1.61 @@ -125,7 +135,7 @@ 1.62 1.63 mgl_enable(MGL_CULL_FACE); 1.64 mgl_enable(MGL_SMOOTH); 1.65 - mgl_color_range(63); /* gradient range */ 1.66 + mgl_color_range(grad_range - 1); /* gradient range */ 1.67 1.68 mgl_enable(MGL_LIGHTING); 1.69 mgl_light_intensity(0, 1.0); 1.70 @@ -162,30 +172,20 @@ 1.71 1.72 switch(prim) { 1.73 case TORUS: 1.74 - mgl_index(GOFFS); 1.75 + mgl_index(green_base); 1.76 mgl_torus(1.0, 0.25, 16, 8); 1.77 break; 1.78 case SPHERE: 1.79 - mgl_index(BOFFS); 1.80 + mgl_index(blue_base); 1.81 mgl_sphere(1.0, 16, 8); 1.82 break; 1.83 case CUBE: 1.84 - mgl_index(ROFFS); 1.85 + mgl_index(red_base); 1.86 mgl_cube(1.0); 1.87 } 1.88 1.89 - /*mgl_begin(MGL_QUADS); 1.90 - mgl_index(ROFFS); 1.91 - mgl_color1f(1.0); 1.92 - mgl_vertex2f(-1, -1); 1.93 - mgl_vertex2f(1, -1); 1.94 - mgl_color1f(0.1); 1.95 - mgl_vertex2f(1, 1); 1.96 - mgl_vertex2f(-1, 1); 1.97 - mgl_end();*/ 1.98 - 1.99 if(!auto_rotate) { 1.100 - draw_cursor(fbuf, 320, 200, mx, my, 63); 1.101 + draw_cursor(fbuf, 320, 200, mx, my, white_base + grad_range - 1); 1.102 } 1.103 1.104 copy_frame(fbuf);