Add 'cubeline', 'cubetext' and 'gears' source code to SVN.
git-svn-id: svn://kolibrios.org@1789 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
251
programs/demos/cubeline/trunk/main.cpp
Normal file
251
programs/demos/cubeline/trunk/main.cpp
Normal file
@@ -0,0 +1,251 @@
|
||||
/*
|
||||
<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> XS Compiler
|
||||
|
||||
iadn
|
||||
http://www.iadn.narod.ru
|
||||
iadn@bk.ru
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include<menuet/os.h>
|
||||
#include <kosgl.h> //TinyGL
|
||||
|
||||
#include "SysCall.h"
|
||||
#include "ProcessTab.h"
|
||||
|
||||
|
||||
int Fps (long x, long y);
|
||||
extern "C"{
|
||||
void app_main(void);
|
||||
}
|
||||
|
||||
struct {
|
||||
int x,y;
|
||||
int dx,dy;
|
||||
} win;
|
||||
|
||||
#define CUBE_STEP 0.1
|
||||
|
||||
#define KEY_ESC 1
|
||||
#define KEY_F 33
|
||||
|
||||
char *title1 = "TinyGL in KolibriOS";
|
||||
char *title2 = "F full screen";
|
||||
char *title3 = "ESC - exit";
|
||||
char *fps = "FPS:";
|
||||
|
||||
unsigned char FullScreen = 0;
|
||||
unsigned char skin = 3;
|
||||
|
||||
float angle;
|
||||
process_table_entry_* pri;
|
||||
KOSGLContext cgl;
|
||||
|
||||
void draw_cube()
|
||||
{
|
||||
float x,y,z;
|
||||
glBegin(GL_LINES);
|
||||
|
||||
for(y=-0.5;y<=0.5;y+=CUBE_STEP)
|
||||
{
|
||||
// the front
|
||||
glColor3f(0,y+0.5,0);
|
||||
glVertex3f(-0.5,y,-0.5);
|
||||
glColor3f(1,y+0.5,0);
|
||||
glVertex3f(0.5,y,-0.5);
|
||||
|
||||
// the back
|
||||
glColor3f(0,y+0.5,1);
|
||||
glVertex3f(-0.5,y,0.5);
|
||||
glColor3f(1,y+0.5,1);
|
||||
glVertex3f(0.5,y,0.5);
|
||||
|
||||
//right side
|
||||
glColor3f(1,y+0.5,0);
|
||||
glVertex3f(0.5,y,-0.5);
|
||||
glColor3f(1,y+0.5,1);
|
||||
glVertex3f(0.5,y,0.5);
|
||||
|
||||
//left side
|
||||
glColor3f(0,y+0.5,0);
|
||||
glVertex3f(-0.5,y,-0.5);
|
||||
glColor3f(0,y+0.5,1);
|
||||
glVertex3f(-0.5,y,0.5);
|
||||
}
|
||||
|
||||
for(x=-0.5;x<=0.5;x+=CUBE_STEP)
|
||||
{
|
||||
// the front
|
||||
glColor3f(x+0.5,1,0);
|
||||
glVertex3f(x,0.5,-0.5);
|
||||
glColor3f(x+0.5,0,0);
|
||||
glVertex3f(x,-0.5,-0.5);
|
||||
|
||||
// the back
|
||||
glColor3f(x+0.5,1,1);
|
||||
glVertex3f(x,0.5,0.5);
|
||||
glColor3f(x+0.5,0,1);
|
||||
glVertex3f(x,-0.5,0.5);
|
||||
|
||||
// the top
|
||||
glColor3f(x+0.5,1,0);
|
||||
glVertex3f(x,0.5,-0.5);
|
||||
glColor3f(x+0.5,1,1);
|
||||
glVertex3f(x,0.5,0.5);
|
||||
|
||||
// the bottom
|
||||
glColor3f(x+0.5,0,0);
|
||||
glVertex3f(x,-0.5,-0.5);
|
||||
glColor3f(x+0.5,0,1);
|
||||
glVertex3f(x,-0.5,0.5);
|
||||
}
|
||||
|
||||
for(z=-0.5;z<=0.5;z+=CUBE_STEP)
|
||||
{
|
||||
// the top
|
||||
glColor3f(0,1,z+0.5);
|
||||
glVertex3f(-0.5,0.5,z);
|
||||
glColor3f(1,1,z+0.5);
|
||||
glVertex3f(0.5,0.5,z);
|
||||
|
||||
// the bottom
|
||||
glColor3f(0,0,z+0.5);
|
||||
glVertex3f(-0.5,-0.5,z);
|
||||
glColor3f(1,0,z+0.5);
|
||||
glVertex3f(0.5,-0.5,z);
|
||||
|
||||
// right side
|
||||
glColor3f(1,1,z+0.5);
|
||||
glVertex3f(0.5,0.5,z);
|
||||
glColor3f(1,0,z+0.5);
|
||||
glVertex3f(0.5,-0.5,z);
|
||||
|
||||
// left side
|
||||
glColor3f(0,1,z+0.5);
|
||||
glVertex3f(-0.5,0.5,z);
|
||||
glColor3f(0,0,z+0.5);
|
||||
glVertex3f(-0.5,-0.5,z);
|
||||
}
|
||||
|
||||
glEnd();
|
||||
}
|
||||
|
||||
void DrawGL()
|
||||
{
|
||||
glLoadIdentity(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glTranslatef(0.0, 0.0, -3.0);
|
||||
glRotatef(angle, 1.0, 0.0, 0.0);
|
||||
glRotatef(2.0*angle, 0.0, 1.0, 0.0);
|
||||
glRotatef(3.0*angle, 0.0, 0.0, 1.0);
|
||||
|
||||
draw_cube();
|
||||
|
||||
kosglSwapBuffers();
|
||||
}
|
||||
|
||||
void reshape()
|
||||
{
|
||||
__menuet__get_process_table((process_table_entry*)pri,-1);
|
||||
glViewport(0, 0, pri->winx_size, pri->winy_size-20);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
gluPerspective(45.0, (GLfloat)pri->winx_size/pri->winy_size, 1.0, 300.0);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||
}
|
||||
|
||||
void disabletgl()
|
||||
{
|
||||
kosglDestroyContext(cgl);
|
||||
delete pri;
|
||||
}
|
||||
|
||||
void Title()
|
||||
{
|
||||
__menuet__write_text(300,8,0x10ffffff,fps,strlen(fps));
|
||||
__menuet__write_text(8,8,0x10ffffff,title1,strlen(title1));
|
||||
__menuet__write_text(180,8,0x00ffffff,title2,strlen(title2));
|
||||
__menuet__write_text(600,8,0x00ffffff,title3,strlen(title3));
|
||||
}
|
||||
|
||||
void draw_window(void)
|
||||
{
|
||||
// start redraw
|
||||
__menuet__window_redraw(1);
|
||||
// define&draw window
|
||||
__menuet__define_window(win.x,win.y,win.dx,win.dy,TYPEWIN(0,0,0,1,skin,0,0,0),0,0);
|
||||
// end redraw
|
||||
__menuet__window_redraw(2);
|
||||
// display string
|
||||
Title();
|
||||
}
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
|
||||
win.x = 100;
|
||||
win.y = 100;
|
||||
win.dx = 400;
|
||||
win.dy = 400;
|
||||
|
||||
draw_window();
|
||||
|
||||
cgl = kosglCreateContext( 0, 0);
|
||||
kosglMakeCurrent( 0, 20, win.dx, win.dy-20, cgl);
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
glClearDepth(1.0);
|
||||
glEnable( GL_CULL_FACE );
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
pri=new process_table_entry_;
|
||||
SysCall(66,1,1);
|
||||
|
||||
reshape();
|
||||
|
||||
do{
|
||||
|
||||
if (angle < 360.0) angle += 0.001 + 0.1*Fps (330,8);
|
||||
else angle = 0.0;
|
||||
|
||||
DrawGL();
|
||||
|
||||
switch(__menuet__check_for_event())
|
||||
{
|
||||
case 1: draw_window();
|
||||
reshape();
|
||||
break;
|
||||
|
||||
case 2:
|
||||
switch(__menuet__getkey()){
|
||||
|
||||
case KEY_F:
|
||||
if(!FullScreen){
|
||||
skin=0;
|
||||
SysCall(67,0,0,SysCall(14)>>16,SysCall(14)&0xffff);
|
||||
draw_window();
|
||||
reshape();
|
||||
FullScreen = 1;
|
||||
}
|
||||
else{
|
||||
skin=3;
|
||||
draw_window();
|
||||
SysCall(67,win.x,win.y,win.dx,win.dy);
|
||||
reshape();
|
||||
FullScreen = 0;
|
||||
};
|
||||
break;
|
||||
|
||||
case KEY_ESC: disabletgl();
|
||||
return;}
|
||||
break;
|
||||
|
||||
case 3: disabletgl();
|
||||
return;
|
||||
}
|
||||
}while(1);
|
||||
}
|
Reference in New Issue
Block a user