Example #1
0
void GameMenu::RunGameMenu2(void)
{
    while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar())
    {
        FsPollDevice();
    }
    
    key=FSKEY_NULL;
    for(;;)
    {
        FsPollDevice();
        key=FsInkey();
        
        if(key==FSKEY_ESC || key==FSKEY_S || key==FSKEY_M)
        {
            return;
        }
        
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        
        Initialize();
		DrawBackground();
		DrawObjects();
		DrawWelcomeText();
		DrawLogo(25, 575);
        
        FsSwapBuffers();
        FsSleep(20);
    }
}
Example #2
0
File: main.cpp Project: HLH15/24783
/* virtual */ void FsLazyWindowApplication::Draw(void)
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glUseProgram(sampler2d.programIdent);
	const GLfloat vtx[12]=
	{
		-1,-1,0,
		 1,-1,0,
		 1, 1,0,
		-1, 1,0
	};
	const GLfloat texCoord[8]=
	{
		0,0, 0,1, 1,1, 1,0
	};

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,texIdent);

	// GL_TEXTURE0 -> 0.  Don't use GL_TEXTURE0! (Frequent confusion).
	glUniform1i(sampler2d.uniformTexIdentPos,0); 
	glEnableVertexAttribArray(sampler2d.attribVertexPos);
	glVertexAttribPointer(sampler2d.attribVertexPos,3,GL_FLOAT,GL_FALSE,0,vtx);
	glEnableVertexAttribArray(sampler2d.attribTexCoordPos);
	glVertexAttribPointer(sampler2d.attribTexCoordPos,2,GL_FLOAT,GL_FALSE,0,texCoord);
	glDrawArrays(GL_TRIANGLE_FAN,0,4);
	glDisableVertexAttribArray(sampler2d.attribVertexPos);
	glDisableVertexAttribArray(sampler2d.attribTexCoordPos);

	FsSwapBuffers();

	needRedraw=false;
}
Example #3
0
int TextInput::Input(char score[])
{
    Ocean2 ocean;
    ocean.ReadFigure();
    Congratulation cong;
    cong.ReadFigure();
    
    FsPollDevice();
    while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar())
    {
        FsPollDevice();
    }
    int count=0;

    for(;;)
    {
        FsPollDevice();
        
        int key=FsInkey();
        
        switch(key)
        {
            case FSKEY_ESC:
                return 0;
            case FSKEY_ENTER:
                return 1;
            case FSKEY_BS:
                str.BackSpace();
                count--;
                break;
        }
        
        const char c=FsInkeyChar();
        
        if(0!=c && 0!=isprint(c) && count<10)
        {
            str.Add(c);
            count++;
        }
       
        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
        
        cong.Drawcongratulation_png();
        
        glRasterPos2d(460, 200);
        YsGlDrawFontBitmap20x32("SCORE");

        glRasterPos2d(400, 200+50);
        YsGlDrawFontBitmap20x32(score);
        
        Drawocean2(450);
        ocean.Drawocean_png();
        Draw();
        
        FsSwapBuffers();
        
        FsSleep(20);
    }
    return 0;
}
int main(void)
{
	int key;
	struct YsGLSLBitmapRenderer *bitmapRenderer;
	YsBitmap bmp;

	FsChangeToProgramDir();

	bmp.LoadPng("flash01.png");
	printf("Bitmap dimension %dx%d\n",bmp.GetWidth(),bmp.GetHeight());

	FsOpenWindow(32,32,640,480,1);

	bitmapRenderer=YsGLSLCreateBitmapRenderer();

	key=FSKEY_NULL;
	while(FSKEY_ESC!=key)
	{
		FsPollDevice();

		key=FsInkey();

		int mx,my,lb,mb,rb;
		FsGetMouseState(lb,mb,rb,mx,my);

		int wid,hei;
		FsGetWindowSize(wid,hei);

		glViewport(0,0,wid,hei);

		glClearColor(0.0,0.0,0.0,0.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

		glColor3ub(255,255,255);
		glBegin(GL_LINES);
		glVertex2i(270,240);
		glVertex2i(370,240);
		glVertex2i(320,190);
		glVertex2i(320,290);
		glEnd();

		YsGLSLUseBitmapRenderer(bitmapRenderer);
		YsGLSLRenderRGBABitmap2D(bitmapRenderer,320,240,YSGLSL_HALIGN_RIGHT,YSGLSL_VALIGN_BOTTOM,bmp.GetWidth(),bmp.GetHeight(),bmp.GetRGBABitmapPointer());
		YsGLSLEndUseBitmapRenderer(bitmapRenderer);

		FsSwapBuffers();

		FsSleep(10);
	}

	YsGLSLDeleteBitmapRenderer(bitmapRenderer);

	return 0;
}
Example #5
0
void Show(int n,int x[],int toBeMoved1,int toBeMoved2)
{
    FsPollDevice();
    while(FSKEY_NULL==FsInkey())
       {
        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
        VisualizeArrayContents(n,x,toBeMoved1,toBeMoved2);
        FsSwapBuffers();
        FsPollDevice();
        FsSleep(10);
       }
}
int main(void)
{
	FsOpenWindow(16,16,800,600,1);

	OglPrim a,b;

	a.AddVertex(100,100);
	a.AddVertex(200,100);
	a.AddVertex(120,170);
	a.AddVertex(150,65);
	a.AddVertex(180,170);

	b=a;
	a.Move(5,5);

	while(FSKEY_ESC!=FsInkey())
	{
		FsPollDevice();

		glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

		glColor3ub(0,0,0);
		a.Draw(GL_LINE_LOOP);

		if(0!=FsGetKeyState(FSKEY_LEFT))
		{
			a.Move(-10,0);
		}
		if(0!=FsGetKeyState(FSKEY_RIGHT))
		{
			a.Move(10,0);
		}
		if(0!=FsGetKeyState(FSKEY_UP))
		{
			a.Move(0,-10);
		}
		if(0!=FsGetKeyState(FSKEY_DOWN))
		{
			a.Move(0,10);
		}

		glColor3ub(0,0,255);
		b.Draw(GL_LINE_LOOP);

		FsSwapBuffers();
		FsSleep(25);
	}

	return 0;
}
Example #7
0
File: main.cpp Project: HLH15/24783
/* virtual */ void FsLazyWindowApplication::Draw(void)
{
	int wid,hei;
	FsGetWindowSize(wid,hei);

	glViewport(0,0,wid,hei);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	Draw(btree.GetRoot(),0,wid,40,40);
	FsSwapBuffers();
	needRedraw=false;
}
void renderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluOrtho2D(0., WorldWidth, 0., (GLdouble)WorldHeight);

	////////////////////////// Drawing The Coordinate Plane Starts Here.
	// We Will Draw Horizontal And Vertical Lines With A Space Of 1 Meter Between Them.
/*	glColor3ub(0, 0, 255);										// Draw In Blue
	glBegin(GL_LINES);
	glLineWidth(0.5);
	// Draw The Vertical Lines
	for (float x = 0.; x <= WorldWidth; x += 1.0f)						// x += 1.0f Stands For 1 Meter Of Space In This Example
	{
		glVertex3f(x, WorldHeight, 0);
		glVertex3f(x, -WorldHeight, 0);
	}

	// Draw The Horizontal Lines
	for (float y = 0.; y <= WorldHeight; y += 1.0f)						// y += 1.0f Stands For 1 Meter Of Space In This Example
	{
		glVertex3f(0, y, 0);
		glVertex3f(WorldWidth, y, 0);
	}
	glEnd(); */
	/////////////////////////// Drawing The Coordinate Plane Ends Here.

	/////////////////////////draw the hallow 2d disc /////////////

	simBall1.DrawCircle(0, circleSections);
	realBall.DrawCircle(0, circleSections);

	///////////// draw the overlay HUD /////////////////////
	glColor3ub(127, 127, 127);
	char str[256];
	sprintf(str, "simBall1: pos(%f, %f), velocity(%f, %f)", simBall1.cx, simBall1.cy, simBall1.vx, simBall1.vy);
	glRasterPos2i(32, height-32);
	glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);
	sprintf(str, "real: pos(%f, %f), velocity(%f, %f)", realBall.cx, realBall.cy, realBall.vx, realBall.vy);
	glRasterPos2i(32, height - 64);
	glCallLists(strlen(str), GL_UNSIGNED_BYTE, str);

	FsSwapBuffers();
}
int main(void)
{
	FsOpenWindow(16,16,800,600,1);
    
	MouseChaser diamond;
	MovableByArrowKeys square;
    
	const int nMovable=2;
	Movable *movables[nMovable]={&diamond,&square};
    
	for(int i=0; i<nMovable; ++i)
	{
		movables[i]->SetPosition(400,300);
	}
    
	for(;;)
	{
		FsPollDevice();
        
		const int key=FsInkey();
		if(FSKEY_ESC==key)
		{
			break;
		}
        
		for(int i=0; i<nMovable; ++i)
		{
			movables[i]->Move();
		}
        
		glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
		for(int i=0; i<nMovable; ++i)
		{
			movables[i]->Draw();
		}
		FsSwapBuffers();
        
		FsSleep(25);
	}
    
	return 0;
}
Example #10
0
int main () {
    srand(time(NULL));
    FsOpenWindow(0,0,600, 800,1);
    glClearColor(0, 0, 0, 1);    
	glShadeModel(GL_SMOOTH);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    textureInit();
    
    WeaponUpgrade::LoadTexture("pic/red.png", "pic/green.png", "pic/blue.png");
    Plane *plane;
    plane = new WeaponUpgrade();
    bool running = true;

    while(running)
    {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        FsPollDevice();

        int key=FsInkey();
        int lb, mb, rb, mx, my;
        int mouse = FsGetMouseEvent(lb, mb, rb, mx, my);

        if(FSKEY_ESC==key)
        {
            running=false;
        }
        
        plane->Draw();
        plane->Move(1.0);
        if (((Prize *)plane)->Dead()) {
            delete plane;
            plane = new WeaponUpgrade();
        }
        
        FsSwapBuffers();
        FsSleep(25);
        
    }   
    return 0;
}
void GameOver(int score)
{
	int r=0;

	FsPollDevice();
	while(FsInkey()!=0)
	{
		FsPollDevice();
	}

	while(FsInkey()==0)
	{
		FsPollDevice();

		int wid,hei;
		FsGetWindowSize(wid,hei);

		glViewport(0,0,wid,hei);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1);

		glClearColor(0.0,0.0,0.0,0.0);
		glClear(GL_COLOR_BUFFER_BIT);

		const char *msg1="Game Over";
		char msg2[256];
		glColor3ub(255,255,255);
		glRasterPos2i(32,32);
		glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1);

		sprintf(msg2,"Your score is %d",score);

		glRasterPos2i(32,48);
		glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2);

		FsSwapBuffers();
		FsSleep(10);
	}
}
Example #12
0
File: main.cpp Project: HLH15/24783
/* virtual */ void FsLazyWindowApplication::Draw(void)
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glUseProgram(uniformColor.programIdent);
	const GLfloat vtx[12]=
	{
		-1,-1,0,
		 1,-1,0,
		 1, 1,0,
		-1, 1,0
	};
	const GLfloat col[4]={0,1,0,1};
	glUniform4fv(uniformColor.uniformColorPos,1,col);
	glEnableVertexAttribArray(uniformColor.attribVertexPos);
	glVertexAttribPointer(uniformColor.attribVertexPos,3,GL_FLOAT,GL_FALSE,0,vtx);
	glDrawArrays(GL_TRIANGLE_FAN,0,4);
	glDisableVertexAttribArray(uniformColor.attribVertexPos);

	FsSwapBuffers();

	needRedraw=false;
}
void GeblGuiEditorBase::DrawGuiOnly(void)
{
	int viewport[4];
	drawEnv.GetOpenGlCompatibleViewport(viewport);
	drawEnv.SetVerticalOrientation(YSTRUE);
	drawEnv.UpdateNearFar();

	SetNeedRedraw(YSFALSE);
	drawEnv.SetNeedRedraw(YSFALSE);
	threeDInterface.SetNeedRedraw(YSFALSE);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	glDisable(GL_DEPTH_TEST);

	// glMatrixMode(GL_PROJECTION);
	// glLoadIdentity();
	// glOrtho(0.0,(double)viewport[2],(double)viewport[3],0.0,-1.0,1.0);
	// glMatrixMode(GL_MODELVIEW);
	// glLoadIdentity();

	FsGuiCanvas::Show();
	FsSwapBuffers();
}
Example #14
0
int main(void)
{
    Vector2 bulletV(0, -10);
    Vector2 cannonV(0, -20);
    Vector2 laserV(0, -1);
    Vector2 bulletPosition(300, 400);
    Vector2 laserPosition(100, 400);
    Vector2 cannonPosition(200, 400);
    Vector2 velocity(1, 1);
    MissileList missiles;
    Missile *missile;
    MissileNode *laser = NULL;
    int laserReload = 0;
    int cannonReload = 0;
    int bulletReload = 0;
    int firing = 0;

    srand(time(NULL));
    FsOpenWindow(0,0,600, 800,1);
    glClearColor(0, 0, 0, 1);

    bool running = true;

    while(running)
    {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        FsPollDevice();

        int key=FsInkey();
        int lb, mb, rb, mx, my;
        int mouse = FsGetMouseEvent(lb, mb, rb, mx, my);

        if(FSKEY_ESC==key)
        {
            running=false;
        }
        if(FsGetKeyState(FSKEY_UP))
        {
            bulletV.rotate(0.05);
            cannonV.rotate(0.05);
            laserV.rotate(0.05);
        }
        if(FsGetKeyState(FSKEY_DOWN))
        {
            bulletV.rotate(-0.05);
            cannonV.rotate(-0.05);
            laserV.rotate(-0.05);
        }
        
        if(FSMOUSEEVENT_LBUTTONDOWN == mouse) {
            firing = 1;
        } else if (FSMOUSEEVENT_LBUTTONUP == mouse) {
            firing = 0;
        }
            
        if (firing == 1) {
            if (laserReload <= 0) {
                laserReload = 100;
                missile = new Laser(gBlue, 100, laserPosition, laserV, 1);
                laser = missiles.InsertFront(missile);
            }
            if (bulletReload <= 0) {
                bulletReload = 100;
                missile = new Bullet(gRed, 100, bulletPosition, bulletV, 1);
                missiles.InsertFront(missile);
            }
            if (cannonReload <= 0) {
                cannonReload = 100;
                missile = new Cannon(gGreen, 100, cannonPosition, cannonV, 1);
                missiles.InsertFront(missile);
            }
        }
        else if (firing == 0 && laser) {
            missiles.Delete(laser);
            laser = NULL;
            laserReload = 0;
        }

        MissileNode *node;
        node = missiles.getFront();
        while(node) {
            node->dat->Move(1.0);
            node->dat->Draw();
            if (!node->dat->CheckInWindow()) {
                node = missiles.Delete(node);
            } else {
                node = node->next;
            }
        }
        
        if (bulletReload > 0) bulletReload -= 10;
        if (cannonReload > 0) cannonReload -= 10;

/*
if(key == FSKEY_UP) printf("UP!!!!\n");
if(key == FSKEY_SPACE) printf("SPACE!!!\n");
if (FsCheckKeyHeldDown()) printf("KEY DOWN!!!\n");
*/
        FsSwapBuffers();


        FsSleep(25);
    }

    return 0;
}
int main(void)
{
	double cubeMatrix[16]=
	{
		1.0,0.0,0.0,0.0,
		0.0,1.0,0.0,0.0,
		0.0,0.0,1.0,0.0,
		0.0,0.0,0.0,1.0
	};

	FsOpenWindow(32,32,800,600,1); // 800x600 pixels, useDoubleBuffer=1

	glEnable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glDepthFunc(GL_LESS);

	FsPassedTime();  // Reset the timer

	while(FsInkey()==0)
	{
		int mx,my,lb,mb,rb,passed;
		double spinX,spinY;

		passed=FsPassedTime();

		FsPollDevice();
		FsGetMouseState(lb,mb,rb,mx,my);

		int wid,hei,cx,cy;
		FsGetWindowSize(wid,hei);
		cx=wid/2;
		cy=hei/2;

		spinX=(double)((mx-cx)/10)*(double)passed/1000.0;  // 1 pixel = degrees/sec
		spinY=(double)((my-cy)/10)*(double)passed/1000.0;  // 1 pixel = degrees/sec

		glClearColor(0.0,0.0,0.0,0.0);
		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

		glViewport(0,0,wid,hei);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(45.0,(double)wid/(double)hei,1.0,20.0);
		glTranslated(0.0,0.0,-10.0);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		glRotated(spinX,0.0,1.0,0.0);
		glRotated(spinY,1.0,0.0,0.0);
		glMultMatrixd(cubeMatrix);
		glGetDoublev(GL_MODELVIEW_MATRIX,cubeMatrix);

		glBegin(GL_QUADS);

		glColor3ub(0,0,255);
		glVertex3d(-2.5,-2.5,-2.5);
		glVertex3d(-2.5, 2.5,-2.5);
		glVertex3d( 2.5, 2.5,-2.5);
		glVertex3d( 2.5,-2.5,-2.5);

		glColor3ub(255,0,0);
		glVertex3d(-2.5,-2.5, 2.5);
		glVertex3d(-2.5, 2.5, 2.5);
		glVertex3d( 2.5, 2.5, 2.5);
		glVertex3d( 2.5,-2.5, 2.5);

		glColor3ub(255,0,255);
		glVertex3d(-2.5,-2.5,-2.5);
		glVertex3d(-2.5,-2.5, 2.5);
		glVertex3d(-2.5, 2.5, 2.5);
		glVertex3d(-2.5, 2.5,-2.5);

		glColor3ub(0,255,0);
		glVertex3d( 2.5,-2.5,-2.5);
		glVertex3d( 2.5,-2.5, 2.5);
		glVertex3d( 2.5, 2.5, 2.5);
		glVertex3d( 2.5, 2.5,-2.5);

		glColor3ub(0,255,255);
		glVertex3d(-2.5,-2.5,-2.5);
		glVertex3d(-2.5,-2.5, 2.5);
		glVertex3d( 2.5,-2.5, 2.5);
		glVertex3d( 2.5,-2.5,-2.5);

		glColor3ub(255,255,0);
		glVertex3d(-2.5, 2.5,-2.5);
		glVertex3d(-2.5, 2.5, 2.5);
		glVertex3d( 2.5, 2.5, 2.5);
		glVertex3d( 2.5, 2.5,-2.5);

		glEnd();

		FsSwapBuffers();

		FsSleep(20-passed);
	}

	return 0;
}
int main(void)
{
	Frame fra;
    
	int lb, mb, rb, rx, ry;//mouse variables
	int mode=0;
	int isWarp=1;  // in the warp or compete mode
	int winner=0;
	int mouseDown=0; 

	int winWid,winHei;
	
	Button Left[4];
	Button Right[4];
	Button Menu[6];

	YsRawPngDecoder image1;
	YsRawPngDecoder image2;
	makegif gif;

	TextString FaceLocation[4];
	TextString TemplateLocation[4];

	int pos1[4];
	int pos2[4];

	int image2Pos[2][4]; //the first index is the image, the second index is the position

	int faceChosen;
	int templateChosen;
	
	////////////////////////////////////////////////////////////////////
	// initialize the positions
	////////////////////////////////////////////////////////////////////

	image2Pos[0][0]=95;
	image2Pos[0][1]=12;
	image2Pos[0][2]=153;
	image2Pos[0][3]=85;

	image2Pos[1][0]=290;
	image2Pos[1][1]=25;
	image2Pos[1][2]=410;
	image2Pos[1][3]=155;
	
	

	////////////////////////////////////////////////////////////////////
	// initialize the face & template locations
	////////////////////////////////////////////////////////////////////

	FaceLocation[0].Set("face0.png");
	FaceLocation[1].Set("face1.png");
	FaceLocation[2].Set("face2.png");
	FaceLocation[3].Set("face3.png");

	TemplateLocation[0].Set("template0.png");
	TemplateLocation[1].Set("template1.png");
	TemplateLocation[2].Set("GIF1/01.png");
	TemplateLocation[3].Set("GIF2/01.png");


	///////////////////////////////////////////////////////////////////////
	// initialize the buttons
	///////////////////////////////////////////////////////////////////////

	for (int i=0; i<4; i++)
	{
		Left[i].wid=160;
		Left[i].hei=120;
		Right[i].wid=160;
		Right[i].hei=120;
	}

    Left[0].init(20, 50, "Picture 1");
    Left[1].init(20, 200, "Picture 2");
    Left[2].init(20, 350, "Picture 3");
    Left[3].init(20, 500, "Picture 4");

	Right[0].init(1120, 50, "Template 1");
    Right[1].init(1120, 200, "Template 2");
    Right[2].init(1120, 350, "Gif 1");
    Right[3].init(1120, 500, "Gif 2");
    
	for (int i=0; i<6; i++)
	{
		Menu[i].wid=80;
		Menu[i].hei=20;
	}
	
	Menu[0].init(20, 5, "Start");
    Menu[1].init(120, 5, "Compete");
    Menu[2].init(220, 5, "Rotate");
    Menu[3].init(320, 5, "Clear");
    Menu[4].init(420, 5, "Exit");
    Menu[5].init(520, 5, "Help");

	FsOpenWindow(64,16,1300,700,1);
	fra.display();

	FsGetWindowSize(winWid,winHei);

	while(1)
	{
		mouseDown=0;
		FsPollDevice();
		glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
		fra.DrawToolbox();
        fra.DrawColum();
        fra.DrawShowWindow();
        fra.DrawExit();

		for (int i=0; i<4; i++)
		{
			Left[i].draw();
			Right[i].draw();
		}

		for (int i=0; i<6; i++)
		{
			Menu[i].draw();
		}


		////////////////////////////////////////////////////////////////////////
		// get button states
		////////////////////////////////////////////////////////////////////////

		if(FsGetMouseEvent(lb,mb,rb,rx,ry)==FSMOUSEEVENT_LBUTTONDOWN)
		{
			mouseDown=1;
			for (int i=0; i<4; i++)
			{
				Left[i].checkPressed(rx, ry);
				Right[i].checkPressed(rx, ry);
			}
			for (int i=0; i<6; i++)
			{
				Menu[i].checkPressed(rx, ry);
			}
		}


		if (Menu[3].state==1)
		{
			mode=WAIT_LEFTBUT;
			Menu[3].state=0;
			isWarp=1;
			Menu[1].state=0;
			winner=0;
		}
		
		if (Menu[1].state==1)
		{
			isWarp=0;
		}

		if (Menu[4].state==1)
		{
			break;
		}

		///////////////////////////////////////////////////////////////
		// switch among different state of the game
		////////////////////////////////////////////////////////////////
		
		if (isWarp==1) //in the warp mode
		{
			switch(mode)
			{
			case WAIT_LEFTBUT:
				{
					for (int i=0; i<4; i++)
					{
						if (Left[i].state==1) // if pressed
						{
						
							if(YSOK==image1.Decode(FaceLocation[i].GetPointer())) 
							{
								printf(FaceLocation[i].GetPointer());
								mode=WAIT_POS1;
								Left[i].state=0;
								faceChosen=i;
								break;
							}
						}

					}
					break;
				}
			case WAIT_POS1:
				{
					if (mouseDown==1)
					{
						if (rx-300<=image1.wid && 550-ry<=image1.hei && rx-300>0 && 550-ry>0)
						{
							pos1[0]=rx-300;
							pos1[1]=image1.hei-(550-ry);
							mouseDown=0;
							mode=WAIT_POS2;
							printf("first pos %d %d\n",pos1[0],pos1[1]);
						}
					
					}
					break;
				}
			case WAIT_POS2:
				{
					if (mouseDown==1)
					{
						if (rx-300<=image1.wid && 550-ry<=image1.hei && rx-300>0 && 550-ry>0)
						{
							pos1[2]=rx-300;
							pos1[3]=image1.hei-(550-ry);
							mouseDown=0;
							mode=WAIT_TEMPLATE;
							printf("second pos %d %d\n",pos1[2],pos1[3]);
						}
					
					}
					break;
				}
			case WAIT_TEMPLATE:
				{
				
					for (int i=0; i<2; i++)
					{
						if (Right[i].state==1) // if pressed
						{
						
							if(YSOK==image2.Decode(TemplateLocation[i].GetPointer())) 
							{
								mode=WAIT_WARP;
								Right[i].state=0;
								templateChosen=i;

								pos2[0]=image2Pos[i][0];
								pos2[1]=image2Pos[i][1];
								pos2[2]=image2Pos[i][2];
								pos2[3]=image2Pos[i][3];
							
								break;


							}
						}

					}

					if (Right[2].state==1)
					{
						if(YSOK==image2.Decode(TemplateLocation[2].GetPointer())) 
							{
								mode=WAIT_WARP;
								Right[2].state=0;
								templateChosen=2;
								//printf("GIF1\n");


								//char *image1String=FaceLocation[faceChosen].GetPointer();
								char gifString[]={"GIF1/01.png"};
								//char gifString[]={"GIF2/01.png"};

								gif.initial(gifString,image2,12,15,0,45,40); //initial the gif class 
								//gif.initial(gifString,image2,4,160,50,260,165); //initial the gif class 
								gif.setImage1(image1,FaceLocation[faceChosen].GetPointer()); // select the head picture

								gif.setImage1HeadLT(pos1[0],pos1[1]); // select the left top point of the head picture

								gif.setImage2HeadRB(pos1[2],pos1[3]); // select the right bottom point of the head picture
								gif.copyRGBA(image1,image2);

								break;

							}
						break;

					}

					if (Right[3].state==1)
					{
						if(YSOK==image2.Decode(TemplateLocation[3].GetPointer())) 
							{
								mode=WAIT_WARP;
								Right[3].state=0;
								templateChosen=3;
								//printf("GIF1\n");


								//char *image1String=FaceLocation[faceChosen].GetPointer();
								//char gifString[]={"GIF1/01.png"};
								char gifString[]={"GIF2/01.png"};

								printf(FaceLocation[faceChosen].GetPointer());

								//gif.initial(gifString,image2,12,15,0,45,40); //initial the gif class 
								gif.initial(gifString,image2,4,160,50,260,165); //initial the gif class 
								gif.setImage1(image1,FaceLocation[faceChosen].GetPointer()); // select the head picture

								gif.setImage1HeadLT(pos1[0],pos1[1]); // select the left top point of the head picture

								gif.setImage2HeadRB(pos1[2],pos1[3]); // select the right bottom point of the head picture
								gif.copyRGBA(image1,image2);

								break;

							}
						break;

					}
					
						
				
					break;
				}
			case WAIT_WARP:
				{
					if (Menu[0].state==1)
					{
						warpImage(image1, image2, pos1, pos2, 0.0);
						mode=FINISHED;
						Menu[0].state=0;
					}
					if (Menu[2].state==1)
					{
						warpImage(image1, image2, pos1, pos2,-20.0);
						mode=FINISHED;
						Menu[2].state=0;
					}
					break;
				
				}
			case FINISHED:
				{
					if (Menu[3].state==1)
					{
						mode=WAIT_LEFTBUT;
						Menu[3].state=0;
					}
					break;
				}
			}
		}
		else
		{
			switch(mode)
			{
			case WAIT_LEFTBUT:
				{
					for (int i=0; i<4; i++)
					{
						if (Left[i].state==1) // if pressed
						{
						
							if(YSOK==image1.Decode(FaceLocation[i].GetPointer())) 
							{
								printf(FaceLocation[i].GetPointer());
								mode=WAIT_TEMPLATE;
								Left[i].state=0;
								//faceChosen=i;
								break;
							}
						}

					}
					break;
				}
			case WAIT_TEMPLATE:
				{
				
					for (int i=0; i<4; i++)
					{
						if (Left[i].state==1) // if pressed
						{
						
							if(YSOK==image2.Decode(FaceLocation[i].GetPointer())) 
							{
								printf(FaceLocation[i].GetPointer());
								mode=WAIT_WARP;
								Left[i].state=0;
								//faceChosen=i;
								break;
							}
						}

					}
					
					break;
				}
			case WAIT_WARP:
				{
					
					if (Menu[0].state==1)
					{
						
						winner=BeautyCompetition(image1,image2);
						glRasterPos2d(300.0,(double)(winHei-50));
						if (winner==1)
						{
							YsGlDrawFontBitmap20x32("PICTURE 1 WINS!");
						}
						else if (winner==2)
						{
							YsGlDrawFontBitmap20x32("PICTURE 2 WINS!");
						}
						printf("\nWINNER:%d!!!\n",winner);
						mode=FINISHED;
						Menu[0].state=0;
					}
					break;
				
				}
			case FINISHED:
				{
					if (Menu[3].state==1)
					{
						mode=WAIT_LEFTBUT;
						Menu[3].state=0;
						winner=0;
					}
					break;
				}
			}
		}

		///////////////////////////////////////////////////////////////
		// actually draw
		//////////////////////////////////////////////////////////////

		if (mode==WAIT_LEFTBUT)
		{
			//do nothing 
		}
		else if (mode>WAIT_LEFTBUT && mode<=WAIT_TEMPLATE)
		{
			image1.Flip();
			FsGetWindowSize(winWid,winHei);
			glRasterPos2d(300.0,(double)(winHei-150));
			glDrawPixels(image1.wid,image1.hei,GL_RGBA,GL_UNSIGNED_BYTE,image1.rgba);
			image1.Flip();
		}
		else if (mode>WAIT_TEMPLATE && mode<=FINISHED)
		{
			if (templateChosen<2)
			{
				image2.Flip();
				FsGetWindowSize(winWid,winHei);
				glRasterPos2d(300.0,(double)(winHei-150));
				glDrawPixels(image2.wid,image2.hei,GL_RGBA,GL_UNSIGNED_BYTE,image2.rgba);
				image2.Flip();
			}
			else if(templateChosen==2 || templateChosen==3)
			{
				if (mode==FINISHED)
				{
				gif.draw();
				}
				else 
				{
					image2.Flip();
					FsGetWindowSize(winWid,winHei);
					glRasterPos2d(300.0,(double)(winHei-150));
					glDrawPixels(image2.wid,image2.hei,GL_RGBA,GL_UNSIGNED_BYTE,image2.rgba);
					image2.Flip();
				}
			}

			if (winner==1)
			{
				glRasterPos2d(300.0,(double)(winHei-50));
				YsGlDrawFontBitmap20x32("PICTURE 1 WINS!");
			}
			else if (winner==2)
			{
				glRasterPos2d(300.0,(double)(winHei-50));
				YsGlDrawFontBitmap20x32("PICTURE 2 WINS!");
			}
						
		}

		


		FsSwapBuffers();
		FsSleep(25);
	}

	return 0;
	
}
Example #17
0
void Map::RunMap()
{
	key = 0;
	int offset=0;
	char *story[] = { 
		"Welcome to CMU Adventure!",
		"Whether you have made up your mind to come to CMU or", 
		"you are still mulling over it, you are welcome to use", 
		"this game to have a glimpse of life at CMU.", 
		" ",
		"To familiarize yourself with the CMU environment,", 
		"navigate through the satellite view map of CMU campus ", // changes by Chun Fan
		"to explore all the buildings.", // changes by Chun Fan
		" ",
		"Studying constitutes a large part of CMU student life.",
		"CMU tries to make learning fun.See how MechE students", 
		"learn CAD & gear theory by playing the CAD & Gear games",
		"at Hammerschlag Hall and Hunts library.",
		" ",
		"Sometimes massive number of assignments could means ",
		"many sleepless nights. Play the StayAwake game to see", // changes by Chun Fan
		"how CMU lecturers and students fight off sleeping bugs",
		"during lectures in Margaret-Morrison Hall.",
		" ",
		"Student life is not just about studying, recreation is", 
		"essential too. Have some fun by playing the Pool game",
		"at University Center.",
		" ",
		"At CMU, safety is utmost important.CMU provides shuttle",
		"buses to ferry students and staffs back home safely.",
		"Play the Shuttle game at Porter Hall to have a feel on",
		"how it is like to catch a shuttle bus at CMU.",
		" ",
		"Press Enter to start game!"
		};

	Building building[5];	
	building[0].set("Uiversity Center", 1374, 1239,  110, 136);
	building[1].set("Hunts Hall", 1042, 662, 70, 35);
	building[2].set("Hammerschlag Hall", 454,  984,  111, 90);
	building[3].set("Porter Hall", 626,  805,  115, 75);
	building[4].set("Margaret-Morisson", 1489, 938,  50,  90);
		
    
	if(YSOK==png.Decode("instructions_background.png"))
    {
		// changes by Chun Fan
        //printf("Read Width=%d Height=%d\n",png.wid,png.hei);
        png.Flip();
    }
    else
    {
        printf("Read Error!\n");
        return ;
    }

	// Story Cover Page
	
	glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

	int winWid,winHei;
	FsGetWindowSize(winWid, winHei);
	glRasterPos2d(0.0, (double)(winHei-1));
	glDrawPixels(png.wid, png.hei, GL_RGBA, GL_UNSIGNED_BYTE, png.rgba);

	if(YSOK==png.Decode("map-with light.png"))
    {
		// changes by Chun Fan
        //printf("Read Width=%d Height=%d\n",png.wid,png.hei);
        png.Flip();
    }
    else
    {
        printf("Read Error!\n");
        return ;
    }

	glColor3ub(0,0,255);
	int n_line=1;
	glRasterPos2d(75,75);
	YsGlDrawFontBitmap20x32(story[0]);

	glColor3ub(0,0,0);
	for (int i=1; i<28; i++)
	{
		n_line++;			
		glRasterPos2d(75,75+16*n_line);
		YsGlDrawFontBitmap12x16(story[i]);
	}
	n_line++;
	glColor3ub(255,0,0);
	glRasterPos2d(75,75+16*n_line);
	YsGlDrawFontBitmap12x16(story[28]);

	FsSwapBuffers();
	
	
	while (key!=FSKEY_ENTER)
	{
		FsPollDevice();
		key = FsInkey();
		
		FsSleep(20);
	}

	
    
    key=FSKEY_NULL;
    int Mnumber=0;
    
    while(FSKEY_ESC!=key)
    {
        FsPollDevice();
        key=FsInkey();
        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
        
        if (key==FSKEY_M)
        {
            Mnumber++;
        }
        if (Mnumber%2==0)
        {
            DramMap();//Include check player's position(whether player can step on that part or not) and move
                      //the map.
            
            CheckPlayersState();
            
            player.DrawPlayerInMap();
            
            player.DrawMovingPlayerInCorner(player.PlayersState);
        }
        if (Mnumber%2==1)
        {
            ShowShrinkMap();
        }
		
		// check position
		int x=GetPlayersPositionX();
		int y=GetPlayersPositionY();
		//printf("x = %d,\t y = %d\n", x, y);

		srand((unsigned int)time(NULL) + rand());

		for (int i=0; i<5; i++)
		{
			int x_min = building[i].getX() - building[i].getW() ;
			int x_max = building[i].getX() + building[i].getW() ;
			int y_min = building[i].getY() - building[i].getH() ;
			int y_max = building[i].getY() + building[i].getH() ;
			if (x>x_min && x<x_max && y>y_min && y<y_max)
			{
				//char name[256];
				YsRawPngDecoder png4;
				int state0=0,state1=0,state2=0,state3=0,state4=0;

				FsPollDevice();
				
				int MouseEvent;

				int lb,mb,rb,mx,my;

				//building[i].getName(name);
				//printf("I am in %s!\n", name);
				switch (i)
				{
					case 0: // pool
                        if(YSOK==png4.Decode("ClickButton.png"))
                        {
                           png4.Flip();
                           int winWid,winHei;
                           FsGetWindowSize(winWid,winHei);
						   glRasterPos2d(400,300);
						   glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba);
						   // changes by Chun Fan
						   //printf("%d  %d",png4.wid,png4.hei);					 
						}

						MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my);
						switch(MouseEvent)
						{
						case FSMOUSEEVENT_LBUTTONDOWN:
								if(mx>=400 && mx<=600 && my>=200 && my<=300)
								{
									state0=1;
								}
						}

						if(state0==1)
						{
							score.setResult(0, poolgame.rungame());
							// changes by Chun Fan
							//printf("Game 1: %d trials, %s\n", score.getCount(0), score.getResult(0)?"Passed":"Failed");
							FsClearEventQueue();
						}
						state0=0;
						//FsClearEventQueue();

						break;

					case 1: // CAD
						if(YSOK==png4.Decode("ClickButton.png"))
                        {
                           png4.Flip();
                           int winWid,winHei;
                           FsGetWindowSize(winWid,winHei);
						   glRasterPos2d(400,300);
						   glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba);
						   // changes by Chun Fan
						   //printf("%d  %d",png4.wid,png4.hei);					 
						}

						MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my);
						switch(MouseEvent)
						{
						case FSMOUSEEVENT_LBUTTONDOWN:

								if(mx>=400 && mx<=600 && my>=200 && my<=300)
								{
									state1=1;
								}
						}

						if(state1==1)
						{
							
							score.setResult(1, cadclass.CADMain());
							// changes by Chun Fan
							//printf("Game 2: %d trials, %s\n", score.getCount(1), score.getResult(1)?"Passed":"Failed");
							FsClearEventQueue();
						}
						state1=0;		
						//FsClearEventQueue();

						break;

					case 2: // gear game
						if(YSOK==png4.Decode("ClickButton.png"))
                        {
                           png4.Flip();
                           int winWid,winHei;
                           FsGetWindowSize(winWid,winHei);
						   glRasterPos2d(400,300);
						   glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba);
						   // changes by Chun Fan
						   //printf("%d  %d",png4.wid,png4.hei);					 
						}

						MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my);
						switch(MouseEvent)
						{
						case FSMOUSEEVENT_LBUTTONDOWN:
								if(mx>=400 && mx<=600 && my>=200 && my<=300)
								{
									state2=1;
								}
						}

						if(state2==1)
						{
						   score.setResult(2, geargame.run());
						   // changes by Chun Fan
						   //printf("Game 3: %d trials, %s\n", score.getCount(2), score.getResult(2)?"Passed":"Failed");
						   
							// changes by Chun Fan
						    glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
							FsClearEventQueue();
						}
						state2=0;
						//FsClearEventQueue();

						break;

					case 3:
						if( score.getGraduate())
						{
							if(YSOK==png4.Decode("ClickButton.png"))
							{
							   png4.Flip();
							   int winWid,winHei;
							   FsGetWindowSize(winWid,winHei);
							   glRasterPos2d(400,300);
							   glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba);
							   // changes by Chun Fan
							   //printf("%d  %d",png4.wid,png4.hei);					 
							}

							MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my);
							switch(MouseEvent)
							{
							case FSMOUSEEVENT_LBUTTONDOWN:
									if(mx>=400 && mx<=600 && my>=200 && my<=300)
									{
										state3=1;
									}
							}
						}

						if(state3==1 )
						{
						   shuttle.action();

							glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

							score.DrawScoreCard();

							FsSwapBuffers();
							
							FsPollDevice();
							int key1 = FsInkey();
							
							while(key1!=FSKEY_ENTER)
							{
								
								FsPollDevice();
								key1 = FsInkey();
								FsSleep(20);
							}
							
							glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

							awardStage.SetDept("Mechanical Engineering");

							awardStage.DrawStage();
							awardStage.PrintCert();

							FsSwapBuffers();						
							
							FsPollDevice();
							key1 = FsInkey();
							
							while(key1!=FSKEY_ENTER)
							{
								FsPollDevice();
								key1 = FsInkey();
								
								FsSleep(20);
							}
							key=FSKEY_ESC;

						}
						state3=0;
				
						//if (checkscore()==1)		
						FsClearEventQueue();

						break;

					case 4: // stayawake
						if(YSOK==png4.Decode("ClickButton.png"))
                        {
                           png4.Flip();
                           int winWid,winHei;
                           FsGetWindowSize(winWid,winHei);
						   glRasterPos2d(400,300);
						   glDrawPixels(png4.wid,png4.hei,GL_RGBA,GL_UNSIGNED_BYTE,png4.rgba);
						   // changes by Chun Fan
						   //printf("%d  %d",png4.wid,png4.hei);					 
						}

						MouseEvent=FsGetMouseEvent(lb,mb,rb,mx,my);
						switch(MouseEvent)
						{
						case FSMOUSEEVENT_LBUTTONDOWN:
								if(mx>=400 && mx<=600 && my>=200 && my<=300)
								{
									state4=1;
								}
						}

						if(state4==1)
						{
						   stayawake.StartGame();
						   score.setResult(3, stayawake.GetScore());
						   // changes by Chun Fan
						   //printf("Game 4: %d trials, %s\n", score.getCount(3), score.getResult(3)?"Passed":"Failed");
							FsClearEventQueue();
						}
						state4=0;
						//FsClearEventQueue();

						break;
					
				}
			}
		}
		
        FsSwapBuffers();
        FsSleep(50);
    }
}
Example #18
0
void Button::Remap2()
{
    FsClearEventQueue();
    FsGetWindowSize (windowWid, windowHei);
    while(FSKEY_NULL!=FsInkey() || 0!=FsInkeyChar())
    {
        FsPollDevice();
    }

	//Initialize();
    
    while(SF2==0 || checkGameControl(SF2) )
    {   
        FsPollDevice();
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        DrawBackground();
		DrawModeTitle2();
		DrawKeyboardSetting();

		double y=180.0;
		double dy=40.0;
		glColor3ub(255, 255, 255);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Up : (press key to remap)");

		DrawLogo(25, 575);

        SF2=FsInkey();
        FsSwapBuffers();
        FsSleep(20);
    }
    
    while(SB2==0  || checkGameControl(SB2))
    {        
        FsPollDevice();
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        DrawBackground();
		DrawModeTitle2();
		DrawKeyboardSetting();

		double y=180.0;
		double dy=40.0;
		glColor3ub(155, 155, 155);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Up : (OK)");
		y+=dy;
		glColor3ub(255, 255, 255);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Down : (press key to remap)");

		DrawLogo(25, 575);

        SB2=FsInkey();
        FsSwapBuffers();
        FsSleep(20);
    }
    
    while(SL2==0 || checkGameControl(SL2))
    {        
        FsPollDevice();
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        DrawBackground();
		DrawModeTitle2();
		DrawKeyboardSetting();

		double y=180.0;
		double dy=40.0;
		glColor3ub(155, 155, 155);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Up : (OK)");
		y+=dy;
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Down : (OK)");
		y+=dy;
		glColor3ub(255, 255, 255);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Left : (press key to remap)");

		DrawLogo(25, 575);

        SL2=FsInkey();
        FsSwapBuffers();
        FsSleep(20);
    }
    
    while(SR2==0 || checkGameControl(SR2))
    {        
        FsPollDevice();
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

        DrawBackground();
		DrawModeTitle2();
		DrawKeyboardSetting();

		double y=180.0;
		double dy=40.0;
		glColor3ub(155, 155, 155);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Up : (OK)");
		y+=dy;
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Down : (OK)");
		y+=dy;
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Left : (OK)");
		y+=dy;
		glColor3ub(255, 255, 255);
		glRasterPos2d(100,y);
		YsGlDrawFontBitmap16x20 ("Right : (press key to remap)");

		DrawLogo(25, 575);

        SR2=FsInkey();
        FsSwapBuffers();
        FsSleep(20);
    }    
    
}
int main(void)
{
	GLfloat vtx[3*3*2*8*16],texCoord[3*3*2*8*16],nom[3*3*2*8*16],col[3*4*2*8*16];
	int nVtx=MakeSphere(vtx,texCoord,nom,col,16,8);

	YsBitmap bmp[6];
	bmp[0].LoadPng("explosion01.png");
	bmp[1].LoadPng("explosion02.png");
	bmp[2].LoadPng("explosion03.png");
	bmp[3].LoadPng("explosion04.png");
	bmp[4].LoadPng("explosion05.png");
	bmp[5].LoadPng("flash01.png");

	FsOpenWindow(16,16,800,600,1);

	YsGLSL3DRenderer *variColorPerVtxShadingRenderer=YsGLSLCreateVariColorPerVtxShading3DRenderer();
	YsGLSL3DRenderer *monoColorPerVtxShadingRenderer=YsGLSLCreateMonoColorPerVtxShading3DRenderer();
	YsGLSL3DRenderer *monoColorPerPixShadingRenderer=YsGLSLCreateMonoColorPerPixShading3DRenderer();
	YsGLSL3DRenderer *variColorPerPixShadingRenderer=YsGLSLCreateVariColorPerPixShading3DRenderer();
	YsGLSL3DRenderer *monoColorPerVtxShadingWithTexRenderer=YsGLSLCreateMonoColorPerVtxShadingWithTexCoord3DRenderer();
	YsGLSL3DRenderer *variColorPerVtxShadingWithTexRenderer=YsGLSLCreateVariColorPerVtxShadingWithTexCoord3DRenderer();
	YsGLSL3DRenderer *monoColorPerPixShadingWithTexRenderer=YsGLSLCreateMonoColorPerPixShadingWithTexCoord3DRenderer();
	YsGLSL3DRenderer *variColorPerPixShadingWithTexRenderer=YsGLSLCreateVariColorPerPixShadingWithTexCoord3DRenderer();
	YsGLSL3DRenderer *renderer3d=monoColorPerVtxShadingRenderer;

	printf("SPACE   Switch between Per Vertex and Per Pixel renderers.\n");


	GLuint texId;
	glGenTextures(1,&texId);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,texId);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp[0].GetWidth(),bmp[0].GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,bmp[0].GetRGBABitmapPointer());

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);


	double rot=0.0;
	int bmpId=0;

	for(int key=FSKEY_NULL; FSKEY_ESC!=key; FsSleep(10))
	{
		FsPollDevice();
		key=FsInkey();

		switch(key)
		{
		case FSKEY_ENTER:
			bmpId=(bmpId+1)%6;
			glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,bmp[bmpId].GetWidth(),bmp[bmpId].GetHeight(),0,GL_RGBA,GL_UNSIGNED_BYTE,bmp[bmpId].GetRGBABitmapPointer());
			break;
		case FSKEY_SPACE:
			if(renderer3d==monoColorPerVtxShadingRenderer)
			{
				renderer3d=monoColorPerPixShadingRenderer;
			}
			else if(renderer3d==monoColorPerPixShadingRenderer)
			{
				renderer3d=variColorPerVtxShadingRenderer;
			}
			else if(renderer3d==variColorPerVtxShadingRenderer)
			{
				renderer3d=variColorPerPixShadingRenderer;
			}
			else if(renderer3d==variColorPerPixShadingRenderer)
			{
				renderer3d=monoColorPerVtxShadingWithTexRenderer;
			}
			else if(renderer3d==monoColorPerVtxShadingWithTexRenderer)
			{
				renderer3d=variColorPerVtxShadingWithTexRenderer;
			}
			else if(renderer3d==variColorPerVtxShadingWithTexRenderer)
			{
				renderer3d=monoColorPerPixShadingWithTexRenderer;
			}
			else if(renderer3d==monoColorPerPixShadingWithTexRenderer)
			{
				renderer3d=variColorPerPixShadingWithTexRenderer;
			}
			else
			{
				renderer3d=monoColorPerVtxShadingRenderer;
			}
			break;
		}


		glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

		glEnable(GL_DEPTH_TEST);

		int wid,hei;
		FsGetWindowSize(wid,hei);

		const double aspect=(double)wid/(double)hei;

		GLfloat modelview[16],projection[16],tfm[16];
		YsGLMakePerspectivefv(projection,YSGLPI/6.0,aspect,1.0,50.0);

		YsGLMakeIdentityfv(modelview);
		YsGLMakeTranslationfv(tfm,0.0,0.0,-15.0);
		YsGLMultMatrixfv(modelview,modelview,tfm);
		YsGLMakeXZRotationfv(tfm,rot);
		YsGLMultMatrixfv(modelview,modelview,tfm);
		YsGLMakeScalingfv(tfm,3.0,3.0,3.0);
		YsGLMultMatrixfv(modelview,modelview,tfm);


		YsGLSLUse3DRenderer(monoColorPerVtxShadingRenderer);
		YsGLSLSet3DRendererProjectionfv(monoColorPerVtxShadingRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(monoColorPerVtxShadingRenderer,modelview);
		YsGLSLEndUse3DRenderer(monoColorPerVtxShadingRenderer);

		YsGLSLUse3DRenderer(variColorPerVtxShadingRenderer);
		YsGLSLSet3DRendererProjectionfv(variColorPerVtxShadingRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(variColorPerVtxShadingRenderer,modelview);
		YsGLSLEndUse3DRenderer(variColorPerVtxShadingRenderer);

		YsGLSLUse3DRenderer(monoColorPerPixShadingRenderer);
		YsGLSLSet3DRendererProjectionfv(monoColorPerPixShadingRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(monoColorPerPixShadingRenderer,modelview);
		YsGLSLEndUse3DRenderer(monoColorPerPixShadingRenderer);

		YsGLSLUse3DRenderer(variColorPerPixShadingRenderer);
		YsGLSLSet3DRendererProjectionfv(variColorPerPixShadingRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(variColorPerPixShadingRenderer,modelview);
		YsGLSLEndUse3DRenderer(variColorPerPixShadingRenderer);

		YsGLSLUse3DRenderer(monoColorPerVtxShadingWithTexRenderer);
		YsGLSLSet3DRendererProjectionfv(monoColorPerVtxShadingWithTexRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(monoColorPerVtxShadingWithTexRenderer,modelview);
		YsGLSLEndUse3DRenderer(monoColorPerVtxShadingWithTexRenderer);

		YsGLSLUse3DRenderer(variColorPerVtxShadingWithTexRenderer);
		YsGLSLSet3DRendererProjectionfv(variColorPerVtxShadingWithTexRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(variColorPerVtxShadingWithTexRenderer,modelview);
		YsGLSLEndUse3DRenderer(variColorPerVtxShadingWithTexRenderer);

		YsGLSLUse3DRenderer(monoColorPerPixShadingWithTexRenderer);
		YsGLSLSet3DRendererProjectionfv(monoColorPerPixShadingWithTexRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(monoColorPerPixShadingWithTexRenderer,modelview);
		YsGLSLEndUse3DRenderer(monoColorPerPixShadingWithTexRenderer);

		YsGLSLUse3DRenderer(variColorPerPixShadingWithTexRenderer);
		YsGLSLSet3DRendererProjectionfv(variColorPerPixShadingWithTexRenderer,projection);
		YsGLSLSet3DRendererModelViewfv(variColorPerPixShadingWithTexRenderer,modelview);
		YsGLSLEndUse3DRenderer(variColorPerPixShadingWithTexRenderer);


		glEnable(GL_CULL_FACE);
		glFrontFace(GL_CW);
	
		YsGLSLUse3DRenderer(renderer3d);

		YsGLSLSet3DRendererTextureType(renderer3d,YSGLSL_TEX_TYPE_BILLBOARD);

		const GLfloat billBoardCenter[3]={0,0,0};
		const GLfloat billBoardDimension[2]={3.0f,3.0f};
		YsGLSLSet3DRendererBillBoardfv(renderer3d,billBoardCenter,billBoardDimension);

		GLfloat color[4]={0,0,1,1};
		YsGLSLSet3DRendererUniformColorfv(renderer3d,color);

		if(renderer3d!=monoColorPerPixShadingWithTexRenderer &&
		   renderer3d!=variColorPerPixShadingWithTexRenderer &&
		   renderer3d!=monoColorPerVtxShadingWithTexRenderer &&
		   renderer3d!=variColorPerVtxShadingWithTexRenderer)
		{
			YsGLSLDrawPrimitiveVtxNomColfv(renderer3d,GL_TRIANGLES,nVtx,vtx,nom,col);
		}
		else if(renderer3d==monoColorPerPixShadingWithTexRenderer || renderer3d==monoColorPerVtxShadingWithTexRenderer)
		{
			YsGLSLDrawPrimitiveVtxTexCoordNomfv(renderer3d,GL_TRIANGLES,nVtx,vtx,texCoord,nom);
		}
		else if(renderer3d==variColorPerPixShadingWithTexRenderer || renderer3d==variColorPerVtxShadingWithTexRenderer)
		{
			YsGLSLDrawPrimitiveVtxTexCoordNomColfv(renderer3d,GL_TRIANGLES,nVtx,vtx,texCoord,nom,col);
		}

		YsGLSLEndUse3DRenderer(renderer3d);



		FsSwapBuffers();

		rot+=YSGLPI/30.0;
	}

	YsGLSLDelete3DRenderer(monoColorPerVtxShadingRenderer);
	YsGLSLDelete3DRenderer(variColorPerVtxShadingRenderer);
	YsGLSLDelete3DRenderer(monoColorPerPixShadingRenderer);

	return 0;
}
int Menu(void)
{
	int r=0,key;
	const double angleInc = PI/180.;
	while(r!=eStart && r!= eStop)
	{
		FsPollDevice();
		key=FsInkey();
		switch(key)
		{
		case FSKEY_S:
			r=eStart;
			break;
		case FSKEY_ESC:
			r=eStop;
			break;
		case FSKEY_UP:
			iSpeed++;
			break;
		case FSKEY_DOWN:
			iSpeed = max(2., iSpeed-1);
			break;
		case FSKEY_LEFT:
			iAngle = max(0., iAngle-angleInc);
			break;
		case FSKEY_RIGHT:
			iAngle = min(90.0, iAngle+angleInc);
			break;
		}

		initPhysics(radius, iSpeed, iAngle);
		if (r == eStop)
			return r;
		int wid,hei;
		FsGetWindowSize(wid,hei);


		glViewport(0,0,wid,hei);
		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		glOrtho(-0.5,(GLdouble)wid-0.5,(GLdouble)hei-0.5,-0.5,-1,1);

		glClearColor(0.0,0.0,0.0,0.0);
		glClear(GL_COLOR_BUFFER_BIT);
		glColor3ub(127,127,127);

		char sSpeed[128];
		sprintf(sSpeed, "Initial ball speed is %f m/s. Use Up/Down keys to change it!\n", iSpeed);
		char sAngle[128];
		sprintf(sAngle, "Initial horizon Angle is %f degrees. Use Left/Right keys to change it!\n", iAngle*180./PI);
		glColor3ub(255,255,255);
		glRasterPos2i(32,32);
		glCallLists(strlen(sSpeed),GL_UNSIGNED_BYTE,sSpeed);
		glRasterPos2i(32,64);
		glCallLists(strlen(sAngle),GL_UNSIGNED_BYTE,sAngle);
		const char *msg1="S.....Start Game";
		const char *msg2="ESC...Exit";
		glRasterPos2i(32,96);
		glCallLists(strlen(msg1),GL_UNSIGNED_BYTE,msg1);
		glRasterPos2i(32,128);
		glCallLists(strlen(msg2),GL_UNSIGNED_BYTE,msg2);

		FsSwapBuffers();
		FsSleep(10);
	}
	return r;
}
Example #21
0
File: main.cpp Project: HLH15/24783
/* virtual */ void FsLazyWindowApplication::Draw(void)
{
	int wid,hei;
	FsGetWindowSize(wid,hei);

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	drawEnv.SetProjectionMode(YsProjectionTransformation::PERSPECTIVE);
	drawEnv.SetAspectRatio((double)wid/(double)hei);
	drawEnv.SetFOVY(YsPi/4.0);
	drawEnv.SetNearFar(0.1,100.0);
	drawEnv.SetViewTarget((min+max)/2.0);
	drawEnv.SetViewDistance((max-min).GetLength());

	GLfloat projMat[16];
	drawEnv.GetProjectionMatrix().GetOpenGlCompatibleMatrix(projMat);


	auto &view=drawEnv.GetViewMatrix();

	YsMatrix4x4 modeling;

	YsMatrix4x4 fullMatrix=view*modeling;

	GLfloat viewMat[16];
	fullMatrix.GetOpenGlCompatibleMatrix(viewMat);

	{
		YsGLSLPlain3DRenderer renderer;  // Again, do not nest the renderer!
		renderer.SetProjection(projMat);
		renderer.SetModelView(viewMat);

		GLfloat color[8]={0,0,1,1, 1,0,0,1};
		const GLfloat vtx[6]=
		{
			lastClick[0].xf(),lastClick[0].yf(),lastClick[0].zf(),
			lastClick[1].xf(),lastClick[1].yf(),lastClick[1].zf()
		};
		renderer.DrawVtxCol(GL_LINES,2,vtx,color);

		glEnable(GL_PROGRAM_POINT_SIZE);
		renderer.SetUniformPointSize(3.0);
		renderer.DrawVtx(GL_POINTS,cellVtx.size()/3,cellVtx.data());
	}
	{
		GLfloat lightDir[]={0,0,1};

		YsGLSLShaded3DRenderer renderer;  // Again, do not nest the renderer!
		renderer.SetProjection(projMat);
		renderer.SetModelView(viewMat);
		renderer.SetLightDirectionInCameraCoordinate(0,lightDir);

		renderer.DrawVtxNomCol(GL_TRIANGLES,vtx.size()/3,vtx.data(),nom.data(),col.data());
	}
	
	YsMatrix4x4 shadowMat;
	shadowMat.Translate(0.0,-12.0,0.0);
	shadowMat.Scale(1.0,0.0,1.0);

	fullMatrix=view*shadowMat*modeling;
	fullMatrix.GetOpenGlCompatibleMatrix(viewMat);
	{
		GLfloat color[]={0,0,0,1};

		YsGLSLPlain3DRenderer renderer;  // Again, do not nest the renderer!
		renderer.SetProjection(projMat);
		renderer.SetModelView(viewMat);
		renderer.SetUniformColor(color);
		renderer.DrawVtx(GL_TRIANGLES,vtx.size()/3,vtx.data());
	}


	FsSwapBuffers();

	needRedraw=false;
}
void FsSimpleWindowIntervalCallBack(void)
{
	int winWid,winHei;
	FsGetWindowSize(winWid,winHei);

	int lb,mb,rb,mx,my;
	FsGetMouseEvent(lb,mb,rb,mx,my);

	float r=1.0,g=0.0,b=0.0,a=1.0;


    glClearColor(0.1f, 0.1f, 0.1f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	

	GLfloat spriteVtx[]=
	{
		1,1,1,
		-1,1,1,
		1,-1,1,
		-1,-1,1,
		1,1,-1,
		-1,1,-1,
		1,-1,-1,
		-1,-1,-1,
	};
	GLfloat spriteColor[]=
	{
		0,0,1, 1,
		0,1,0, 1,
		1,0,0, 1,
		1,0,1, 1,
		1,1,0, 1,
		1,1,1, 1,
		0,0,1, 1,
		0,1,0, 1,
	};

	GLfloat monoColorVtx[]=
	{
		 1, 0, 0,
		-1, 0, 0,
		 0, 1, 0,
		 0,-1, 0,
		 0, 0, 1,
		 0, 0,-1,
	};


	const int nVtx=(sizeof(spriteVtx)/(3*sizeof(GLfloat)));



	glDisable(GL_DEPTH_TEST);

	glEnable(GL_PROGRAM_POINT_SIZE);  // Needed for enabling gl_PointSize in the vertex shader.
	glEnable(GL_POINT_SPRITE);        // Needed for enabling gl_PointCoord in the fragment shader.

	YsGLSLUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());
	YsGLSLUseWindowCoordinateInPlain2DDrawing(YsGLSLSharedPlain2DRenderer(),1);
	YsGLSLDrawPlain2DLinef(YsGLSLSharedPlain2DRenderer(),mx-10,my-10,mx+10,my+10,r,g,b,a);
	YsGLSLDrawPlain2DLinef(YsGLSLSharedPlain2DRenderer(),mx+10,my-10,mx-10,my+10,r,g,b,a);
	
	YsGLSLEndUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());

	
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	
	
	glEnable(GL_DEPTH_TEST);

	static double hdg=0.0;

	GLfloat modelview[16],projection[16],tfm[16];
	YsGLMakeIdentityfv(modelview);
	YsGLMakeTranslationfv(tfm,0.0f,0.0f,-5.0f);
	YsGLMultMatrixfv(modelview,modelview,tfm);
	YsGLMakeXZRotationfv(tfm,(float)hdg);
	YsGLMultMatrixfv(modelview,modelview,tfm);

	YsGLMakePerspectivefv(projection,YSGLPI/6.0,(float)winWid/(float)winHei,1.0,50.0);


	YsGLSLUse3DRenderer(variColorRenderer);

	YsGLSLSet3DRendererModelViewfv(variColorRenderer,modelview);
	YsGLSLSet3DRendererProjectionfv(variColorRenderer,projection);

	YsGLSLDrawPrimitiveVtxColfv(variColorRenderer,GL_POINTS,nVtx,spriteVtx,spriteColor);

	YsGLSLEndUse3DRenderer(variColorRenderer);


	YsGLSLUse3DRenderer(monoColorRenderer);

	YsGLSLSet3DRendererModelViewfv(monoColorRenderer,modelview);
	YsGLSLSet3DRendererProjectionfv(monoColorRenderer,projection);

	YsGLSLDrawPrimitiveVtxfv(monoColorRenderer,GL_POINTS,6,monoColorVtx);

	YsGLSLEndUse3DRenderer(monoColorRenderer);

	
	hdg+=0.01;

	FsSwapBuffers();
}
Example #23
0
int main(){
    
    Vector2 startPosition(300, 500);
    Vector2 startDirection(0, -1);
    
    /* This list is used to store all user emmitted active missiles */
    MissileList enemy2Missiles;
    MissileList playerMissiles;
    
    /* Create the thunder */
    Thunder thunder(startPosition, startDirection);
    thunder.setVelocity(5);
    thunder.SwitchWeapon(BULLET, playerMissiles);
    
    Plane *player;
    player = &thunder;
    
    /* Create the boss */
    LazerEnemy enemy2(Vector2(300, 0), Vector2(0,1));
    enemy2.Init(enemy2Missiles);
    enemy2.setVelocity(15);
    Plane *enemy;
    enemy = &enemy2;
  
    
    FsOpenWindow(0,0,WINDOW_WID,WINDOW_HEI,1);
    glClearColor(0.1, 0.1, 0.1, 1);
    
    bool running = true;
    int i = 0;
    int cntDown = 0;
    
    while(running)
    {
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        FsPollDevice();
        
        int key=FsInkey();
        int lb, mb, rb, mx, my;
        int mouse = FsGetMouseEvent(lb, mb, rb, mx, my);
        
        if(FSKEY_ESC==key) {
            running=false;
            break;
        } else if (FSKEY_UP == key) {
            /* UP for power up */
            ((Thunder *)player)->PowerUp(playerMissiles);
        }
        if (FSMOUSEEVENT_RBUTTONDOWN == mouse) {
            /* Right click for switch between 3 types of weapons */
            i = (i+1) % 3;
            ((Thunder *)player)->SwitchWeapon((MissileType)i, playerMissiles);
        }
        
        /* Thunder: shoot and cool down weapon. */
        player->Shoot(mouse, playerMissiles);
        player->CoolDown();
        
        /* Thunder: move and draw. */
        player->Move(1.0);
        player->Draw();
        
        /* Draw the enemy */
        enemy->Aim(player);
        printf("before move\n");
        enemy->Move(0.4);
        printf("after move\n");
        enemy->Draw();
        /* Enemy fire */
        ((LazerEnemy *)enemy)->Shoot(enemy2Missiles);
        enemy->CoolDown();
        
        if (enemy->CheckHit(playerMissiles) == 1) {
            ((LazerEnemy *)enemy)->Disappear(enemy2Missiles);
            cntDown = 100;
        }
        
        /* Stay for a while after boss die */
        if (cntDown > 0) {
            cntDown--;
            if (cntDown == 0)
                running = false;
        }
        
        /* traverse the missiles list, move missile */
        MissileNode *node;
        node = enemy2Missiles.getFront();
        while(node) {
            node->dat->Move(1.0);
            
            if (!node->dat->CheckInWindow()) {
                node = enemy2Missiles.Delete(node);
            } else {
                node = node->next;
            }
        }
        node = playerMissiles.getFront();
        while(node) {
            node->dat->Move(1.0);
            
            if (!node->dat->CheckInWindow()) {
                node = playerMissiles.Delete(node);
            } else {
                node = node->next;
            }
        }
        
        FOR_EACH(node, enemy2Missiles) {
            node->dat->Draw();
        }
        FOR_EACH(node, playerMissiles) {
            node->dat->Draw();
        }
        PrintPower(((LazerEnemy *)enemy)->getLife());
        FsSwapBuffers();
        FsSleep(25);
    }
    
    return 0;
}
Example #24
0
int main(int argc,char **argv)
{
    Options opt;
    if(!parse_args(&opt,argc,argv)){
        return 1;
    }
    char strk[256],strmu[256],strsigma[256],striso[256];
    int terminate=0;
    CameraObject camera;
    OrbitingViewer orbit;

	orbit.focusY=4.0;

    camera.z=10.0;

    FsOpenWindow(16,16,800,600,1);


    Cylinder cylinder;
	cylinder.setRadius(9.0);

    YsVec3 min(-10.0,0.0,-10.0);
    YsVec3 max(10.0,20.0,10.0);
    Box box;
    box.setMinMax(min,max);

    std::vector <YsVec3> iniPos;
    const double interval=0.9;
    CreateUniformInitialParticleLocation(iniPos,10,40,10,YsVec3(10.0,20.0,0.0),interval);

    std::vector <YsVec3> drip;
    CreateUniformInitialParticleLocation(drip,5,5,5,YsVec3(0.0,20.0,0.0),interval);

	ParticleSimulation sim;
    if(opt.infile){
        sim.read(opt.infile);
    }
    else{
	    //sim.init(iniPos);
    }
	sim.setObstacle(box);
	//sim.calculate_force();
	//sim.calculate_force();

	sim.mode=sim.MODE_NORMAL;



	glClearColor(0,0,0,0);

	YSBOOL pause=YSFALSE;
    YSBOOL cube=YSFALSE;
    YSBOOL savestl=YSFALSE;

    while(0==terminate)
    {
        FsPollDevice();

        int wid,hei;
        FsGetWindowSize(wid,hei);

        int key=FsInkey();
        switch(key)
        {
        case FSKEY_K:
            {
            printf("Enter k:\n");
            fscanf(stdin,"%lf",strk);
            double k=atof(strk);
            sim.setK(k);
            break;
            }
        case FSKEY_M:
            {
            printf("Enter mu:\n");
            fscanf(stdin,"%lf",strmu);
            double mu=atof(strmu);
            sim.setMu(mu);
            break;
            }
        case FSKEY_S:
            {
            printf("Enter Sigma:\n");
            fscanf(stdin,"%lf",strmu);
            double sigma=atof(strsigma);
            sim.setSigma(sigma);
            break;
            }
        case FSKEY_Q:
            if(cube){
                cube=YSFALSE;
            }
            else{
                cube=YSTRUE;
            }
            break;
        case FSKEY_I:
            {
                printf("Enter isolevel:\n");
                fscanf(stdin,"%lf",striso);
                double iso=atof(striso);
                sim.setIso(iso);
                break;
            }
        case FSKEY_L:
            if(savestl){
                savestl=YSFALSE;
            }
            else{
                savestl=YSTRUE;
            }
            break;

        case FSKEY_D:
            sim.placeParticles(drip);
            break;

		case FSKEY_P:
			YsFlip(pause);
			break;
        case FSKEY_ESC:
            terminate=1;
            break;
        }


		if(FSKEY_SPACE==key || YSTRUE!=pause)
		{
			sim.update();
		}

        if(0!=FsGetKeyState(FSKEY_LEFT))
        {
            orbit.h+=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_RIGHT))
        {
            orbit.h-=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_UP))
        {
            orbit.p+=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_DOWN))
        {
            orbit.p-=YsPi/180.0;
        }
        if(0!=FsGetKeyState(FSKEY_F) && orbit.dist>1.0)
        {
            orbit.dist/=1.05;
        }
        if(0!=FsGetKeyState(FSKEY_B) && orbit.dist<200.0)
        {
            orbit.dist*=1.05;
        }
        orbit.SetUpCamera(camera);

        glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);

        glViewport(0,0,wid,hei);

        // Set up 3D drawing
        camera.SetUpCameraProjection();
        camera.SetUpCameraTransformation();

        glEnable(GL_DEPTH_TEST);
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(1,1);

        // 3D drawing from here
		glPushMatrix();
		glPointSize(3);
        if(cube){
           sim.drawMesh();
           if(savestl){
               sim.shl.SaveBinStl("test.stl");
               printf("stl saved\n");
               savestl=YSFALSE;
           }
        }
        else{
            sim.drawParticles();
        }
        //sim.drawColorFieldGrid();

        glPopMatrix();

        // Set up 2D drawing
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0,(float)wid-1,(float)hei-1,0,-1,1);

        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();

        glDisable(GL_DEPTH_TEST);

        FsSwapBuffers();
        FsSleep(25);
    }
    //sim.write(opt.outfile);

    return 0;
}
Example #25
0
int main (void)
{
    const double YS_PI=3.1415927;
    FsOpenWindow(16, 16, 800, 600, 1);
    
    int ObstaclesState[5];
    int x1[5], y1[5], x2[5], y2[5];
    
    int Point[10000];//trajectory
    int p[10000],q[10000];//trajectory
    
    srand((unsigned)time(NULL));
    
   // for(int i=0;i<10000;i++)
   // {
   //     Point[i]=1;
   // }//draw points
    
    for(int i=0;i<5;++i)
    {
    x1[i]=rand()%720;
    y1[i]=rand()%520;
    x2[i]=x1[i]+80+rand()%70;
    y2[i]=y1[i]+80+rand()%70;
    ObstaclesState[i]=1;
    }
    
    int terminate=0;
    int y=0;
    int x=30;
    int a=55;
    int b=545;
    
    double m=1.0;
    double dt=0.025;
    int CannonballState=0;
  
    int angle=30;
    
    double vx;
    double vy;

    int Hit=0;
    int TargetState=1;
    
  
    while(0==terminate)
 {
     FsPollDevice();
     
     angle++;
     if(angle>=90) angle=0;
     
     int key=FsInkey();
       if(FSKEY_ESC==key)
       {
          terminate=1;
       }
       else if(FSKEY_SPACE==key)
     {
         if(0==CannonballState)
       {
           CannonballState=1;

           vx=cos(angle*YS_PI/180)*400;
           vy=-sin(angle*YS_PI/180)*400;
       }
     }

     //draw screen
     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

     if(0!=ObstaclesState)
		{
			for(int i=0; i<5; ++i)
			{
				if(0!=ObstaclesState[i])
                {
                    DrawObstacles(x1[i],y1[i],x2[i],y2[i]);
                if(0!=CannonballState && 0!=CheckCollision(a, b, x1[i], y1[i], x2[i], y2[i]))
                 {
                    printf("Hit An Obstacle!\n");
                    ObstaclesState[i]=0;
                    CannonballState=0;
                    Hit=1;
                    a=55;
                    b=545;
                 }
                }
                if(0!=Hit)
                {
                    DrawObstacles2(x1[i],y1[i],x2[i],y2[i]);
                }
            }
        }
     
    if(0!=TargetState)
                 {
                    if(0!=CannonballState && 0!=CheckHit(a, b, y))
                    {
                        printf("HitTarget!\n");
                        TargetState=0;
                        CannonballState=0;
                        break;
                    }
                 }
        
    DrawCannonLine(x);
    RotateCannonline(x, 90);
    DrawCannon();
    DrawTarget(y);
    MoveTarget(y, 600);

     if(0!=CannonballState)
     {
        DrawCannonball(a, b);
        MoveCannonball(a, b, vx, vy, m, dt);
         
        // for(int i=0;i<10000;i++)
        // {
        //     Point[i]=1;
        // }//draw points
         
       //  if(0!=Point)//not working
       //  {
             for(int i=0; i<10000; ++i)
             {
       //          if(0!=Point[i])
        //         {
                     p[i]=a;
                 //    printf("%d\n",a);
                     q[i]=b;
//                     DrawTrajectory(p[i], q[i]);
         ///        }
           //  }
         }
        if(a>800||b>600)
         {
             CannonballState=0;
             a=55;
             b=545;
         }
     }
    FsSwapBuffers();
    FsSleep(25);
 }
    return 0;
}
void GeblGuiEditorBase::Draw(void)
{
	if(YSTRUE!=drawingMasterSwitch)
	{
		DrawGuiOnly();
		return;
	}

	// Do this at the beginning of Draw funtion.  This will allow one of the elements set SetNeedRedraw(YSTRUE) 
	// within drawing function so that Draw function will be called again in the next iteragion. >>
	SetNeedRedraw(YSFALSE);
	drawEnv.SetNeedRedraw(YSFALSE);
	threeDInterface.SetNeedRedraw(YSFALSE);
	// <<


	glEnable(GL_POLYGON_OFFSET_FILL);
	glPolygonOffset(1,1);


	if(NULL==slHd)
	{
		if(NULL!=GetTopStatusBar())
		{
			GetTopStatusBar()->ClearStringAll();
		}
		if(NULL!=GetBottomStatusBar())
		{
			GetBottomStatusBar()->ClearStringAll();
		}
	}

	if(NULL!=slHd && NULL!=GetTopStatusBar())
	{
		YsWString ful,pth,fil;
		slHd->GetFileName(ful);
		ful.SeparatePathFile(pth,fil);
		if(YSTRUE==slHd->IsModified())
		{
			fil.Append(L"(*)");
		}

		YsWString curMsg;
		if(0!=YsWString::Strcmp(fil,GetTopStatusBar()->GetString(curMsg,0)))
		{
			GetTopStatusBar()->SetString(0,fil);
		}
	}

	if(NULL!=slHd && NULL!=GetBottomStatusBar())
	{
		YsString str("Selection");
		YsString append;

		{
			YsArray <YsShellVertexHandle> selVtHd;
			slHd->GetSelectedVertex(selVtHd);
			if(0<selVtHd.GetN())
			{
				append.Printf("  Vertex:%d",(int)selVtHd.GetN());
				str.Append(append);
			}
		}
		{
			YsArray <YsShellPolygonHandle> selPlHd;
			slHd->GetSelectedPolygon(selPlHd);
			if(0<selPlHd.GetN())
			{
				append.Printf("  Polygon:%d",(int)selPlHd.GetN());
				str.Append(append);
			}
		}
		{
			YsArray <YsShellExt::ConstEdgeHandle> selCeHd;
			slHd->GetSelectedConstEdge(selCeHd);
			if(0<selCeHd.GetN())
			{
				append.Printf("  ConstEdge:%d",(int)selCeHd.GetN());
				str.Append(append);
			}
		}
		{
			YsArray <YsShellExt::FaceGroupHandle> selFgHd;
			slHd->GetSelectedFaceGroup(selFgHd);
			if(0<selFgHd.GetN())
			{
				append.Printf("  FaceGroup:%d",(int)selFgHd.GetN());
				str.Append(append);
			}
		}
		GetBottomStatusBar()->SetString(0,str);
	}


	int viewport[4];
	drawEnv.GetOpenGlCompatibleViewport(viewport);
	drawEnv.SetVerticalOrientation(YSTRUE);
	drawEnv.UpdateNearFar();


	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);


	if(YsCoordSysModel==YSOPENGL)
	{
		glFrontFace(GL_CCW);
	}
	else
	{
		glFrontFace(GL_CW);
	}


	const YsMatrix4x4 &projMat=drawEnv.GetProjectionMatrix();
	const YsMatrix4x4 &viewMat=drawEnv.GetViewMatrix();
	const YsMatrix4x4 projViewMat=(projMat*viewMat);

	threeDInterface.SetViewport(viewport);
	threeDInterface.SetProjViewModelMatrix(projViewMat);


	glViewport(viewport[0],viewport[1],viewport[2],viewport[3]);

	GLfloat glProjMat[16];
	projMat.GetOpenGlCompatibleMatrix(glProjMat);

	GLfloat glModelviewMat[16];
	viewMat.GetOpenGlCompatibleMatrix(glModelviewMat);


	// glMatrixMode(GL_PROJECTION);
	// glLoadIdentity();
	// glMultMatrixf(glProjMat);
	// glMatrixMode(GL_MODELVIEW);
	// glLoadIdentity();
	// glMultMatrixf(glModelviewMat);


	YsGLSLSetShared3DRendererProjection(glProjMat);
	YsGLSLSetShared3DRendererModelView(glModelviewMat);


	YsVec3 lightDir=YsUnitVector(YsVec3(0.1,1.0,3.0));
	const GLfloat lightDirf[]={lightDir.xf(),lightDir.yf(),lightDir.zf()};
	YsGLSLSetShared3DRendererDirectionalLightInCameraCoordinatefv(0,lightDirf);
	YsGLSLSetShared3DRendererSpecularColor(config->GetSpecularColor());
	YsGLSLSetShared3DRendererAmbientColor(config->GetAmbientColor());
	YsGLSLSetShared3DRendererLightColor(0,config->GetLightColor());



	actuallyDrawVertex=drawVertex;
	actuallyDrawConstEdge=drawConstEdge;
	actuallyDrawPolygonEdge=drawPolygonEdge;
	actuallyDrawPolygon=drawPolygon;
	actuallyDrawShrunkPolygon=drawShrunkPolygon;
	actuallyDrawNonManifoldEdge=drawNonManifoldEdge;

	if(NULL!=UIBeforeDrawCallBack)
	{
		(*UIBeforeDrawCallBack)(*this);
	}

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);


	if(YSTRUE==viewDrawBackgroundGradation->GetCheck() && (NULL==guiExtension || YSTRUE!=guiExtension->DrawBackground()))
	{
// Linear interpolation looks to be too fast.  Probably need three colors.
		YsGLSLUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());
		YsGLSLUseWindowCoordinateInPlain2DDrawing(YsGLSLSharedPlain2DRenderer(),YSTRUE);

		glDepthMask(0);

		const GLfloat rect[12]=
		{
			0                   ,0,
			(GLfloat)viewport[2],0,
			0                   ,(GLfloat)viewport[3]/2.0f,
			(GLfloat)viewport[2],(GLfloat)viewport[3]/2.0f,
			0                   ,(GLfloat)viewport[3],
			(GLfloat)viewport[2],(GLfloat)viewport[3]
		};
		const GLfloat color[24]=
		{
			config->bgColor[0].Rf(),config->bgColor[0].Gf(),config->bgColor[0].Bf(),1,
			config->bgColor[0].Rf(),config->bgColor[0].Gf(),config->bgColor[0].Bf(),1,
			config->bgColor[1].Rf(),config->bgColor[1].Gf(),config->bgColor[1].Bf(),1,
			config->bgColor[1].Rf(),config->bgColor[1].Gf(),config->bgColor[1].Bf(),1,
			config->bgColor[2].Rf(),config->bgColor[2].Gf(),config->bgColor[2].Bf(),1,
			config->bgColor[2].Rf(),config->bgColor[2].Gf(),config->bgColor[2].Bf(),1
		};
		YsGLSLDrawPlain2DPrimitivefv(YsGLSLSharedPlain2DRenderer(),GL_TRIANGLE_STRIP,6,rect,color);

		glDepthMask(1);

		YsGLSLEndUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());
	}



	threeDInterface.Draw();


	if(NULL!=slHd && YSTRUE==slHd->NeedRemakeHighlightVertexBuffer())
	{
		slHd->GetHighlight().RemakeVertexBuffer(*slHd);
		slHd->SetNeedRemakeHighlightVertexBuffer(YSFALSE);
	}

	if(NEED_REMAKE_DRAWING_NONE!=needRemakeDrawingBuffer || (nullptr!=slHd && YSTRUE==slHd->GetTemporaryModification().Changed()))
	{
		RemakeDrawingBuffer(slHd,needRemakeDrawingBuffer);
		needRemakeDrawingBuffer=NEED_REMAKE_DRAWING_NONE;
		slHd->GetTemporaryModification().ClearChangeFlag();
	}
	if(NEED_REMAKE_DRAWING_NONE!=needRemakeDrawingBuffer_for_OtherShell && YSTRUE==actuallyDrawOtherShell)
	{
		YsArray <YsShellDnmContainer <YsShellExtEditGui>::Node *> allNode;
		shlGrp.GetNodePointerAll(allNode);
		for(YSSIZE_T nodeIdx=0; nodeIdx<allNode.GetN(); ++nodeIdx)
		{
			if(slHd!=allNode[nodeIdx])
			{
				RemakeDrawingBuffer(allNode[nodeIdx],needRemakeDrawingBuffer_for_OtherShell);
			}
		}
		needRemakeDrawingBuffer_for_OtherShell=NEED_REMAKE_DRAWING_NONE;
	}


	{
		GLfloat prevTfm[16];
		GLfloat curNodeTfm[16];
		if(YSTRUE==dnmEditMode)
		{
			YsMatrix4x4 curMat;
			{
				YsGLSLShaded3DRenderer renderer;
				renderer.GetModelView(prevTfm);
				curMat.CreateFromOpenGlCompatibleMatrix(prevTfm);
			}
			YsMatrix4x4 tfm=curMat*dnmState.GetNodeToRootTransformation(slHd);
			tfm.GetOpenGlCompatibleMatrix(curNodeTfm);
			YsGLSLSetShared3DRendererModelView(curNodeTfm);
		}


		YsShellExtDrawingBuffer &drawBuf=slHd->GetDrawingBuffer();
		if(YSTRUE==actuallyDrawVertex && NULL!=slHd)
		{
			GeblGuiFoundation::DrawVertex(*slHd,viewport);
		}
		if(0<drawBuf.selectedVertexPosBuffer.GetNumVertex() && NULL!=slHd)
		{
			GeblGuiFoundation::DrawSelectedVertex(*slHd,viewport);
		}
		if(0<drawBuf.selectedVertexLineBuffer.GetNumVertex() && NULL!=slHd)
		{
			GeblGuiFoundation::DrawSelectedVertexLine(*slHd);
		}
		if(YSTRUE==actuallyDrawPolygonEdge && NULL!=slHd)
		{
			GeblGuiFoundation::DrawPolygonEdge(*slHd);
		}
		if(YSTRUE==actuallyDrawShrunkPolygon && NULL!=slHd)
		{
			GeblGuiFoundation::DrawShrunkPolygon(*slHd);

		}
		if(0<drawBuf.selectedPolygonPosBuffer.GetNumVertex() && NULL!=slHd)
		{
			GeblGuiFoundation::DrawSelectedPolygon(*slHd);
		}
		if(YSTRUE==actuallyDrawConstEdge && 0<drawBuf.constEdgeVtxBuffer.GetNumVertex() && NULL!=slHd)
		{
			GeblGuiFoundation::DrawConstEdge(*slHd);
		}
		if(0<drawBuf.selectedConstEdgeVtxBuffer.GetNumVertex() && NULL!=slHd)
		{
			GeblGuiFoundation::DrawSelectedConstEdge(*slHd);
		}
		if(YSTRUE==dnmEditMode)
		{
			YsGLSLSetShared3DRendererModelView(prevTfm);
		}


		if(YSTRUE!=dnmEditMode)
		{
			DrawInGeometryEditMode();
		}
		else
		{
			DrawInDnmEditMode();
		}


		if(YSTRUE==dnmEditMode)
		{
			YsGLSLSetShared3DRendererModelView(curNodeTfm);
		}
		if(0<=drawBuf.selectedFaceGroupVtxBuffer.GetNumVertex() && NULL!=slHd)
		{
			GeblGuiFoundation::DrawSelectedFaceGroup(*slHd);
		}
		if(YSTRUE==dnmEditMode)
		{
			YsGLSLSetShared3DRendererModelView(prevTfm);
		}
	}




	if(NULL!=slHd && YSTRUE==actuallyDrawNonManifoldEdge)
	{
		if(YSTRUE==nonManifoldEdgeCache.IsModified(slHd))
		{
			nonManifoldEdgeCache.CacheNonManifoldEdge(slHd);
		}
		struct YsGLSL3DRenderer *renderer=YsGLSLSharedVariColor3DRenderer();
		YsGLSLUse3DRenderer(renderer);

		glLineWidth(3);
		YsGLSLDrawPrimitiveVtxColfv(renderer,GL_LINES,nonManifoldEdgeCache.lineVtxBuf.GetNi(),nonManifoldEdgeCache.lineVtxBuf,nonManifoldEdgeCache.lineColBuf);
		glLineWidth(1);

		YsGLSLEndUse3DRenderer(renderer);

		// The following could have easily be done by glPointSize.  However, stupid OpenGL ES 2.0 got rid of glPointSize.
		// OpenGL ES should be gone.  The hardware on the tablets and smart phones are good enough to support full-blown
		// OpenGL.  OpenGL ES will be remembered as a dark history of OpenGL.  That is bad.  Not as bad as Direct 3D though.
		renderer=YsGLSLSharedVariColorMarkerByPointSprite3DRenderer();
		YsGLSLUse3DRenderer(renderer);

#ifdef GL_PROGRAM_POINT_SIZE
		glEnable(GL_POINT_SPRITE);
		glEnable(GL_PROGRAM_POINT_SIZE);
#endif
		YsGLSLSet3DRendererUniformMarkerType(renderer,YSGLSL_MARKER_TYPE_RECT);
		YsGLSLSet3DRendererUniformMarkerDimension(renderer,3.0f);
		YsGLSLDrawPrimitiveVtxColfv(
		    renderer,GL_POINTS,
		    nonManifoldEdgeCache.pointVtxBuf.GetNi(),
		    nonManifoldEdgeCache.pointVtxBuf,
		    nonManifoldEdgeCache.pointColBuf);
#ifdef GL_PROGRAM_POINT_SIZE
		glDisable(GL_POINT_SPRITE);
		glDisable(GL_PROGRAM_POINT_SIZE);
#endif
		YsGLSLEndUse3DRenderer(renderer);
	}

	if(YSTRUE==drawHighlight)
	{
		auto &bufManager=YsGLBufferManager::GetSharedBufferManager();
		auto &highlight=slHd->GetHighlight();

		YsGLSLRenderer renderer(YsGLSLSharedFlat3DRenderer());

		const GLfloat blue[]={0.0f,0.0f,1.0f,1.0f};
		YsGLSLSet3DRendererUniformColorfv(renderer,blue);

		{
			auto unitPtr=bufManager.GetBufferUnit(highlight.highlightedEdgeVboHandle);
			if(nullptr!=unitPtr && YsGLBufferManager::Unit::EMPTY!=unitPtr->GetState())
			{
				unitPtr->GetActualBuffer()->DrawPrimitiveVtx(renderer,GL_LINES);
			}
		}

		glLineWidth(2);
		{
			auto unitPtr=bufManager.GetBufferUnit(highlight.highlightedThickEdgeVboHandle);
			if(nullptr!=unitPtr && YsGLBufferManager::Unit::EMPTY!=unitPtr->GetState())
			{
				unitPtr->GetActualBuffer()->DrawPrimitiveVtx(renderer,GL_LINES);
			}
		}
		glLineWidth(1);

		const GLfloat darkBlue[]={0.0f,0.0f,0.7f,1.0f};
		YsGLSLSet3DRendererUniformColorfv(renderer,darkBlue);
		{
			auto unitPtr=bufManager.GetBufferUnit(highlight.highlightedPolygonVboHandle);
			if(nullptr!=unitPtr && YsGLBufferManager::Unit::EMPTY!=unitPtr->GetState())
			{
				unitPtr->GetActualBuffer()->DrawPrimitiveVtx(renderer,GL_TRIANGLES);
			}
		}
	}

	if(NULL!=UIDrawCallBack3D)
	{
		UIDrawCallBack3D(*this);
	}
	if(draw3dCallBack)
	{
		draw3dCallBack();
	}


	refBmpStore->Draw();


	if(YSTRUE==drawAxis)
	{
		const GLfloat axisLength=5.0;
		GeblGuiFoundation::DrawAxis(axisLength,viewport,projMat,viewMat);
	}



	// 2D Drawing
	// glMatrixMode(GL_PROJECTION);
	// glLoadIdentity();
	// glOrtho(0.0,(double)viewport[2],(double)viewport[3],0.0,-1.0,1.0);
	// glMatrixMode(GL_MODELVIEW);
	// glLoadIdentity();

	YsGLSLUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());
	YsGLSLUseWindowCoordinateInPlain2DDrawing(YsGLSLSharedPlain2DRenderer(),YSTRUE);
	{
		if(YSTRUE==lBtnDown)
		{
			const GLfloat rect[8]=
			{
				(GLfloat)lBtnDownMx,(GLfloat)lBtnDownMy,
				(GLfloat)moveMx,    (GLfloat)lBtnDownMy,
				(GLfloat)moveMx,    (GLfloat)moveMy,
				(GLfloat)lBtnDownMx,(GLfloat)moveMy
			};
			const GLfloat color[16]=
			{
				0,0,0,0.8f,
				0,0,0,0.8f,
				0,0,0,0.8f,
				0,0,0,0.8f
			};
			YsGLSLDrawPlain2DPrimitivefv(YsGLSLSharedPlain2DRenderer(),GL_LINE_LOOP,4,rect,color);
		}
	}
	YsGLSLEndUsePlain2DRenderer(YsGLSLSharedPlain2DRenderer());

	glDisable(GL_DEPTH_TEST);

	FsGuiCanvas::Show();

	if(NULL!=UIDrawCallBack2D)
	{
		(*UIDrawCallBack2D)(*this);
	}

	FsSwapBuffers();
}
int main(void)
{
    
    printf("Enter Dimension>");
    
    char str[256];
    fgets(str,255,stdin);
    int wid=0,hei=0;
    {
        // Either cut & paste Parse function, or write parsing algorithm here.
        int state=0,n=0;
        for(int i=0; 0!=str[i]; ++i)
        {
            if(0==state)
            {
                if(' '!=str[i])
                {
                    if(0==n)
                    {
                        wid=atoi(str+i);
                    }
                    else if(1==n)
                    {
                        hei=atoi(str+i);
                    }
                    ++n;
                    state=1;
                }
            }
            else
            {
                if(' '==str[i])
                {
                    state=0;
                }
            }
        }
        if(2>n || 0>wid || 0>hei)
        {
            return 0;
        }
    }
    
    
    CharBitmap bmp;
    bmp.Create(wid,hei);
    CharBitmap undo(bmp);
    FsOpenWindow(0,0,wid*20,hei*20,1);
    
    for(;;)
    {
        FsPollDevice();
        auto key=FsInkey();
        
        int lb,mb,rb,mx,my;
        FsGetMouseEvent(lb,mb,rb,mx,my);
        
        if(FSKEY_ESC==key)
        {
            break;
        }
        if(FSKEY_0<=key && key<=FSKEY_7)
        {
            undo=bmp;
            int px=mx/20;
            int py=my/20;
            int colorCode=key-FSKEY_0;
            bmp.SetPixel(px,py,colorCode);   //why can int colorcode call the function setpixel which takes unsigned char?
            
        }
        if(FSKEY_U==key)
        {
            bmp=undo;
        }
        
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
        bmp.Draw();
        FsSwapBuffers();
        
        FsSleep(25);
    }
}