Tweak themes for more color consistency.
[ntk.git] / test / CubeView.cxx
blobaba5266883221f52f59d7c1246d82137d36fdb39
1 //
2 // "$Id: CubeView.cxx 7903 2010-11-28 21:06:39Z matt $"
3 //
4 // CubeView class implementation for the Fast Light Tool Kit (FLTK).
5 //
6 // Copyright 1998-2010 by Bill Spitzak and others.
7 //
8 // This library is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU Library General Public
10 // License as published by the Free Software Foundation; either
11 // version 2 of the License, or (at your option) any later version.
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Library General Public License for more details.
18 // You should have received a copy of the GNU Library General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 // USA.
23 // Please report all bugs and problems on the following page:
25 // http://www.fltk.org/str.php
28 #include "CubeView.h"
29 #include <math.h>
32 #if HAVE_GL
33 CubeView::CubeView(int x,int y,int w,int h,const char *l)
34 : Fl_Gl_Window(x,y,w,h,l)
35 #else
36 CubeView::CubeView(int x,int y,int w,int h,const char *l)
37 : Fl_Box(x,y,w,h,l)
38 #endif /* HAVE_GL */
40 vAng = 0.0;
41 hAng=0.0;
42 size=10.0;
43 xshift=0.0;
44 yshift=0.0;
46 /* The cube definition. These are the vertices of a unit cube
47 * centered on the origin.*/
49 boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
50 boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
51 boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
52 boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
53 boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
54 boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
55 boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
56 boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
58 #if !HAVE_GL
59 label("OpenGL is required for this demo to operate.");
60 align(FL_ALIGN_WRAP | FL_ALIGN_INSIDE);
61 #endif /* !HAVE_GL */
64 #if HAVE_GL
65 void CubeView::drawCube() {
66 /* Draw a colored cube */
67 #define ALPHA 0.5
68 glShadeModel(GL_FLAT);
70 glBegin(GL_QUADS);
71 glColor4f(0.0, 0.0, 1.0, ALPHA);
72 glVertex3fv(boxv0);
73 glVertex3fv(boxv1);
74 glVertex3fv(boxv2);
75 glVertex3fv(boxv3);
77 glColor4f(1.0, 1.0, 0.0, ALPHA);
78 glVertex3fv(boxv0);
79 glVertex3fv(boxv4);
80 glVertex3fv(boxv5);
81 glVertex3fv(boxv1);
83 glColor4f(0.0, 1.0, 1.0, ALPHA);
84 glVertex3fv(boxv2);
85 glVertex3fv(boxv6);
86 glVertex3fv(boxv7);
87 glVertex3fv(boxv3);
89 glColor4f(1.0, 0.0, 0.0, ALPHA);
90 glVertex3fv(boxv4);
91 glVertex3fv(boxv5);
92 glVertex3fv(boxv6);
93 glVertex3fv(boxv7);
95 glColor4f(1.0, 0.0, 1.0, ALPHA);
96 glVertex3fv(boxv0);
97 glVertex3fv(boxv3);
98 glVertex3fv(boxv7);
99 glVertex3fv(boxv4);
101 glColor4f(0.0, 1.0, 0.0, ALPHA);
102 glVertex3fv(boxv1);
103 glVertex3fv(boxv5);
104 glVertex3fv(boxv6);
105 glVertex3fv(boxv2);
106 glEnd();
108 glColor3f(1.0, 1.0, 1.0);
109 glBegin(GL_LINES);
110 glVertex3fv(boxv0);
111 glVertex3fv(boxv1);
113 glVertex3fv(boxv1);
114 glVertex3fv(boxv2);
116 glVertex3fv(boxv2);
117 glVertex3fv(boxv3);
119 glVertex3fv(boxv3);
120 glVertex3fv(boxv0);
122 glVertex3fv(boxv4);
123 glVertex3fv(boxv5);
125 glVertex3fv(boxv5);
126 glVertex3fv(boxv6);
128 glVertex3fv(boxv6);
129 glVertex3fv(boxv7);
131 glVertex3fv(boxv7);
132 glVertex3fv(boxv4);
134 glVertex3fv(boxv0);
135 glVertex3fv(boxv4);
137 glVertex3fv(boxv1);
138 glVertex3fv(boxv5);
140 glVertex3fv(boxv2);
141 glVertex3fv(boxv6);
143 glVertex3fv(boxv3);
144 glVertex3fv(boxv7);
145 glEnd();
146 }//drawCube
148 void CubeView::draw() {
149 if (!valid()) {
150 glLoadIdentity();
151 glViewport(0,0,w(),h());
152 glOrtho(-10,10,-10,10,-20050,10000);
153 glEnable(GL_BLEND);
154 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
157 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
159 glPushMatrix();
161 glTranslatef(xshift, yshift, 0);
162 glRotatef(hAng,0,1,0); glRotatef(vAng,1,0,0);
163 glScalef(float(size),float(size),float(size));
165 drawCube();
167 glPopMatrix();
169 #endif /* HAVE_GL */
172 // End of "$Id: CubeView.cxx 7903 2010-11-28 21:06:39Z matt $".