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
20 static void cleanup();
25 static void backdrop();
27 static void display();
29 static void reshape(int x, int y);
30 static void keyboard(unsigned char c, int x, int y);
31 static void mbutton(int bn, int state, int x, int y);
32 static void mmotion(int x, int y);
34 static float cam_theta = 45, cam_phi, cam_dist = 10;
35 static unsigned int sdr_curve_top, sdr_beam, sdr_sky;
36 static unsigned int start_time;
37 static float beam_rot_speed = 0.1;
39 int main(int argc, char **argv)
41 glutInit(&argc, argv);
42 glutInitWindowSize(800, 600);
43 glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
45 glutCreateWindow("Faros");
47 glutDisplayFunc(display);
49 glutReshapeFunc(reshape);
50 glutKeyboardFunc(keyboard);
51 glutMouseFunc(mbutton);
52 glutMotionFunc(mmotion);
68 glEnable(GL_CULL_FACE);
69 glEnable(GL_DEPTH_TEST);
70 glEnable(GL_MULTISAMPLE);
72 // glEnable(GL_LIGHTING);
75 glEnable(GL_NORMALIZE);
77 if(!(sdr_curve_top = create_program_load(CURVE_VS, CURVE_FS)))
80 if(!(sdr_beam = create_program_load(BEAM_VS, BEAM_FS)))
83 if(!(sdr_sky = create_program_load("sdr/sky.v.glsl", "sdr/sky.f.glsl"))) {
87 start_time = glutGet(GLUT_ELAPSED_TIME);
101 glScalef(1.1, 3, 1.1);
102 glTranslatef(0, 0.5, 0);
106 glShadeModel(GL_FLAT);
110 glRotatef(90, 1, 0, 0);
111 glTranslatef(0, -0.15, 0);
112 glutSolidCylinder(2, 0.3, 16, 1);
117 glTranslatef(0, 3, 0);
118 glRotatef(22.5, 0, 1, 0);
119 glRotatef(-90, 1, 0, 0);
120 glutSolidCylinder(0.5, 1.0, 8, 1);
123 // trim middle cylinder (mporntoura)
125 glTranslatef(0, 3.9, 0);
126 glRotatef(22.5, 0, 1, 0);
127 glRotatef(-90, 1, 0, 0);
128 glutSolidCylinder(0.55, 0.02, 8, 1);
131 // top smaller cylinder
133 glTranslatef(0, 4, 0);
134 glRotatef(22.5, 0, 1, 0);
135 glRotatef(-90, 1, 0, 0);
136 glutSolidCylinder(0.28, 0.5, 8, 1);
139 // top wire even smaller cylinder
141 glTranslatef(0, 4.5, 0);
142 glRotatef(22.5, 0, 1, 0);
143 glRotatef(-90, 1, 0, 0);
144 glutWireCylinder(0.18, 0.3, 9, 3);
147 glShadeModel(GL_SMOOTH);
151 glTranslatef(0, 4.8, 0);
152 glRotatef(22.5, 0, 1, 0);
153 glRotatef(-90, 1, 0, 0);
154 glutSolidCone(0.18, 0.2, 9, 1);
159 glTranslatef(-0.28, 4, 0);
161 glutSolidSphere(0.1, 16, 16);
164 //pyramid on top of kormos
165 bind_program(sdr_curve_top);
168 glTranslatef(0, 3, 0);
169 glRotatef(45, 0, 1, 0);
170 glRotatef(-90, 1, 0, 0);
171 glScalef(1, 1, 0.45);
172 glutSolidCylinder(1, 1, 4, 16);
180 glPushAttrib(GL_ENABLE_BIT);
181 glDisable(GL_CULL_FACE);
185 glTranslatef(0, 4.65, 0.2);
186 bind_program(sdr_beam);
189 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
191 for(int i=0; i<BEAM_SHELLS; i++) {
192 float t = (float)i / (float)(BEAM_SHELLS - 1);
193 float rad = BEAM_RMIN + (BEAM_RMAX - BEAM_RMIN) * t;
194 float alpha = BEAM_ENERGY / t;
196 glColor4f(0.8, 0.8, 0.2, alpha);
198 glutSolidCylinder(rad, 6, 10, 1);
212 glTranslatef(0, -1.25, 0);
216 glutSolidSphere(10, 32, 32);
221 static void backdrop()
224 bind_program(sdr_sky);
225 glutSolidSphere(200, 16, 32);
230 static void display()
232 unsigned int tmsec = glutGet(GLUT_ELAPSED_TIME) - start_time;
233 float tsec = (float)tmsec / 1000.0;
235 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
238 glMatrixMode(GL_MODELVIEW);
241 glTranslatef(0, -2, -cam_dist);
242 glRotatef(cam_phi, 1, 0, 0);
243 glRotatef(cam_theta, 0, 1, 0);
250 float beam_angle = tsec * beam_rot_speed * 360;
252 glRotatef(beam_angle, 0, 1, 0);
265 static void reshape(int x, int y)
267 glViewport(0, 0, x, y);
269 glMatrixMode(GL_PROJECTION);
272 gluPerspective(50, (float)x / (float)y, 0.5, 500);
275 static void keyboard(unsigned char c, int x, int y)
285 static int prev_x, prev_y;
287 static void mbutton(int bn, int state, int x, int y)
289 int button = bn - GLUT_LEFT_BUTTON;
290 bst[button] = state == GLUT_DOWN;
296 static void mmotion(int x, int y)
304 if (dx == 0 && dy == 0)
308 cam_theta += dx * 0.5;
319 cam_dist += dy * 0.1;