int FsGetMouseEvent(int &lb,int &mb,int &rb,int &mx,int &my) { if(0<nMosBufUsed) { int eventType=mosBuffer[0].eventType; mx=mosBuffer[0].mx; my=mosBuffer[0].my; lb=mosBuffer[0].lb; mb=mosBuffer[0].mb; rb=mosBuffer[0].rb; int i; for(i=0; i<nMosBufUsed-1; i++) { mosBuffer[i]=mosBuffer[i+1]; } nMosBufUsed--; return eventType; } else { FsGetMouseState(lb,mb,rb,mx,my); return FSMOUSEEVENT_NONE; } }
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; }
int Game(void) { DWORD passedTime = 0; FsPassedTime(true); //////////// initial setting up the scene //////////////////////////////////////// int timeSpan = 33; // milliseconds double timeInc = (double)timeSpan * 0.001; // time increment in seconds FsGetWindowSize(width, height); int lb,mb,rb,mx,my; glViewport(0, 0, width, height); ////////////////////// main simulation loop ////////////////////////// while (1) { FsPollDevice(); FsGetMouseState(lb,mb,rb,mx,my); int key=FsInkey(); if(key == FSKEY_ESC) break; timeInc = (double)(passedTime) * 0.001; clocktime += timeInc; /////////// update physics ///////////////// updateNumPhysics(simBall1, timeInc); updatePrecisePhysics(realBall, timeInc); ///////////////////////////////////////// renderScene(); ////// update time lapse ///////////////// passedTime = FsPassedTime(); // Making it up to 50fps int timediff = timeSpan-passedTime; // printf("\ntimeInc=%f, passedTime=%d, timediff=%d", timeInc, passedTime, timediff); while(timediff >= timeSpan/3) { FsSleep(5); passedTime=FsPassedTime(); // Making it up to 50fps timediff = timeSpan-passedTime; // printf("--passedTime=%d, timediff=%d", passedTime, timediff); } passedTime=FsPassedTime(true); // Making it up to 50fps } 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; }