2 #include <GL/freeglut.h>
9 #define CURVE_VS "sdr/curve_top.v.glsl"
10 #define CURVE_FS "sdr/curve_top.f.glsl"
11 #define BEAM_VS "sdr/beam.v.glsl"
12 #define BEAM_FS "sdr/beam.f.glsl"
14 #define BEAM_SHELLS 40
15 #define BEAM_RMIN 0.01
16 #define BEAM_RMAX 0.125
17 #define BEAM_ENERGY 0.02
21 static void cleanup();
26 static void backdrop();
29 static void display();
31 static void reshape(int x, int y);
32 static void keyboard(unsigned char c, int x, int y);
33 static void mbutton(int bn, int state, int x, int y);
34 static void mmotion(int x, int y);
36 static float cam_theta = 45, cam_phi, cam_dist = 10;
37 static unsigned int sdr_curve_top, sdr_beam, sdr_sky;
38 static unsigned int start_time;
39 static float anim_speed = 0.1;
40 static unsigned int anim_stop_time;
41 static unsigned int tmsec;
43 static const float sil_color[] = {0.05, 0.02, 0.1, 1.0};
44 static const float beam_color[] = {0.5, 0.4, 0.2, 1.0};
46 int main(int argc, char **argv)
48 glutInit(&argc, argv);
49 glutInitWindowSize(800, 600);
50 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
52 glutCreateWindow("Faros");
54 glutDisplayFunc(display);
56 glutReshapeFunc(reshape);
57 glutKeyboardFunc(keyboard);
58 glutMouseFunc(mbutton);
59 glutMotionFunc(mmotion);
75 glEnable(GL_CULL_FACE);
76 glEnable(GL_DEPTH_TEST);
77 glEnable(GL_MULTISAMPLE);
79 // glEnable(GL_LIGHTING);
82 glEnable(GL_NORMALIZE);
84 if(!(sdr_curve_top = create_program_load(CURVE_VS, CURVE_FS)))
87 if(!(sdr_beam = create_program_load(BEAM_VS, BEAM_FS)))
90 if(!(sdr_sky = create_program_load("sdr/sky.v.glsl", "sdr/sky.f.glsl"))) {
94 start_time = glutGet(GLUT_ELAPSED_TIME);
104 glColor3fv(sil_color);
108 glScalef(1.1, 3, 1.1);
109 glTranslatef(0, 0.5, 0);
113 glShadeModel(GL_FLAT);
117 glRotatef(90, 1, 0, 0);
118 glTranslatef(0, -0.15, 0);
119 glutSolidCylinder(2, 0.3, 16, 1);
124 glTranslatef(0, 3, 0);
125 glRotatef(22.5, 0, 1, 0);
126 glRotatef(-90, 1, 0, 0);
127 glutSolidCylinder(0.5, 1.0, 8, 1);
130 // trim middle cylinder (mporntoura)
132 glTranslatef(0, 3.9, 0);
133 glRotatef(22.5, 0, 1, 0);
134 glRotatef(-90, 1, 0, 0);
135 glutSolidCylinder(0.55, 0.02, 8, 1);
138 // top smaller cylinder
140 glTranslatef(0, 4, 0);
141 glRotatef(22.5, 0, 1, 0);
142 glRotatef(-90, 1, 0, 0);
143 glutSolidCylinder(0.28, 0.5, 8, 1);
146 // top wire even smaller cylinder
148 glTranslatef(0, 4.5, 0);
149 glRotatef(22.5, 0, 1, 0);
150 glRotatef(-90, 1, 0, 0);
151 glutWireCylinder(0.18, 0.3, 9, 3);
154 glShadeModel(GL_SMOOTH);
158 glTranslatef(0, 4.8, 0);
159 glRotatef(22.5, 0, 1, 0);
160 glRotatef(-90, 1, 0, 0);
161 glutSolidCone(0.18, 0.2, 9, 1);
166 glTranslatef(-0.28, 4, 0);
168 glutSolidSphere(0.1, 16, 16);
171 //pyramid on top of kormos
172 bind_program(sdr_curve_top);
175 glTranslatef(0, 3, 0);
176 glRotatef(45, 0, 1, 0);
177 glRotatef(-90, 1, 0, 0);
178 glScalef(1, 1, 0.45);
179 glutSolidCylinder(1, 1, 4, 16);
187 glPushAttrib(GL_ENABLE_BIT);
188 glDisable(GL_CULL_FACE);
192 glTranslatef(0, 4.65, 0.2);
193 bind_program(sdr_beam);
194 set_uniform_float(sdr_beam, "beam_len", BEAM_LEN);
197 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
199 for(int i=0; i<BEAM_SHELLS; i++) {
200 float t = (float)i / (float)(BEAM_SHELLS - 1);
201 float rad = BEAM_RMIN + (BEAM_RMAX - BEAM_RMIN) * t;
202 float alpha = BEAM_ENERGY / (t * t);
204 glColor4f(beam_color[0], beam_color[1], beam_color[2], alpha);
206 glutSolidCylinder(rad, BEAM_LEN, 12, 1);
220 glTranslatef(0, -1.25, 0);
223 glColor3fv(sil_color);
224 glutSolidSphere(10, 32, 32);
229 static void backdrop()
232 bind_program(sdr_sky);
233 glutSolidSphere(200, 16, 32);
238 static void display()
240 if(anim_stop_time > 0) {
241 tmsec = anim_stop_time - start_time;
243 tmsec = glutGet(GLUT_ELAPSED_TIME) - start_time;
246 float tsec = (float)tmsec / 1000.0;
247 float tanim = tsec * anim_speed;
249 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
252 glMatrixMode(GL_MODELVIEW);
255 glTranslatef(0, -2, -cam_dist);
256 glRotatef(cam_phi, 1, 0, 0);
257 glRotatef(cam_theta, 0, 1, 0);
264 float beam_angle = tanim * 360;
266 glRotatef(beam_angle, 0, 1, 0);
279 static void reshape(int x, int y)
281 glViewport(0, 0, x, y);
283 glMatrixMode(GL_PROJECTION);
286 gluPerspective(50, (float)x / (float)y, 0.5, 500);
289 static unsigned int calc_timeshift(float prev_speed, float speed)
291 return tmsec * speed - tmsec * prev_speed;
294 static void keyboard(unsigned char c, int x, int y)
300 if(anim_stop_time > 0) {
301 start_time += glutGet(GLUT_ELAPSED_TIME) - anim_stop_time;
304 anim_stop_time = glutGet(GLUT_ELAPSED_TIME);
308 //printf("prin %u\n", glutGet(GLUT_ELAPSED_TIME) - start_time);
309 //start_time += calc_timeshift(anim_speed, anim_speed + 0.1);
313 //start_time += calc_timeshift(anim_speed, anim_speed - 0.1);
323 static int prev_x, prev_y;
325 static void mbutton(int bn, int state, int x, int y)
327 int button = bn - GLUT_LEFT_BUTTON;
328 bst[button] = state == GLUT_DOWN;
334 static void mmotion(int x, int y)
342 if (dx == 0 && dy == 0)
346 cam_theta += dx * 0.5;
357 cam_dist += dy * 0.1;