Subversion Repositories Kolibri OS

Rev

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