int32_t u, v, du, dv, uslope, vslope;
#endif
#ifdef ZBUF
- int z, dz, zslope;
+ int32_t z, dz, zslope;
#endif
int32_t start_idx, end_idx;
int32_t u, v, du, dv, uslope, vslope;
#endif
#ifdef ZBUF
- int z, dz, zslope;
+ int32_t z, dz, zslope;
#endif
for(i=1; i<nverts; i++) {
/* go across the scanline interpolating if necessary */
while(x <= right[i].x) {
+ /*if(x == (180 << 8) && i == 174) {
+ asm("int $3");
+ }*/
#if defined(GOURAUD) || defined(TEXMAP) || defined(BLEND_ALPHA) || defined(BLEND_ADD)
int cr, cg, cb;
#endif
#endif
#ifdef ZBUF
- int cz = z;
+ int32_t cz = z;
z += zslope;
if(z <= *zptr) {
- *zptr = z;
+ *zptr++ = z;
} else {
#ifdef GOURAUD
r += rslope;
u += uslope;
v += vslope;
#endif
- goto skip_pixel;
+ /* skip pixel */
+ pixptr++;
+ zptr++;
+ x += 256;
+ continue;
}
- zptr++;
#endif
#ifdef GOURAUD
color = G3D_PACK_RGB(cr, cg, cb);
#endif
-#ifdef ZBUF
-skip_pixel:
-#endif
#ifdef DEBUG_OVERDRAW
*pixptr++ += DEBUG_OVERDRAW;
#else
int main(int argc, char **argv)
{
glutInit(&argc, argv);
- glutInitWindowSize(800, 600);
+ glutInitWindowSize(1280, 960);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
glutCreateWindow("Mindlapse");
static void mouse_button(int bn, int st, int x, int y)
{
+ int bit;
+
map_mouse_pos(&x, &y);
mouse_x = x;
mouse_y = y;
+ switch(bn) {
+ case GLUT_LEFT_BUTTON:
+ bit = 0;
+ break;
+ case GLUT_RIGHT_BUTTON:
+ bit = 1;
+ break;
+ case GLUT_MIDDLE_BUTTON:
+ bit = 2;
+ break;
+ }
+
if(st == GLUT_DOWN) {
- mouse_bmask |= 1 << bn;
+ mouse_bmask |= 1 << bit;
} else {
- mouse_bmask &= ~(1 << bn);
+ mouse_bmask &= ~(1 << bit);
}
}
static uint16_t *lowres_pixels;
static int lowres_width, lowres_height;
+static int use_zbuf;
+
+
struct screen *polytest_screen(void)
{
return &scr;
{
g3d_matrix_mode(G3D_PROJECTION);
g3d_load_identity();
- g3d_perspective(50.0, 1.3333333, 0.5, 100.0);
+ g3d_perspective(50.0, 1.3333333, 1.0, 10.0);
g3d_enable(G3D_CULL_FACE);
g3d_enable(G3D_LIGHTING);
g3d_polygon_mode(G3D_GOURAUD);
g3d_enable(G3D_TEXTURE_2D);
- g3d_enable(G3D_DEPTH_TEST);
+ g3d_clear_color(20, 30, 50);
}
static void update(void)
update();
- //memset16(fb_pixels, PACK_RGB16(20, 30, 50), FB_WIDTH * FB_HEIGHT);
- g3d_clear_color(20, 30, 50);
- g3d_clear(G3D_COLOR_BUFFER_BIT | G3D_DEPTH_BUFFER_BIT);
+ if(use_zbuf) {
+ g3d_clear(G3D_COLOR_BUFFER_BIT | G3D_DEPTH_BUFFER_BIT);
+ g3d_enable(G3D_DEPTH_TEST);
+ } else {
+ g3d_clear(G3D_COLOR_BUFFER_BIT);
+ g3d_disable(G3D_DEPTH_TEST);
+ }
+
g3d_matrix_mode(G3D_MODELVIEW);
g3d_load_identity();
draw_bsp(&torus_bsp, vdir[0], vdir[1], vdir[2]);
} else {
- //zsort_mesh(&torus);
+ if(!use_zbuf) {
+ zsort_mesh(&torus);
+ }
draw_mesh(&torus);
}
+ /* show zbuffer */
/*{
int i;
for(i=0; i<FB_WIDTH*FB_HEIGHT; i++) {
unsigned int z = pfill_zbuf[i];
- fb_pixels[i] = z;
+ fb_pixels[i] = (z >> 5) & 0x7e0;
}
}*/
+ cs_dputs(fb_pixels, 140, 0, use_zbuf ? "zbuffer" : "zsort");
+
/*draw_mesh(&cube);*/
swap_buffers(fb_pixels);
}
use_bsp = !use_bsp;
printf("drawing with %s\n", use_bsp ? "BSP tree" : "z-sorting");
break;
+
+ case 'z':
+ use_zbuf = !use_zbuf;
+ printf("Z-buffer %s\n", use_zbuf ? "on" : "off");
+ break;
}
}