deepstone
diff src/test.c @ 4:c3e0bccd673e
added texture mapping
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 21 Nov 2011 11:51:23 +0200 |
parents | 0e781cc43178 |
children | bce78aaafc68 |
line diff
1.1 --- a/src/test.c Mon Nov 21 10:16:09 2011 +0200 1.2 +++ b/src/test.c Mon Nov 21 11:51:23 2011 +0200 1.3 @@ -41,6 +41,7 @@ 1.4 static unsigned char *fbuf; 1.5 1.6 static struct texture *tex; 1.7 +static char *texfile; 1.8 1.9 static int white_base, red_base, green_base, blue_base; 1.10 static int grad_range; 1.11 @@ -113,16 +114,38 @@ 1.12 signal(SIGILL, sighandler); 1.13 signal(SIGABRT, sighandler); 1.14 1.15 - palm_add_color(255, 255, 255); 1.16 - palm_add_color(255, 0, 0); 1.17 - palm_add_color(0, 255, 0); 1.18 - palm_add_color(0, 0, 255); 1.19 - palm_build(); 1.20 1.21 - white_base = palm_color_base(255, 255, 255); 1.22 - red_base = palm_color_base(255, 0, 0); 1.23 - green_base = palm_color_base(0, 255, 0); 1.24 - blue_base = palm_color_base(0, 0, 255); 1.25 + if(mgl_init(320, 200) == -1) { 1.26 + fprintf(stderr, "mgl init failed\n"); 1.27 + return -1; 1.28 + } 1.29 + fbuf = mgl_framebuffer(); 1.30 + 1.31 + 1.32 + if(!texfile) { 1.33 + palm_add_color(255, 255, 255); 1.34 + palm_add_color(255, 0, 0); 1.35 + palm_add_color(0, 255, 0); 1.36 + palm_add_color(0, 0, 255); 1.37 + palm_build(); 1.38 + 1.39 + white_base = palm_color_base(255, 255, 255); 1.40 + red_base = palm_color_base(255, 0, 0); 1.41 + green_base = palm_color_base(0, 255, 0); 1.42 + blue_base = palm_color_base(0, 0, 255); 1.43 + 1.44 + tex = tex_gen_checker(64, 64, 3, 3, red_base, blue_base); 1.45 + } else { 1.46 + if(!(tex = load_texture(texfile))) { 1.47 + return -1; 1.48 + } 1.49 + 1.50 + palm_build(); 1.51 + get_texture_pixels(tex); 1.52 + 1.53 + mgl_enable(MGL_TEXTURE_2D); 1.54 + } 1.55 + 1.56 grad_range = palm_color_range(); 1.57 1.58 pal = palm_palette(); 1.59 @@ -130,12 +153,6 @@ 1.60 set_palette(i, pal[i].r, pal[i].g, pal[i].b); 1.61 } 1.62 1.63 - if(mgl_init(320, 200) == -1) { 1.64 - fprintf(stderr, "mgl init failed\n"); 1.65 - return -1; 1.66 - } 1.67 - fbuf = mgl_framebuffer(); 1.68 - 1.69 mgl_enable(MGL_CULL_FACE); 1.70 mgl_enable(MGL_SMOOTH); 1.71 mgl_color_range(grad_range - 1); /* gradient range */ 1.72 @@ -148,10 +165,6 @@ 1.73 mgl_load_identity(); 1.74 mgl_perspective(45.0, 320.0 / 200.0, 0.5, 100.0); 1.75 1.76 - if(!(tex = tex_gen_checker(64, 64, 3, 3, red_base, blue_base))) { 1.77 - fprintf(stderr, "failed to generate texture\n"); 1.78 - return -1; 1.79 - } 1.80 mgl_teximage(tex->width, tex->height, tex->pixels); 1.81 1.82 return 0; 1.83 @@ -358,6 +371,10 @@ 1.84 auto_rotate = !auto_rotate; 1.85 break; 1.86 1.87 + case 't': 1.88 + texfile = argv[++i]; 1.89 + break; 1.90 + 1.91 case 'v': 1.92 use_vsync = !use_vsync; 1.93 break;