1 /* StonerView: An eccentric visual toy.
2 Copyright 1998-2001 by Andrew Plotkin (erkyrath@eblong.com)
3 http://www.eblong.com/zarf/stonerview.html
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation. No representations are made about the suitability of this
10 software for any purpose. It is provided "as is" without express or
14 /* Ported away from GLUT (so that it can do `-root' and work with xscreensaver)
15 by Jamie Zawinski <jwz@jwz.org>, 22-Jan-2001.
23 #include "stonerview.h"
25 static GLfloat view_rotx = -45.0, view_roty = 0.0, view_rotz = 0.0;
26 static GLfloat view_scale = 4.0;
30 init_view(int wireframe_p)
32 stonerview_state *st = (stonerview_state *) calloc (1, sizeof(*st));
34 st->wireframe = wireframe_p;
35 st->num_els = NUM_ELS;
36 st->elist = (elem_t *) calloc (st->num_els, sizeof(*st->elist));
38 st->osctail = &st->oscroot;
40 /* for trackball, two-sided lighting and no face culling */
41 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
43 glEnable(GL_LIGHTING);
45 glEnable(GL_DEPTH_TEST);
47 glEnable(GL_NORMALIZE);
52 /* callback: draw everything */
53 void win_draw(stonerview_state *st)
56 static const GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
57 static const GLfloat gray[] = { 0.6, 0.6, 0.6, 1.0 };
59 glDrawBuffer(GL_BACK);
61 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
64 glScalef(view_scale, view_scale, view_scale);
65 glRotatef(view_rotx, 1.0, 0.0, 0.0);
66 glRotatef(view_roty, 0.0, 1.0, 0.0);
67 glRotatef(view_rotz, 0.0, 0.0, 1.0);
69 glShadeModel(GL_FLAT);
71 for (ix=0; ix < st->num_els; ix++) {
72 elem_t *el = &st->elist[ix];
74 glNormal3f(0.0, 0.0, 1.0);
76 /* outline the square */
77 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, (st->wireframe ? white : gray));
78 glBegin(GL_LINE_LOOP);
79 glVertex3f(el->pos[0]-el->vervec[0], el->pos[1]-el->vervec[1], el->pos[2]);
80 glVertex3f(el->pos[0]+el->vervec[1], el->pos[1]-el->vervec[0], el->pos[2]);
81 glVertex3f(el->pos[0]+el->vervec[0], el->pos[1]+el->vervec[1], el->pos[2]);
82 glVertex3f(el->pos[0]-el->vervec[1], el->pos[1]+el->vervec[0], el->pos[2]);
85 if (st->wireframe) continue;
88 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, el->col);
90 glVertex3f(el->pos[0]-el->vervec[0], el->pos[1]-el->vervec[1], el->pos[2]);
91 glVertex3f(el->pos[0]+el->vervec[1], el->pos[1]-el->vervec[0], el->pos[2]);
92 glVertex3f(el->pos[0]+el->vervec[0], el->pos[1]+el->vervec[1], el->pos[2]);
93 glVertex3f(el->pos[0]-el->vervec[1], el->pos[1]+el->vervec[0], el->pos[2]);
100 void win_release(stonerview_state *st)
103 /*free (st->oscroot); -- #### how do we free this? */