Merge pull request #1844 from jrw972/monterey
[ACE_TAO.git] / TAO / tests / FL_Cube / test_i.cpp
blob14fc41808d6b843d745661e5adbd33c4aaa8755a
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)
12 void
13 Simple_Server_i::set_x_angle (CORBA::Long x)
15 this->window_->set_x_angle (x);
18 void
19 Simple_Server_i::set_y_angle (CORBA::Long y)
21 this->window_->set_y_angle (y);
24 void
25 Simple_Server_i::shutdown (void)
27 this->orb_->shutdown (0);
30 // ****************************************************************
32 Simple_Window::Simple_Window (int x, int y,
33 int w, int h,
34 const char* l)
35 : Fl_Gl_Window (x, y, w, h, l),
36 x_angle_ (0),
37 y_angle_ (0)
39 boxv0[0] = -0.5; boxv0[1] = -0.5; boxv0[2] = -0.5;
40 boxv1[0] = 0.5; boxv1[1] = -0.5; boxv1[2] = -0.5;
41 boxv2[0] = 0.5; boxv2[1] = 0.5; boxv2[2] = -0.5;
42 boxv3[0] = -0.5; boxv3[1] = 0.5; boxv3[2] = -0.5;
43 boxv4[0] = -0.5; boxv4[1] = -0.5; boxv4[2] = 0.5;
44 boxv5[0] = 0.5; boxv5[1] = -0.5; boxv5[2] = 0.5;
45 boxv6[0] = 0.5; boxv6[1] = 0.5; boxv6[2] = 0.5;
46 boxv7[0] = -0.5; boxv7[1] = 0.5; boxv7[2] = 0.5;
49 void
50 Simple_Window::set_x_angle (CORBA::Long x)
52 this->x_angle_ = x;
53 this->redraw ();
56 void
57 Simple_Window::set_y_angle (CORBA::Long y)
59 this->y_angle_ = y;
60 this->redraw ();
63 void
64 Simple_Window::draw (void)
66 // Based on the CubeView example in the FL toolkit.
68 if (!this->valid())
70 glLoadIdentity();
71 glViewport(0, 0, this->w(), this->h());
72 glOrtho(-2,2,-2,2,-20000,10000);
73 glEnable(GL_BLEND);
74 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
77 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
79 glPushMatrix();
81 glRotatef(this->x_angle_, 0, 1, 0);
82 glRotatef(this->y_angle_, 1, 0, 0);
84 this->draw_cube ();
86 glPopMatrix ();
89 void
90 Simple_Window::draw_cube (void)
92 const float ALPHA = 0.5;
94 glBegin(GL_QUADS);
95 glColor4f(0.0, 0.0, 1.0, ALPHA);
96 glVertex3fv(boxv0);
97 glVertex3fv(boxv1);
98 glVertex3fv(boxv2);
99 glVertex3fv(boxv3);
101 glColor4f(1.0, 1.0, 0.0, ALPHA);
102 glVertex3fv(boxv0);
103 glVertex3fv(boxv4);
104 glVertex3fv(boxv5);
105 glVertex3fv(boxv1);
107 glColor4f(0.0, 1.0, 1.0, ALPHA);
108 glVertex3fv(boxv2);
109 glVertex3fv(boxv6);
110 glVertex3fv(boxv7);
111 glVertex3fv(boxv3);
113 glColor4f(1.0, 0.0, 0.0, ALPHA);
114 glVertex3fv(boxv4);
115 glVertex3fv(boxv5);
116 glVertex3fv(boxv6);
117 glVertex3fv(boxv7);
119 glColor4f(1.0, 0.0, 1.0, ALPHA);
120 glVertex3fv(boxv0);
121 glVertex3fv(boxv3);
122 glVertex3fv(boxv7);
123 glVertex3fv(boxv4);
125 glColor4f(0.0, 1.0, 0.0, ALPHA);
126 glVertex3fv(boxv1);
127 glVertex3fv(boxv5);
128 glVertex3fv(boxv6);
129 glVertex3fv(boxv2);
130 glEnd();
132 glColor3f(1.0, 1.0, 1.0);
133 glBegin(GL_LINES);
134 glVertex3fv(boxv0);
135 glVertex3fv(boxv1);
137 glVertex3fv(boxv1);
138 glVertex3fv(boxv2);
140 glVertex3fv(boxv2);
141 glVertex3fv(boxv3);
143 glVertex3fv(boxv3);
144 glVertex3fv(boxv0);
146 glVertex3fv(boxv4);
147 glVertex3fv(boxv5);
149 glVertex3fv(boxv5);
150 glVertex3fv(boxv6);
152 glVertex3fv(boxv6);
153 glVertex3fv(boxv7);
154 glVertex3fv(boxv7);
155 glVertex3fv(boxv4);
157 glVertex3fv(boxv0);
158 glVertex3fv(boxv4);
160 glVertex3fv(boxv1);
161 glVertex3fv(boxv5);
163 glVertex3fv(boxv2);
164 glVertex3fv(boxv6);
166 glVertex3fv(boxv3);
167 glVertex3fv(boxv7);
168 glEnd();