Subversion Repositories Kolibri OS

Rev

Rev 8528 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8528 Rev 8530
Line 10... Line 10...
10
 * 3-D gear wheels.  This program is in the public domain.
10
 * 3-D gear wheels.  This program is in the public domain.
11
 *
11
 *
12
 * Brian Paul
12
 * Brian Paul
13
 */
13
 */
Line -... Line 14...
-
 
14
 
-
 
15
/*
-
 
16
 * Newlib port by maxcodehack
-
 
17
 */
14
 
18
 
15
#include  
19
#include  
16
#include  //TinyGL
20
#include  // TinyGL
17
#include 
21
#include 
Line 18... Line 22...
18
#include 
22
#include 
19
 
-
 
Line 20... Line 23...
20
#include "SysCall.h"
23
 
21
#include "ProcessTab.h"
-
 
22
 
-
 
23
int Fps (long x, long y);
-
 
Line 24... Line 24...
24
extern "C"{
24
#include "SysCall.h"
25
int main(void);
25
 
26
}
26
int Fps (long x, long y);
27
 
27
 
Line 28... Line 28...
28
struct {
28
struct {
29
	   int x,y;
29
	int x,y;
Line 30... Line -...
30
	   int dx,dy;
-
 
31
	   } win;
30
	int dx,dy;
32
 
-
 
33
#define KEY_ESC       1
31
} win;
Line 34... Line 32...
34
#define KEY_F     	 33
32
 
35
 
33
#define KEY_ESC       1
-
 
34
#define KEY_F     	 33
-
 
35
 
Line 36... Line 36...
36
char *title1 = "TinyGL in KolibriOS";
36
char *title = "Gears (F - full screen, ESC - exit)";
37
char *title2 = "F full screen";
37
char *fps    = "FPS:";
Line 38... Line 38...
38
char *title3 = "ESC - exit";
38
 
Line 171... Line 171...
171
      glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
171
	  glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 );
172
   }
172
	}
173
   glEnd();      
173
	glEnd();
174
}
174
}
Line 175... Line 175...
175
 
175
 
176
void init( void )
176
void init()
177
{
177
{
178
   static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 };
178
	static GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0 };
179
   static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
179
	static GLfloat red[4] = {0.8, 0.1, 0.0, 1.0 };
180
   static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
180
	static GLfloat green[4] = {0.0, 0.8, 0.2, 1.0 };
Line 241... Line 241...
241
};
241
};
Line 242... Line 242...
242
 
242
 
243
void Title()
243
void Title()
244
{
244
{
245
     kos_text(300,8,0x10ffffff,fps,strlen(fps));
245
     kos_text(300,8,0x10ffffff,fps,strlen(fps));
246
	 kos_text(180,8,0x00ffffff,title2,strlen(title2));
246
	 /*kos_text(180,8,0x90ffffff,title2,strlen(title2));
247
     kos_text(600,8,0x00ffffff,title3,strlen(title3));
247
     kos_text(600,8,0x90ffffff,title3,strlen(title3));*/
Line 248... Line -...
248
}
-
 
249
 
-
 
250
void kol_wnd_define(unsigned x, unsigned y, unsigned w, unsigned h, unsigned cs, unsigned b, char *t)
-
 
251
{
-
 
252
asm volatile ("int $0x40"::"a"(0), "b"(x*65536+w), "c"(y*65536+h), "d"(cs), "D"(t), "S"(b) );
-
 
253
}
248
}
254
 
249
 
255
void draw_window(void)
250
void draw_window()
256
{
251
{
257
	// start redraw
252
	// start redraw
258
	begin_draw();
253
	begin_draw();
259
	// define&draw window
254
	// define&draw window
260
	kol_wnd_define(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,title1);
255
	sys_create_window(win.x, win.y, win.dx, win.dy, title, 0, /*TYPEWIN(0,0,0,1,skin,0,0,0)*/skin);
261
    // end redraw
256
    // end redraw
262
    end_draw();
257
    end_draw();
263
    // display string
258
    // display string
Line 264... Line 259...
264
    Title();
259
    Title();
265
}
260
}
266
 
-
 
267
int kos_get_key()
-
 
268
{
-
 
269
	unsigned short __ret;
-
 
270
	asm volatile("int $0x40":"=a"(__ret):"0"(2));
-
 
271
	if(!(__ret & 0xFF)) return (__ret>>8)&0xFF; else return 0;
-
 
272
}
-
 
273
 
-
 
274
int main(void)          
261
 
275
{
262
int main()          
276
 
263
{
277
  win.x = 100;
264
	win.x = 100;
Line 278... Line 265...
278
  win.y = 100;
265
	win.y = 100;
Line 279... Line 266...
279
  win.dx = 400;
266
	win.dx = 400;
280
  win.dy = 400;	 
267
	win.dy = 400;	 
Line 281... Line 268...
281
 
268
 
Line 282... Line 269...
282
  draw_window();
269
	draw_window();
283
 
270
 
Line 284... Line 271...
284
  cgl = kosglCreateContext( 0, 0);
271
	cgl = kosglCreateContext( 0, 0);
Line 285... Line 272...
285
  kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl);
272
	kosglMakeCurrent( 0, 0, win.dx, win.dy, cgl);
286
 
-
 
287
  init();
273
 
Line 288... Line 274...
288
 
274
	init();
289
  pri = new proc_info;
275
 
290
  SysCall(66,1,1);
276
	pri = new proc_info;
Line 322... Line 308...
322
   
308
 
Line 323... Line 309...
323
 kosglSwapBuffers();
309
		kosglSwapBuffers();
Line 324... Line 310...
324
 
310
 
325
 angle += 0.01 + 0.3* Fps (330,8);
311
		angle += 0.01 + 0.3 * Fps (330, 8);
-
 
312
				
326
 			
313
		switch(check_os_event())
327
		  switch(SysCall(11))
314
		{
328
		      {
315
			case 1:
Line 329... Line 316...
329
		          case 1: draw_window();				  	   	  
316
				draw_window();
-
 
317
				reshape();
330
				  	   	  reshape();
318
				break;
331
				  	   	  break;
-
 
332
				  	   	  
319
					  
333
		          case 2: 		          
320
			case 2:	          
334
		          	   switch(kos_get_key()){
321
				   key = get_key();
335
 
322
				   switch(key.code) {
336
						   case KEY_F:
323
						case KEY_F:
337
                                    if(!FullScreen){									 
324
							if(!FullScreen){									 
338
									 skin=0;
325
								skin=0x01;
339
									 SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff);
326
								SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff);
340
									 draw_window();
327
								draw_window();
341
									 reshape();
328
								reshape();
342
									 FullScreen = 1;
329
								FullScreen = 1;
343
									}
330
							}
344
									else{
331
							else{
345
									 skin=3;
332
								skin=0x34;
346
									 draw_window();
333
								draw_window();
347
									 SysCall(67,win.x,win.y,win.dx,win.dy);
334
								SysCall(67,win.x,win.y,win.dx,win.dy);
Line 348... Line 335...
348
									 reshape();
335
								reshape();
-
 
336
								FullScreen = 0;
349
									 FullScreen = 0;
337
							};
-
 
338
							break;
350
									};
339
			  
Line -... Line 340...
-
 
340
					   case KEY_ESC: 
351
						  			break;
341
								disabletgl();
352
		          
342
								return 0;
353
                           case KEY_ESC: disabletgl();
343
					}
354
						  				 return 0;}
344
					break;
355
						  				 break;
345