Rev 7954 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7954 | Rev 7955 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | Ïðèìåð âçÿò èç íàáîðà ïðèìåðîâ ê êîìïèëÿòîðó XS Compiler |
2 | Ïðèìåð âçÿò èç íàáîðà ïðèìåðîâ ê êîìïèëÿòîðó XS Compiler |
3 | 3 | ||
4 | iadn |
4 | iadn |
5 | http://www.iadn.narod.ru |
5 | http://www.iadn.narod.ru |
6 | iadn@bk.ru |
6 | iadn@bk.ru |
7 | */ |
7 | */ |
8 | 8 | ||
9 | #include |
9 | #include |
10 | #include |
10 | #include |
11 | #include |
11 | #include |
12 | 12 | ||
13 | #include "SysCall.h" |
13 | #include "SysCall.h" |
14 | #include "ProcessTab.h" |
14 | #include "ProcessTab.h" |
15 | 15 | ||
16 | 16 | ||
17 | int Fps (long x, long y); |
17 | int Fps (long x, long y); |
18 | extern "C"{ |
18 | extern "C"{ |
19 | int main(void); |
19 | int main(void); |
20 | } |
20 | } |
21 | 21 | ||
22 | static struct { |
22 | static struct { |
23 | int x,y; |
23 | int x,y; |
24 | int dx,dy; |
24 | int dx,dy; |
25 | } win; |
25 | } win; |
26 | 26 | ||
27 | #define CUBE_STEP 0.1 |
27 | #define CUBE_STEP 0.1 |
28 | 28 | ||
29 | #define KEY_ESC 1 |
29 | #define KEY_ESC 1 |
30 | #define KEY_F 33 |
30 | #define KEY_F 33 |
- | 31 | ||
- | 32 | static char title1[] = "TinyGL in KolibriOS"; |
|
- | 33 | static char title2[] = "F full screen"; |
|
- | 34 | static char title3[] = "ESC - exit"; |
|
- | 35 | static char fps[] = "FPS:"; |
|
31 | 36 | ||
32 | static unsigned char FullScreen = 0; |
37 | static unsigned char FullScreen = 0; |
33 | static unsigned char skin = 3; |
38 | static unsigned char skin = 3; |
34 | 39 | ||
35 | static float angle; |
40 | static float angle; |
36 | static process_table_entry_* pri; |
41 | static process_table_entry_* pri; |
37 | static KOSGLContext cgl; |
42 | static KOSGLContext cgl; |
38 | 43 | ||
39 | static void draw_cube() |
44 | static void draw_cube() |
40 | { |
45 | { |
41 | float x,y,z; |
46 | float x,y,z; |
42 | glBegin(GL_LINES); |
47 | glBegin(GL_LINES); |
43 | 48 | ||
44 | for(y=-0.5;y<=0.5;y+=CUBE_STEP) |
49 | for(y=-0.5;y<=0.5;y+=CUBE_STEP) |
45 | { |
50 | { |
46 | // the front |
51 | // the front |
47 | glColor3f(0,y+0.5,0); |
52 | glColor3f(0,y+0.5,0); |
48 | glVertex3f(-0.5,y,-0.5); |
53 | glVertex3f(-0.5,y,-0.5); |
49 | glColor3f(1,y+0.5,0); |
54 | glColor3f(1,y+0.5,0); |
50 | glVertex3f(0.5,y,-0.5); |
55 | glVertex3f(0.5,y,-0.5); |
51 | 56 | ||
52 | // the back |
57 | // the back |
53 | glColor3f(0,y+0.5,1); |
58 | glColor3f(0,y+0.5,1); |
54 | glVertex3f(-0.5,y,0.5); |
59 | glVertex3f(-0.5,y,0.5); |
55 | glColor3f(1,y+0.5,1); |
60 | glColor3f(1,y+0.5,1); |
56 | glVertex3f(0.5,y,0.5); |
61 | glVertex3f(0.5,y,0.5); |
57 | 62 | ||
58 | //right side |
63 | //right side |
59 | glColor3f(1,y+0.5,0); |
64 | glColor3f(1,y+0.5,0); |
60 | glVertex3f(0.5,y,-0.5); |
65 | glVertex3f(0.5,y,-0.5); |
61 | glColor3f(1,y+0.5,1); |
66 | glColor3f(1,y+0.5,1); |
62 | glVertex3f(0.5,y,0.5); |
67 | glVertex3f(0.5,y,0.5); |
63 | 68 | ||
64 | //left side |
69 | //left side |
65 | glColor3f(0,y+0.5,0); |
70 | glColor3f(0,y+0.5,0); |
66 | glVertex3f(-0.5,y,-0.5); |
71 | glVertex3f(-0.5,y,-0.5); |
67 | glColor3f(0,y+0.5,1); |
72 | glColor3f(0,y+0.5,1); |
68 | glVertex3f(-0.5,y,0.5); |
73 | glVertex3f(-0.5,y,0.5); |
69 | } |
74 | } |
70 | 75 | ||
71 | for(x=-0.5;x<=0.5;x+=CUBE_STEP) |
76 | for(x=-0.5;x<=0.5;x+=CUBE_STEP) |
72 | { |
77 | { |
73 | // the front |
78 | // the front |
74 | glColor3f(x+0.5,1,0); |
79 | glColor3f(x+0.5,1,0); |
75 | glVertex3f(x,0.5,-0.5); |
80 | glVertex3f(x,0.5,-0.5); |
76 | glColor3f(x+0.5,0,0); |
81 | glColor3f(x+0.5,0,0); |
77 | glVertex3f(x,-0.5,-0.5); |
82 | glVertex3f(x,-0.5,-0.5); |
78 | 83 | ||
79 | // the back |
84 | // the back |
80 | glColor3f(x+0.5,1,1); |
85 | glColor3f(x+0.5,1,1); |
81 | glVertex3f(x,0.5,0.5); |
86 | glVertex3f(x,0.5,0.5); |
82 | glColor3f(x+0.5,0,1); |
87 | glColor3f(x+0.5,0,1); |
83 | glVertex3f(x,-0.5,0.5); |
88 | glVertex3f(x,-0.5,0.5); |
84 | 89 | ||
85 | // the top |
90 | // the top |
86 | glColor3f(x+0.5,1,0); |
91 | glColor3f(x+0.5,1,0); |
87 | glVertex3f(x,0.5,-0.5); |
92 | glVertex3f(x,0.5,-0.5); |
88 | glColor3f(x+0.5,1,1); |
93 | glColor3f(x+0.5,1,1); |
89 | glVertex3f(x,0.5,0.5); |
94 | glVertex3f(x,0.5,0.5); |
90 | 95 | ||
91 | // the bottom |
96 | // the bottom |
92 | glColor3f(x+0.5,0,0); |
97 | glColor3f(x+0.5,0,0); |
93 | glVertex3f(x,-0.5,-0.5); |
98 | glVertex3f(x,-0.5,-0.5); |
94 | glColor3f(x+0.5,0,1); |
99 | glColor3f(x+0.5,0,1); |
95 | glVertex3f(x,-0.5,0.5); |
100 | glVertex3f(x,-0.5,0.5); |
96 | } |
101 | } |
97 | 102 | ||
98 | for(z=-0.5;z<=0.5;z+=CUBE_STEP) |
103 | for(z=-0.5;z<=0.5;z+=CUBE_STEP) |
99 | { |
104 | { |
100 | // the top |
105 | // the top |
101 | glColor3f(0,1,z+0.5); |
106 | glColor3f(0,1,z+0.5); |
102 | glVertex3f(-0.5,0.5,z); |
107 | glVertex3f(-0.5,0.5,z); |
103 | glColor3f(1,1,z+0.5); |
108 | glColor3f(1,1,z+0.5); |
104 | glVertex3f(0.5,0.5,z); |
109 | glVertex3f(0.5,0.5,z); |
105 | 110 | ||
106 | // the bottom |
111 | // the bottom |
107 | glColor3f(0,0,z+0.5); |
112 | glColor3f(0,0,z+0.5); |
108 | glVertex3f(-0.5,-0.5,z); |
113 | glVertex3f(-0.5,-0.5,z); |
109 | glColor3f(1,0,z+0.5); |
114 | glColor3f(1,0,z+0.5); |
110 | glVertex3f(0.5,-0.5,z); |
115 | glVertex3f(0.5,-0.5,z); |
111 | 116 | ||
112 | // right side |
117 | // right side |
113 | glColor3f(1,1,z+0.5); |
118 | glColor3f(1,1,z+0.5); |
114 | glVertex3f(0.5,0.5,z); |
119 | glVertex3f(0.5,0.5,z); |
115 | glColor3f(1,0,z+0.5); |
120 | glColor3f(1,0,z+0.5); |
116 | glVertex3f(0.5,-0.5,z); |
121 | glVertex3f(0.5,-0.5,z); |
117 | 122 | ||
118 | // left side |
123 | // left side |
119 | glColor3f(0,1,z+0.5); |
124 | glColor3f(0,1,z+0.5); |
120 | glVertex3f(-0.5,0.5,z); |
125 | glVertex3f(-0.5,0.5,z); |
121 | glColor3f(0,0,z+0.5); |
126 | glColor3f(0,0,z+0.5); |
122 | glVertex3f(-0.5,-0.5,z); |
127 | glVertex3f(-0.5,-0.5,z); |
123 | } |
128 | } |
124 | 129 | ||
125 | glEnd(); |
130 | glEnd(); |
126 | } |
131 | } |
127 | 132 | ||
128 | static void DrawGL() |
133 | static void DrawGL() |
129 | { |
134 | { |
130 | glLoadIdentity(); // óñòàíàâëèâàåì åäåíè÷íóþ ìàòðèöó |
135 | glLoadIdentity(); // óñòàíàâëèâàåì åäåíè÷íóþ ìàòðèöó |
131 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
136 | glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); |
132 | 137 | ||
133 | glTranslatef(0.0, 0.0, -3.0); |
138 | glTranslatef(0.0, 0.0, -3.0); |
134 | glRotatef(angle, 1.0, 0.0, 0.0); |
139 | glRotatef(angle, 1.0, 0.0, 0.0); |
135 | glRotatef(2.0*angle, 0.0, 1.0, 0.0); |
140 | glRotatef(2.0*angle, 0.0, 1.0, 0.0); |
136 | glRotatef(3.0*angle, 0.0, 0.0, 1.0); |
141 | glRotatef(3.0*angle, 0.0, 0.0, 1.0); |
137 | 142 | ||
138 | draw_cube(); |
143 | draw_cube(); |
139 | 144 | ||
140 | kosglSwapBuffers(); |
145 | kosglSwapBuffers(); |
141 | } |
146 | } |
142 | 147 | ||
143 | static void reshape() |
148 | static void reshape() |
144 | { |
149 | { |
145 | __menuet__get_process_table((process_table_entry*)pri,-1); |
150 | __menuet__get_process_table((process_table_entry*)pri,-1); |
146 | glViewport(0, 0, pri->winx_size, pri->winy_size-20); |
151 | glViewport(0, 0, pri->winx_size, pri->winy_size-20); |
147 | glMatrixMode(GL_PROJECTION); |
152 | glMatrixMode(GL_PROJECTION); |
148 | glLoadIdentity(); |
153 | glLoadIdentity(); |
149 | gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0); |
154 | gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0); |
150 | glMatrixMode(GL_MODELVIEW); |
155 | glMatrixMode(GL_MODELVIEW); |
151 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
156 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
152 | } |
157 | } |
153 | 158 | ||
154 | static void disabletgl() |
159 | static void disabletgl() |
155 | { |
160 | { |
156 | kosglDestroyContext(cgl); |
161 | kosglDestroyContext(cgl); |
157 | delete pri; |
162 | delete pri; |
158 | } |
163 | } |
- | 164 | ||
- | 165 | static void Title() |
|
- | 166 | { |
|
- | 167 | __menuet__write_text(300,8,0x10ffffff,fps,strlen(fps)); |
|
- | 168 | __menuet__write_text(8,8,0x10ffffff,title1,strlen(title1)); |
|
- | 169 | __menuet__write_text(180,8,0x00ffffff,title2,strlen(title2)); |
|
- | 170 | __menuet__write_text(600,8,0x00ffffff,title3,strlen(title3)); |
|
- | 171 | } |
|
159 | 172 | ||
160 | static void draw_window(void) |
173 | static void draw_window(void) |
- | 174 | { |
|
161 | { |
175 | // start redraw |
- | 176 | __menuet__window_redraw(1); |
|
162 | __menuet__window_redraw(1); // start redraw |
177 | // define&draw window |
163 | __menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0, |
178 | __menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0); |
164 | "Cubeline / F full screen / FPS:"); |
179 | // end redraw |
- | 180 | __menuet__window_redraw(2); |
|
- | 181 | // display string |
|
165 | __menuet__window_redraw(2); // end redraw |
182 | Title(); |
166 | } |
183 | } |
167 | 184 | ||
168 | int main(void) |
185 | int main(void) |
169 | { |
186 | { |
170 | 187 | ||
171 | win.x = 100; |
188 | win.x = 100; |
172 | win.y = 100; |
189 | win.y = 100; |
173 | win.dx = 400; |
190 | win.dx = 400; |
174 | win.dy = 400; |
191 | win.dy = 400; |
175 | 192 | ||
176 | draw_window(); |
193 | draw_window(); |
177 | 194 | ||
178 | cgl = kosglCreateContext( 0, 0); |
195 | cgl = kosglCreateContext( 0, 0); |
179 | kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl); |
196 | kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl); |
180 | 197 | ||
181 | glMatrixMode(GL_MODELVIEW); |
198 | glMatrixMode(GL_MODELVIEW); |
182 | glLoadIdentity(); |
199 | glLoadIdentity(); |
183 | 200 | ||
184 | glClearDepth(1.0); |
201 | glClearDepth(1.0); |
185 | glEnable( GL_CULL_FACE ); |
202 | glEnable( GL_CULL_FACE ); |
186 | glEnable(GL_DEPTH_TEST); |
203 | glEnable(GL_DEPTH_TEST); |
187 | 204 | ||
188 | pri=new process_table_entry_; |
205 | pri=new process_table_entry_; |
189 | SysCall(66,1,1); |
206 | SysCall(66,1,1); |
190 | 207 | ||
191 | reshape(); |
208 | reshape(); |
192 | 209 | ||
193 | do{ |
210 | do{ |
194 | 211 | ||
195 | if (angle < 360.0) angle += 0.001 + 0.1*Fps (330,8); |
212 | if (angle < 360.0) angle += 0.001 + 0.1*Fps (330,8); |
196 | else angle = 0.0; |
213 | else angle = 0.0; |
197 | 214 | ||
198 | DrawGL(); |
215 | DrawGL(); |
199 | 216 | ||
200 | switch(__menuet__check_for_event()) |
217 | switch(__menuet__check_for_event()) |
201 | { |
218 | { |
202 | case 1: draw_window(); |
219 | case 1: draw_window(); |
203 | reshape(); |
220 | reshape(); |
204 | break; |
221 | break; |
205 | 222 | ||
206 | case 2: |
223 | case 2: |
207 | switch(__menuet__getkey()){ |
224 | switch(__menuet__getkey()){ |
208 | 225 | ||
209 | case KEY_F: |
226 | case KEY_F: |
210 | if(!FullScreen){ |
227 | if(!FullScreen){ |
211 | skin=0; |
228 | skin=0; |
212 | SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff); |
229 | SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff); |
213 | draw_window(); |
230 | draw_window(); |
214 | reshape(); |
231 | reshape(); |
215 | FullScreen = 1; |
232 | FullScreen = 1; |
216 | } |
233 | } |
217 | else{ |
234 | else{ |
218 | skin=3; |
235 | skin=3; |
219 | draw_window(); |
236 | draw_window(); |
220 | SysCall(67,win.x,win.y,win.dx,win.dy); |
237 | SysCall(67,win.x,win.y,win.dx,win.dy); |
221 | reshape(); |
238 | reshape(); |
222 | FullScreen = 0; |
239 | FullScreen = 0; |
223 | }; |
240 | }; |
224 | break; |
241 | break; |
225 | 242 | ||
226 | case KEY_ESC: disabletgl(); |
243 | case KEY_ESC: disabletgl(); |
227 | return 0;} |
244 | return 0;} |
228 | break; |
245 | break; |
229 | 246 | ||
230 | case 3: disabletgl(); |
247 | case 3: disabletgl(); |
231 | return 0; |
248 | return 0; |
232 | } |
249 | } |
233 | }while(1); |
250 | }while(1); |
234 | }>=0.5;z+=CUBE_STEP) |
251 | }>=0.5;z+=CUBE_STEP) |
235 | >=0.5;x+=CUBE_STEP) |
252 | >=0.5;x+=CUBE_STEP) |
236 | >=0.5;y+=CUBE_STEP) |
253 | >=0.5;y+=CUBE_STEP) |
237 | > |
254 | > |