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 = 15.0;
26 static GLfloat view_scale = 4.0;
30 init_view(int wireframe_p, int transparent_p)
32 stonerview_state *st = (stonerview_state *) calloc (1, sizeof(*st));
34 st->wireframe = wireframe_p;
35 st->transparent = transparent_p;
36 st->num_els = NUM_ELS;
37 st->elist = (elem_t *) calloc (st->num_els, sizeof(*st->elist));
39 st->osctail = &st->oscroot;
41 /* for trackball, two-sided lighting and no face culling */
42 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
44 glEnable(GL_CULL_FACE);
45 glEnable(GL_LIGHTING);
47 glEnable(GL_DEPTH_TEST);
49 glEnable(GL_NORMALIZE);
51 glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
52 glEnable(GL_LINE_SMOOTH);
56 glBlendFunc(GL_SRC_ALPHA,GL_ONE);
61 /* callback: draw everything */
62 void win_draw(stonerview_state *st)
65 static const GLfloat white[] = { 1.0, 1.0, 1.0, 1.0 };
66 static const GLfloat gray[] = { 0.6, 0.6, 0.6, 1.0 };
68 glDrawBuffer(GL_BACK);
70 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
73 glScalef(view_scale, view_scale, view_scale);
74 glRotatef(view_rotx, 1.0, 0.0, 0.0);
75 glRotatef(view_roty, 0.0, 1.0, 0.0);
76 glRotatef(view_rotz, 0.0, 0.0, 1.0);
78 glShadeModel(GL_FLAT);
80 for (ix=0; ix < st->num_els; ix++) {
81 elem_t *el = &st->elist[ix];
83 glNormal3f(0.0, 0.0, 1.0);
85 /* outline the square */
86 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, (st->wireframe ? white : gray));
87 glBegin(GL_LINE_LOOP);
88 glVertex3f(el->pos[0]-el->vervec[0], el->pos[1]-el->vervec[1], el->pos[2]);
89 glVertex3f(el->pos[0]+el->vervec[1], el->pos[1]-el->vervec[0], el->pos[2]);
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]);
94 if (st->wireframe) continue;
97 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, el->col);
99 glVertex3f(el->pos[0]-el->vervec[0], el->pos[1]-el->vervec[1], el->pos[2]);
100 glVertex3f(el->pos[0]+el->vervec[1], el->pos[1]-el->vervec[0], el->pos[2]);
101 glVertex3f(el->pos[0]+el->vervec[0], el->pos[1]+el->vervec[1], el->pos[2]);
102 glVertex3f(el->pos[0]-el->vervec[1], el->pos[1]+el->vervec[0], el->pos[2]);
109 void win_release(stonerview_state *st)
112 /*free (st->oscroot); -- #### how do we free this? */