/* zbuffer1.c:
A zbuffer() demo program that draws two intersecting planes.
This program requires the z-buffer option. */
#include <gl/gl.h> #include <gl/device.h>
main() { Device dev; short val; initialize(); while (TRUE) { if (qtest()) { dev = qread(&val); if (dev == ESCKEY) { zbuffer(FALSE); gexit(); exit(0); }
else if (dev == REDRAW) { reshapeviewport(); drawpolys(); }
}
}
}
initialize() {
int gid; float xmax,ymax;
prefposition(XMAXSCREEN/4, XMAXSCREEN*3/4, YMAXSCREEN/4, YMAXSCREEN*3/4); gid = winopen("zbuffer1"); winset(gid); winconstraints(); perspective(900, 1.34, 1.01, 500.0); lookat(-150.0, 90.0, 250.0, 50.0, 50.0, 0.0, 0); lsetdepth(0xC00000,0x3FFFFF); qdevice(ESCKEY); qdevice(REDRAW); qenter(REDRAW,gid); zbuffer(TRUE); }
drawpolys() {
zclear(); color(BLACK); clear(); color(YELLOW); pmv(0.0, 0.0, 100.0); pdr(100.0, 0.0, 100.0); pdr(100.0, 100.0, 100.0); pdr(0.0, 100.0, 100.0); pclos(); color(RED); pmv(0.0, 0.0, 50.0); pdr(100.0, 0.0, 50.0); pdr(100.0, 100.0, 200.0); pdr(0.0, 100.0, 200.0); pclos();
}
The lookat subroutine , pclos subroutine , pdr subroutine , perspective subroutine , pmv subroutine , zbuffer subroutine , zclear subroutine .