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();
28 static void display();
30 static void reshape(int x, int y);
31 static void keyboard(unsigned char c, int x, int y);
32 static void mbutton(int bn, int state, int x, int y);
33 static void mmotion(int x, int y);
35 static float cam_theta = 45, cam_phi, cam_dist = 10;
36 static unsigned int sdr_curve_top, sdr_beam, sdr_sky;
37 static unsigned int start_time;
38 static float beam_rot_speed = 0.1;
40 static const float sil_color[] = {0.05, 0.02, 0.1, 1.0};
41 static const float beam_color[] = {0.5, 0.4, 0.2, 1.0};
43 int main(int argc, char **argv)
45 glutInit(&argc, argv);
46 glutInitWindowSize(800, 600);
47 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
49 glutCreateWindow("Faros");
51 glutDisplayFunc(display);
53 glutReshapeFunc(reshape);
54 glutKeyboardFunc(keyboard);
55 glutMouseFunc(mbutton);
56 glutMotionFunc(mmotion);
72 glEnable(GL_CULL_FACE);
73 glEnable(GL_DEPTH_TEST);
74 glEnable(GL_MULTISAMPLE);
76 // glEnable(GL_LIGHTING);
79 glEnable(GL_NORMALIZE);
81 if(!(sdr_curve_top = create_program_load(CURVE_VS, CURVE_FS)))
84 if(!(sdr_beam = create_program_load(BEAM_VS, BEAM_FS)))
87 if(!(sdr_sky = create_program_load("sdr/sky.v.glsl", "sdr/sky.f.glsl"))) {
91 start_time = glutGet(GLUT_ELAPSED_TIME);
101 glColor3fv(sil_color);
105 glScalef(1.1, 3, 1.1);
106 glTranslatef(0, 0.5, 0);
110 glShadeModel(GL_FLAT);
114 glRotatef(90, 1, 0, 0);
115 glTranslatef(0, -0.15, 0);
116 glutSolidCylinder(2, 0.3, 16, 1);
121 glTranslatef(0, 3, 0);
122 glRotatef(22.5, 0, 1, 0);
123 glRotatef(-90, 1, 0, 0);
124 glutSolidCylinder(0.5, 1.0, 8, 1);
127 // trim middle cylinder (mporntoura)
129 glTranslatef(0, 3.9, 0);
130 glRotatef(22.5, 0, 1, 0);
131 glRotatef(-90, 1, 0, 0);
132 glutSolidCylinder(0.55, 0.02, 8, 1);
135 // top smaller cylinder
137 glTranslatef(0, 4, 0);
138 glRotatef(22.5, 0, 1, 0);
139 glRotatef(-90, 1, 0, 0);
140 glutSolidCylinder(0.28, 0.5, 8, 1);
143 // top wire even smaller cylinder
145 glTranslatef(0, 4.5, 0);
146 glRotatef(22.5, 0, 1, 0);
147 glRotatef(-90, 1, 0, 0);
148 glutWireCylinder(0.18, 0.3, 9, 3);
151 glShadeModel(GL_SMOOTH);
155 glTranslatef(0, 4.8, 0);
156 glRotatef(22.5, 0, 1, 0);
157 glRotatef(-90, 1, 0, 0);
158 glutSolidCone(0.18, 0.2, 9, 1);
163 glTranslatef(-0.28, 4, 0);
165 glutSolidSphere(0.1, 16, 16);
168 //pyramid on top of kormos
169 bind_program(sdr_curve_top);
172 glTranslatef(0, 3, 0);
173 glRotatef(45, 0, 1, 0);
174 glRotatef(-90, 1, 0, 0);
175 glScalef(1, 1, 0.45);
176 glutSolidCylinder(1, 1, 4, 16);
184 glPushAttrib(GL_ENABLE_BIT);
185 glDisable(GL_CULL_FACE);
189 glTranslatef(0, 4.65, 0.2);
190 bind_program(sdr_beam);
191 set_uniform_float(sdr_beam, "beam_len", BEAM_LEN);
194 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
196 for(int i=0; i<BEAM_SHELLS; i++) {
197 float t = (float)i / (float)(BEAM_SHELLS - 1);
198 float rad = BEAM_RMIN + (BEAM_RMAX - BEAM_RMIN) * t;
199 float alpha = BEAM_ENERGY / (t * t);
201 glColor4f(beam_color[0], beam_color[1], beam_color[2], alpha);
203 glutSolidCylinder(rad, BEAM_LEN, 12, 1);
217 glTranslatef(0, -1.25, 0);
220 glColor3fv(sil_color);
221 glutSolidSphere(10, 32, 32);
226 static void backdrop()
229 bind_program(sdr_sky);
230 glutSolidSphere(200, 16, 32);
235 static void display()
237 unsigned int tmsec = glutGet(GLUT_ELAPSED_TIME) - start_time;
238 float tsec = (float)tmsec / 1000.0;
240 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
243 glMatrixMode(GL_MODELVIEW);
246 glTranslatef(0, -2, -cam_dist);
247 glRotatef(cam_phi, 1, 0, 0);
248 glRotatef(cam_theta, 0, 1, 0);
255 float beam_angle = tsec * beam_rot_speed * 360;
257 glRotatef(beam_angle, 0, 1, 0);
270 static void reshape(int x, int y)
272 glViewport(0, 0, x, y);
274 glMatrixMode(GL_PROJECTION);
277 gluPerspective(50, (float)x / (float)y, 0.5, 500);
280 static void keyboard(unsigned char c, int x, int y)
290 static int prev_x, prev_y;
292 static void mbutton(int bn, int state, int x, int y)
294 int button = bn - GLUT_LEFT_BUTTON;
295 bst[button] = state == GLUT_DOWN;
301 static void mmotion(int x, int y)
309 if (dx == 0 && dy == 0)
313 cam_theta += dx * 0.5;
324 cam_dist += dy * 0.1;