From 14bea4fd5097f292b6600e6ae65903ee46396fa7 Mon Sep 17 00:00:00 2001 From: Ivan Baravy Date: Mon, 15 Jan 2024 03:32:24 +0000 Subject: [PATCH] Update demos/gears to use sys/ksys.h git-svn-id: svn://kolibrios.org@9965 a494cfbc-eb01-0410-851d-a64ba20cac60 --- data/Tupfile.lua | 1 + programs/demos/gears/Tupfile.lua | 10 + programs/demos/gears/fps.c | 45 ++++ programs/demos/gears/main.c | 344 +++++++++++++++++++++++++++++++ 4 files changed, 400 insertions(+) create mode 100644 programs/demos/gears/Tupfile.lua create mode 100644 programs/demos/gears/fps.c create mode 100644 programs/demos/gears/main.c diff --git a/data/Tupfile.lua b/data/Tupfile.lua index 0b15ca3bd1..6ddfcd6709 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -738,6 +738,7 @@ tup.append_table(img_files, { }) tup.append_table(extra_files, { -- {"kolibrios/3D/cubeline", PROGS .. "/demos/cubeline/trunk/cubeline"}, + {"kolibrios/3D/gears", PROGS .. "/demos/gears/gears"}, {"kolibrios/emul/e80/e80", PROGS .. "/emulator/e80/trunk/e80"}, {"kolibrios/emul/uarm/", "../contrib/other/uarm/uARM"}, {"kolibrios/games/2048", PROGS .. "/games/2048/2048"}, diff --git a/programs/demos/gears/Tupfile.lua b/programs/demos/gears/Tupfile.lua new file mode 100644 index 0000000000..e01dfad3af --- /dev/null +++ b/programs/demos/gears/Tupfile.lua @@ -0,0 +1,10 @@ +if tup.getconfig("NO_GCC") ~= "" then return end +HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") +tup.include(HELPERDIR .. "/use_gcc.lua") +tup.include(HELPERDIR .. "/use_newlib.lua") +tup.include(HELPERDIR .. "/use_tinygl.lua") + +LDFLAGS = LDFLAGS .. " --subsystem native" + +compile_gcc{"fps.c", "main.c"} +link_gcc("gears") diff --git a/programs/demos/gears/fps.c b/programs/demos/gears/fps.c new file mode 100644 index 0000000000..5f84de22db --- /dev/null +++ b/programs/demos/gears/fps.c @@ -0,0 +1,45 @@ +#include + +/* +Calculate and draw FPS +x,y - window relative coordinates to draw FPS info + +Returns the number of centiseconds (cs) spent in one drawing cycle +*/ + +int time1=0; +int time2=0; +int fps1=0; +int timerend=0; + +int Fps (long x, long y) +{ + int tr; + + time1 = _ksys_get_tick_count(); // time in cs since boot + + if (timerend==0) + { + time2 = time1; + timerend = time1; + } + + tr = time1 - timerend; + + if ((time1 - time2) < 100) // if passed less than one second + { + fps1++; + } + else + { + // draw FPS info + _ksys_draw_bar(x, y, 23, 7, 0x00555555); + _ksys_draw_number(fps1, x, y, 4, 0xfafafa); + fps1 = 0; + time2 = time1; + } + + timerend = time1; + + return tr; +} diff --git a/programs/demos/gears/main.c b/programs/demos/gears/main.c new file mode 100644 index 0000000000..367fcc6a29 --- /dev/null +++ b/programs/demos/gears/main.c @@ -0,0 +1,344 @@ +/* + Initial version was a Mesa example + + iadn + http://www.iadn.narod.ru + iadn@bk.ru +*/ + +/* + * 3-D gear wheels. This program is in the public domain. + * + * Brian Paul + */ + +/* + * Newlib port by maxcodehack + */ + +#include +#include // TinyGL +#include +#include + +int Fps (long x, long y); + +struct { + int x,y; + int dx,dy; +} win; + +#define KEY_ESC 1 +#define KEY_F 33 + +char *title = "Gears (F - full screen, ESC - exit)"; +char *fps = "FPS:"; + +unsigned char FullScreen = 0; +unsigned char skin = 0x34; + +ksys_oskey_t key; + +ksys_thread_t pri; +KOSGLContext cgl; + +static GLfloat view_rotx = 20.0, view_roty = 30.0, view_rotz = 0.0; +static GLint gear1, gear2, gear3; +static GLfloat angle = 0.0; + +static GLuint limit; +static GLuint count = 1; + +/* + * Draw a gear wheel. You'll probably want to call this function when + * building a display list since we do a lot of trig here. + * + * Input: inner_radius - radius of hole at center + * outer_radius - radius at center of teeth + * width - width of gear + * teeth - number of teeth + * tooth_depth - depth of tooth + */ +static void gear( GLfloat inner_radius, GLfloat outer_radius, GLfloat width, + GLint teeth, GLfloat tooth_depth ) +{ + GLint i; + GLfloat r0, r1, r2; + GLfloat angle, da; + GLfloat u, v, len; + + r0 = inner_radius; + r1 = outer_radius - tooth_depth/2.0; + r2 = outer_radius + tooth_depth/2.0; + + da = 2.0*M_PI / teeth / 4.0; + + glShadeModel( GL_FLAT ); + + glNormal3f( 0.0, 0.0, 1.0 ); + + /* draw front face */ + glBegin( GL_QUAD_STRIP ); + for (i=0;i<=teeth;i++) { + angle = i * 2.0*M_PI / teeth; + glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 ); + glVertex3f( r1*cos(angle), r1*sin(angle), width*0.5 ); + glVertex3f( r0*cos(angle), r0*sin(angle), width*0.5 ); + glVertex3f( r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5 ); + } + glEnd(); + + /* draw front sides of teeth */ + glBegin( GL_QUADS ); + da = 2.0*M_PI / teeth / 4.0; + for (i=0;i