xlogo, more animation controls, help screen with F1.
[faros-demo] / src / geom.cc
1 #include <GL/glew.h>
2 #include <GL/freeglut.h>
3 #include "geom.h"
4 #include "sdr.h"
5
6 static unsigned int sdr_curve_top;
7
8 bool init_geom()
9 {
10         if(!(sdr_curve_top = create_program_load("sdr/curve_top.v.glsl", "sdr/curve_top.f.glsl"))) {
11                 return false;
12         }
13         return true;
14 }
15
16 void destroy_geom()
17 {
18         free_program(sdr_curve_top);
19 }
20
21 void faros()
22 {
23         // kormos
24         glPushMatrix();
25         glScalef(1.1, 3, 1.1);
26         glTranslatef(0, 0.5, 0);
27         glutSolidCube(1.0);
28         glPopMatrix();
29
30         glShadeModel(GL_FLAT);
31
32         // base
33         glPushMatrix();
34         glRotatef(90, 1, 0, 0);
35         glTranslatef(0, -0.15, 0);
36         glutSolidCylinder(2, 0.3, 16, 1);
37         glPopMatrix();
38
39         // middle cylinder
40         glPushMatrix();
41         glTranslatef(0, 3, 0);
42         glRotatef(22.5, 0, 1, 0);
43         glRotatef(-90, 1, 0, 0);
44         glutSolidCylinder(0.5, 1.0, 8, 1);
45         glPopMatrix();
46
47         // trim middle cylinder (mporntoura)
48         glPushMatrix();
49         glTranslatef(0, 3.9, 0);
50         glRotatef(22.5, 0, 1, 0);
51         glRotatef(-90, 1, 0, 0);
52         glutSolidCylinder(0.55, 0.02, 8, 1);
53         glPopMatrix();
54
55         // top smaller cylinder
56         glPushMatrix();
57         glTranslatef(0, 4, 0);
58         glRotatef(22.5, 0, 1, 0);
59         glRotatef(-90, 1, 0, 0);
60         glutSolidCylinder(0.28, 0.5, 8, 1);
61         glPopMatrix();
62
63         // top wire even smaller cylinder
64         glPushMatrix();
65         glTranslatef(0, 4.5, 0);
66         glRotatef(22.5, 0, 1, 0);
67         glRotatef(-90, 1, 0, 0);
68         glutWireCylinder(0.18, 0.3, 9, 3);
69         glPopMatrix();
70
71         glShadeModel(GL_SMOOTH);
72
73         // top troulos
74         glPushMatrix();
75         glTranslatef(0, 4.8, 0);
76         glRotatef(22.5, 0, 1, 0);
77         glRotatef(-90, 1, 0, 0);
78         glutSolidCone(0.18, 0.2, 9, 1);
79         glPopMatrix();
80
81         // tsamploukano
82         glPushMatrix();
83         glTranslatef(-0.28, 4, 0);
84         glScalef(1, 13, 1);
85         glutSolidSphere(0.1, 16, 16);
86         glPopMatrix();
87
88         //pyramid on top of kormos
89         bind_program(sdr_curve_top);
90
91         glPushMatrix();
92         glTranslatef(0, 3, 0);
93         glRotatef(45, 0, 1, 0);
94         glRotatef(-90, 1, 0, 0);
95         glScalef(1, 1, 0.45);
96         glutSolidCylinder(1, 1, 4, 16);
97         glPopMatrix();
98
99         bind_program(0);
100 }
101
102
103 void ground()
104 {
105         glPushMatrix();
106
107         glTranslatef(0, -1.25, 0);
108         glScalef(1, 0.1, 1);
109
110         glutSolidSphere(10, 32, 32);
111
112         glPopMatrix();
113 }
114
115 void xlogo()
116 {
117         static const float xlogo_varr[] = {
118                 -0.500, 0.407, -0.113, -0.109, 0.059, -0.006, -0.251, 0.407,
119                 -0.113, -0.109, -0.499, -0.593, -0.410, -0.593, 0.059, -0.006,
120                 -0.058, -0.182, 0.251, -0.593, 0.500, -0.593, 0.114, -0.079,
121                 -0.058, -0.182, 0.114, -0.079, 0.500, 0.407, 0.411, 0.407
122         };
123
124         glPushAttrib(GL_ENABLE_BIT);
125         glEnable(GL_BLEND);
126         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
127
128         glBegin(GL_QUADS);
129         const float *vptr = xlogo_varr;
130         for(int i=0; i<(int)(sizeof xlogo_varr / sizeof *xlogo_varr) / 2; i++) {
131                 glVertex2fv(vptr);
132                 vptr += 2;
133         }
134         glEnd();
135
136         glPopAttrib();
137 }