Rev 7953 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1789 | yogev_ezra | 1 | /* |
2 | Пример взят из набора примеров к компилятору XS Compiler |
||
3 | |||
4 | iadn |
||
5 | http://www.iadn.narod.ru |
||
6 | iadn@bk.ru |
||
7 | */ |
||
8 | |||
9 | #include |
||
10 | #include |
||
11 | #include |
||
12 | |||
13 | #include "SysCall.h" |
||
14 | #include "ProcessTab.h" |
||
15 | |||
16 | |||
17 | int Fps (long x, long y); |
||
18 | extern "C"{ |
||
5098 | clevermous | 19 | int main(void); |
1789 | yogev_ezra | 20 | } |
21 | |||
5098 | clevermous | 22 | static struct { |
1789 | yogev_ezra | 23 | int x,y; |
24 | int dx,dy; |
||
25 | } win; |
||
26 | |||
27 | #define CUBE_STEP 0.1 |
||
28 | |||
29 | #define KEY_ESC 1 |
||
30 | #define KEY_F 33 |
||
31 | |||
5098 | clevermous | 32 | static unsigned char FullScreen = 0; |
33 | static unsigned char skin = 3; |
||
1789 | yogev_ezra | 34 | |
5098 | clevermous | 35 | static float angle; |
36 | static process_table_entry_* pri; |
||
37 | static KOSGLContext cgl; |
||
1789 | yogev_ezra | 38 | |
5098 | clevermous | 39 | static void draw_cube() |
1789 | yogev_ezra | 40 | { |
41 | float x,y,z; |
||
42 | glBegin(GL_LINES); |
||
43 | |||
44 | for(y=-0.5;y<=0.5;y+=CUBE_STEP) |
||
45 | { |
||
46 | // the front |
||
47 | glColor3f(0,y+0.5,0); |
||
48 | glVertex3f(-0.5,y,-0.5); |
||
49 | glColor3f(1,y+0.5,0); |
||
50 | glVertex3f(0.5,y,-0.5); |
||
51 | |||
52 | // the back |
||
53 | glColor3f(0,y+0.5,1); |
||
54 | glVertex3f(-0.5,y,0.5); |
||
55 | glColor3f(1,y+0.5,1); |
||
56 | glVertex3f(0.5,y,0.5); |
||
57 | |||
58 | //right side |
||
59 | glColor3f(1,y+0.5,0); |
||
60 | glVertex3f(0.5,y,-0.5); |
||
61 | glColor3f(1,y+0.5,1); |
||
62 | glVertex3f(0.5,y,0.5); |
||
63 | |||
64 | //left side |
||
65 | glColor3f(0,y+0.5,0); |
||
66 | glVertex3f(-0.5,y,-0.5); |
||
67 | glColor3f(0,y+0.5,1); |
||
68 | glVertex3f(-0.5,y,0.5); |
||
69 | } |
||
70 | |||
71 | for(x=-0.5;x<=0.5;x+=CUBE_STEP) |
||
72 | { |
||
73 | // the front |
||
74 | glColor3f(x+0.5,1,0); |
||
75 | glVertex3f(x,0.5,-0.5); |
||
76 | glColor3f(x+0.5,0,0); |
||
77 | glVertex3f(x,-0.5,-0.5); |
||
78 | |||
79 | // the back |
||
80 | glColor3f(x+0.5,1,1); |
||
81 | glVertex3f(x,0.5,0.5); |
||
82 | glColor3f(x+0.5,0,1); |
||
83 | glVertex3f(x,-0.5,0.5); |
||
84 | |||
85 | // the top |
||
86 | glColor3f(x+0.5,1,0); |
||
87 | glVertex3f(x,0.5,-0.5); |
||
88 | glColor3f(x+0.5,1,1); |
||
89 | glVertex3f(x,0.5,0.5); |
||
90 | |||
91 | // the bottom |
||
92 | glColor3f(x+0.5,0,0); |
||
93 | glVertex3f(x,-0.5,-0.5); |
||
94 | glColor3f(x+0.5,0,1); |
||
95 | glVertex3f(x,-0.5,0.5); |
||
96 | } |
||
97 | |||
98 | for(z=-0.5;z<=0.5;z+=CUBE_STEP) |
||
99 | { |
||
100 | // the top |
||
101 | glColor3f(0,1,z+0.5); |
||
102 | glVertex3f(-0.5,0.5,z); |
||
103 | glColor3f(1,1,z+0.5); |
||
104 | glVertex3f(0.5,0.5,z); |
||
105 | |||
106 | // the bottom |
||
107 | glColor3f(0,0,z+0.5); |
||
108 | glVertex3f(-0.5,-0.5,z); |
||
109 | glColor3f(1,0,z+0.5); |
||
110 | glVertex3f(0.5,-0.5,z); |
||
111 | |||
112 | // right side |
||
113 | glColor3f(1,1,z+0.5); |
||
114 | glVertex3f(0.5,0.5,z); |
||
115 | glColor3f(1,0,z+0.5); |
||
116 | glVertex3f(0.5,-0.5,z); |
||
117 | |||
118 | // left side |
||
119 | glColor3f(0,1,z+0.5); |
||
120 | glVertex3f(-0.5,0.5,z); |
||
121 | glColor3f(0,0,z+0.5); |
||
122 | glVertex3f(-0.5,-0.5,z); |
||
123 | } |
||
124 | |||
125 | glEnd(); |
||
126 | } |
||
127 | |||
5098 | clevermous | 128 | static void DrawGL() |
1789 | yogev_ezra | 129 | { |
130 | glLoadIdentity(); // устанавливаем еденичную матрицу |
||
131 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
||
132 | |||
133 | glTranslatef(0.0, 0.0, -3.0); |
||
134 | glRotatef(angle, 1.0, 0.0, 0.0); |
||
135 | glRotatef(2.0*angle, 0.0, 1.0, 0.0); |
||
136 | glRotatef(3.0*angle, 0.0, 0.0, 1.0); |
||
137 | |||
138 | draw_cube(); |
||
139 | |||
140 | kosglSwapBuffers(); |
||
141 | } |
||
142 | |||
5098 | clevermous | 143 | static void reshape() |
1789 | yogev_ezra | 144 | { |
145 | __menuet__get_process_table((process_table_entry*)pri,-1); |
||
146 | glViewport(0, 0, pri->winx_size, pri->winy_size-20); |
||
147 | glMatrixMode(GL_PROJECTION); |
||
148 | glLoadIdentity(); |
||
149 | gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0); |
||
150 | glMatrixMode(GL_MODELVIEW); |
||
151 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
||
152 | } |
||
153 | |||
5098 | clevermous | 154 | static void disabletgl() |
1789 | yogev_ezra | 155 | { |
156 | kosglDestroyContext(cgl); |
||
157 | delete pri; |
||
158 | } |
||
159 | |||
5098 | clevermous | 160 | static void draw_window(void) |
1789 | yogev_ezra | 161 | { |
7951 | leency | 162 | __menuet__window_redraw(1); // start redraw |
7954 | leency | 163 | __menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0, |
164 | "Cubeline / F full screen / FPS:"); |
||
7951 | leency | 165 | __menuet__window_redraw(2); // end redraw |
1789 | yogev_ezra | 166 | } |
167 | |||
5098 | clevermous | 168 | int main(void) |
1789 | yogev_ezra | 169 | { |
170 | |||
171 | win.x = 100; |
||
172 | win.y = 100; |
||
173 | win.dx = 400; |
||
174 | win.dy = 400; |
||
175 | |||
176 | draw_window(); |
||
177 | |||
178 | cgl = kosglCreateContext( 0, 0); |
||
179 | kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl); |
||
180 | |||
181 | glMatrixMode(GL_MODELVIEW); |
||
182 | glLoadIdentity(); |
||
183 | |||
184 | glClearDepth(1.0); |
||
185 | glEnable( GL_CULL_FACE ); |
||
186 | glEnable(GL_DEPTH_TEST); |
||
187 | |||
188 | pri=new process_table_entry_; |
||
189 | SysCall(66,1,1); |
||
190 | |||
191 | reshape(); |
||
192 | |||
193 | do{ |
||
194 | |||
195 | if (angle < 360.0) angle += 0.001 + 0.1*Fps (330,8); |
||
196 | else angle = 0.0; |
||
197 | |||
198 | DrawGL(); |
||
199 | |||
200 | switch(__menuet__check_for_event()) |
||
201 | { |
||
202 | case 1: draw_window(); |
||
203 | reshape(); |
||
204 | break; |
||
205 | |||
206 | case 2: |
||
207 | switch(__menuet__getkey()){ |
||
208 | |||
209 | case KEY_F: |
||
210 | if(!FullScreen){ |
||
211 | skin=0; |
||
212 | SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff); |
||
213 | draw_window(); |
||
214 | reshape(); |
||
215 | FullScreen = 1; |
||
216 | } |
||
217 | else{ |
||
218 | skin=3; |
||
219 | draw_window(); |
||
220 | SysCall(67,win.x,win.y,win.dx,win.dy); |
||
221 | reshape(); |
||
222 | FullScreen = 0; |
||
223 | }; |
||
224 | break; |
||
225 | |||
226 | case KEY_ESC: disabletgl(); |
||
5098 | clevermous | 227 | return 0;} |
1789 | yogev_ezra | 228 | break; |
229 | |||
230 | case 3: disabletgl(); |
||
5098 | clevermous | 231 | return 0; |
1789 | yogev_ezra | 232 | } |
233 | }while(1); |
||
234 | }>=0.5;z+=CUBE_STEP) |