Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / FL_Cube / test_i.cpp
blob1d75cbd70c9a92e48483bbd0891664201b78a1f8
1 #include "test_i.h"
2 #include <GL/gl.h>
4 Simple_Server_i::Simple_Server_i (CORBA::ORB_ptr orb,
5 Simple_Window *window)
6 : orb_ (CORBA::ORB::_duplicate (orb)),
7 window_ (window)
11 void
12 Simple_Server_i::set_x_angle (CORBA::Long x)
14 this->window_->set_x_angle (x);
17 void
18 Simple_Server_i::set_y_angle (CORBA::Long y)
20 this->window_->set_y_angle (y);
23 void
24 Simple_Server_i::shutdown ()
26 this->orb_->shutdown (false);
29 // ****************************************************************
31 Simple_Window::Simple_Window (int x, int y,
32 int w, int h,
33 const char* l)
34 : Fl_Gl_Window (x, y, w, h, l),
35 x_angle_ (0),
36 y_angle_ (0)
38 boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
39 boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
40 boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
41 boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
42 boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
43 boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
44 boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
45 boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
48 void
49 Simple_Window::set_x_angle (CORBA::Long x)
51 this->x_angle_ = x;
52 this->redraw ();
55 void
56 Simple_Window::set_y_angle (CORBA::Long y)
58 this->y_angle_ = y;
59 this->redraw ();
62 void
63 Simple_Window::draw ()
65 // Based on the CubeView example in the FL toolkit.
67 if (!this->valid())
69 glLoadIdentity();
70 glViewport(0, 0, this->w(), this->h());
71 glOrtho(-2,2,-2,2,-20000,10000);
72 glEnable(GL_BLEND);
73 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
76 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
78 glPushMatrix();
80 glRotatef(this->x_angle_, 0, 1, 0);
81 glRotatef(this->y_angle_, 1, 0, 0);
83 this->draw_cube ();
85 glPopMatrix ();
88 void
89 Simple_Window::draw_cube ()
91 const float ALPHA = 0.5;
93 glBegin(GL_QUADS);
94 glColor4f(0.0, 0.0, 1.0, ALPHA);
95 glVertex3fv(boxv0);
96 glVertex3fv(boxv1);
97 glVertex3fv(boxv2);
98 glVertex3fv(boxv3);
100 glColor4f(1.0, 1.0, 0.0, ALPHA);
101 glVertex3fv(boxv0);
102 glVertex3fv(boxv4);
103 glVertex3fv(boxv5);
104 glVertex3fv(boxv1);
106 glColor4f(0.0, 1.0, 1.0, ALPHA);
107 glVertex3fv(boxv2);
108 glVertex3fv(boxv6);
109 glVertex3fv(boxv7);
110 glVertex3fv(boxv3);
112 glColor4f(1.0, 0.0, 0.0, ALPHA);
113 glVertex3fv(boxv4);
114 glVertex3fv(boxv5);
115 glVertex3fv(boxv6);
116 glVertex3fv(boxv7);
118 glColor4f(1.0, 0.0, 1.0, ALPHA);
119 glVertex3fv(boxv0);
120 glVertex3fv(boxv3);
121 glVertex3fv(boxv7);
122 glVertex3fv(boxv4);
124 glColor4f(0.0, 1.0, 0.0, ALPHA);
125 glVertex3fv(boxv1);
126 glVertex3fv(boxv5);
127 glVertex3fv(boxv6);
128 glVertex3fv(boxv2);
129 glEnd();
131 glColor3f(1.0, 1.0, 1.0);
132 glBegin(GL_LINES);
133 glVertex3fv(boxv0);
134 glVertex3fv(boxv1);
136 glVertex3fv(boxv1);
137 glVertex3fv(boxv2);
139 glVertex3fv(boxv2);
140 glVertex3fv(boxv3);
142 glVertex3fv(boxv3);
143 glVertex3fv(boxv0);
145 glVertex3fv(boxv4);
146 glVertex3fv(boxv5);
148 glVertex3fv(boxv5);
149 glVertex3fv(boxv6);
151 glVertex3fv(boxv6);
152 glVertex3fv(boxv7);
153 glVertex3fv(boxv7);
154 glVertex3fv(boxv4);
156 glVertex3fv(boxv0);
157 glVertex3fv(boxv4);
159 glVertex3fv(boxv1);
160 glVertex3fv(boxv5);
162 glVertex3fv(boxv2);
163 glVertex3fv(boxv6);
165 glVertex3fv(boxv3);
166 glVertex3fv(boxv7);
167 glEnd();