// draw the score to the screen void drawScore(){ std::ostringstream ch; ch << score; glPrintf( "SCORE: ", 20, 325, GLUT_BITMAP_HELVETICA_18); glPrintf( ch.str().c_str(), 30, 275, GLUT_BITMAP_HELVETICA_18); glPrintf( "SET", 300, 440, GLUT_BITMAP_HELVETICA_18); }
// The Analog Channel Setup Menu int bgMenuAna2 ( _AnaSetting *Input ) { static int state, done; auto int options; state = MENU_INIT; done = 0; while ( !done ) { keyProcess(); costate { waitfor(DelayMs(1)); glBuffLock(); glSetBrushType(PIXWHITE); glBlock(0,180,320,60); glSetBrushType(PIXBLACK); glPrintf(0,180,&fi10x16,"Input -> %d",Input->In ); glPrintf(0,200,&fi10x16,"Status -> %s",statusMsg[Input->Enable]); glPrintf(0,220,&fi10x16,"Mode -> %s",modeMsg[Input->GainMode]); statusMsg[Input->Enable], glBuffUnlock(); waitfor ((options =glMenu( &MenuAnaSet2, &state, 30, 30 ) )!= 0); switch (options) { case 1: Input ->Enable = 1; done = 1; break; case 2: Input ->Enable = 0; done = 1; break; case 3: waitfor ( bgMenuRSel ( Input ) ); break; case 4: done = 1; break; } } } glBuffLock(); glSetBrushType(PIXWHITE); glBlock(0,180,320,60); glSetBrushType(PIXBLACK); glMenuClear( &MenuAnaSet2 ); glRefreshMenu( &MenuAnaSetup ); glBuffUnlock(); return 1; }
main() { //------------------------------------------------------------------------ // Initialize the controller //------------------------------------------------------------------------ brdInit(); //initialize board for this demo // Start-up the keypad driver // Initialize the graphic driver dispInit(); keypadDef(); // Use the default keypad ASCII return values glBackLight(1); // Turn-on the backlight glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8); // Initialize 6x8 font glBlankScreen(); for(;;) { glPrintf (0, 0, &fi6x8, "Waiting for a Switch"); glPrintf (0, 8, &fi6x8, "to be pressed on the"); glPrintf (0, 16, &fi6x8, "prototyping board..."); while (BitRdPortI(PGDR, S2) && BitRdPortI(PGDR, S3)); glBlankScreen(); if (!BitRdPortI(PGDR, S2)) { glPrintf (0, 0, &fi6x8, "Switch 2 is Active!"); dispLedOut(5, 1); //Turn-on Keypad LED DS1 BitWrPortI(PGDR, &PGDRShadow, 0, DS1); //proto-board DS1 on while (!BitRdPortI(PGDR, S2)); dispLedOut(5, 0); // Turn-OFF Keypad LED DS1 BitWrPortI(PGDR, &PGDRShadow, 1, DS1); //proto-board DS1 off } if (!BitRdPortI(PGDR, S3)) { glPrintf (0, 0, &fi6x8, "Switch 3 is Active!"); dispLedOut(6, 1); //Turn-on Keypad LED DS2 BitWrPortI(PGDR, &PGDRShadow, 0, DS2); //proto-board DS2 on while (!BitRdPortI(PGDR, S3)); dispLedOut(6, 0); // Turn-OFF Keypad LED DS2 BitWrPortI(PGDR, &PGDRShadow, 1, DS2); //proto-board DS2 off } glBlankScreen(); } }
void render() { float rad; // radians of rotation based on frame counter // clear the colour (drawing) and depth sort back (offscreen) buffers glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // count the frame and base a rotation on it. frame++; rad = frame * (0.0175f); for (int i=0; i<max_flares; i++) { drawSprite( flares[i].x,flares[i].y,flare_size,flare_size,0,flareTex); } drawSprite( mx,my,64,64,0,flareTex); // see printf documentation for the formatting of variables... glPrintf(100, 240, font1,"frame=%i, mousebtn: %i, targets: %i", frame, mx, max_targets); // swap the front (visible) buffer for the back (offscreen) buffer swapBuffers(); }
//*************************************************************************** // Function to display the user instruction for creating a message from // the keypad. //*************************************************************************** void display_help(void) { auto int i, loop; auto int wKey, helpMenuDone; // Copy help messages to a single array buffer[0] = '\0'; for(i = 0; i<(sizeof(help)/2); i++) { strcat(buffer, help[i]); } // Display help message until the user presses a key helpMenuDone = FALSE; while(!helpMenuDone) { i=0; while(buffer[i] != '\0' && !helpMenuDone) { glHScroll(0, 16, LCD_XS, 16, -6); glPrintf(116, 20, &fi6x8, "%c", buffer[i++]); // 250ms delay loop, checking for key press every msec for(loop=0; loop < 250; loop++) { msDelay(1); keyProcess (); if(keyGet() != 0) { helpMenuDone = TRUE; } } } } }
void draw_buy_stuff(void) { struct planet * p = &planets[player.place]; for (int i=0; i<num_cargo_types; i++) { glPrintf(0.1,0.3+(0.06*i),"%s:%d:price:%d",cargo_types[i].name,p->cargo_types[i].avil,p->cargo_types[i].price); } }
//------------------------------------------------------------------------ // Display Sign-on message //------------------------------------------------------------------------ void SignOnMessage(void) { auto int signMesgDone, i, loop; auto char buffer[256]; // Display Sign-on Message then wait for any key to continue glXPutBitmap (0,0,53,29,Zwbw5_bmp); msDelay(500); signMesgDone = FALSE; while(!signMesgDone) { i=0; sprintf(buffer, "Hello from Zworld!!!"); strcat(buffer, " Press any KEY to Continue... "); while(buffer[i] != '\0' && !signMesgDone) { glHScroll(50, 0, LCD_XS, 16, -6); glPrintf (116, 4, &fi6x8, "%c", buffer[i++]); for(loop=0; loop < 165; loop++) { msDelay(1); keyProcess (); if(keyGet() != 0) { signMesgDone = TRUE; } } } } }
void draw_sell_stuff(void) { struct planet * p = &planets[player.place]; struct space_ship * s = player.ship; for (int i=0; i<num_cargo_types; i++) { glPrintf(0.1,0.3+(0.06*i),"%s:%d:price:%d",cargo_types[i].name,s->cargo[i].avil,p->cargo_types[i].price); } }
////////////////////////////////////////////////////////// // Display sign-on message on the LCD and run Demo. ////////////////////////////////////////////////////////// nodebug void demo( void ) { auto int px,py; // Current Position auto int dx,dy; // Current Direction auto int lock_cnt; auto int viewloop; auto int iterations; glBuffLock(); glBlankScreen(); drawBox(BOXTOPLEFTX, BOXTOPLEFTY, BOXWIDTH, BOXHEIGHT); glPrintf(20,10, &fi10x16, "glBuffer lock/unlocking Demo"); glPrintf(20,200, &fi10x16, "Increase lock/unlocking usage"); glPrintf(20,216, &fi10x16, "to 0."); glBuffUnlock(); px = BOXTOPLEFTX + 1; py = BOXTOPLEFTY + 1; // Give Direction dx = 2; dy = 2; for(iterations = 1; iterations < 30; iterations++) { for(viewloop=0; viewloop < 10; viewloop++) { glBuffLock(); glPrintf(20,216, &fi10x16, "to %d.", iterations); // By increasing the number of iterations between // locking and unlocking the graphic buffer you can // get increased performance. // // Note: Functions glBuffLock() and glBuffUnlock() can be // nested up to a level of 255, but be sure to balance the // calls. // buffLock_cntrl(&dx, &dy, &px, &py, iterations); glBuffUnlock(); } } }
//------------------------------------------------------------------------ // Display Welcome Message //------------------------------------------------------------------------ nodebug int WelcomeMessage(void) { static int i, status; status = 0; costate { glBlankScreen(); glPrintf(0,0, &fi11x16 , "Welcome..."); for(i=0; i < 4; i++) { switch(i) { case 0: waitfor(scroll_welcome(0, 16, &fi11x16, "Willkommen", -11)); break; case 1: waitfor(scroll_welcome(0, 16, &fi11x16, "Bienvenidos", -11)); break; case 2: waitfor(scroll_welcome(0, 16, &fichinese, "\x22\x21", -16)); break; case 3: waitfor(scroll_welcome(0, 16, &fi11x16, "to Z-World!", -11)); break; } } for(i=0; i<32;i++) { glVScroll(0, 0, LCD_XS, 32, -1); waitfor(DelayMs(30)); } // Delay for 100ms for visual effects waitfor(DelayMs(100)); // Check for keypress to exit welcome message glBlankScreen(); status = 1; } return(status); }
void draw_background(void) { glClearColor(0,0,0,0); glClear(GL_COLOR_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0,1,1,0,-1,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glBegin(GL_LINES); glColor4f(1,1,1,1); glVertex2f(0,0.1); glVertex2f(1,0.1); size_t num_items= sizeof(menu_items)/sizeof(*menu_items); float spacing = 1.0 / num_items; for (size_t item=0; item<num_items; item++) { glVertex2f((item*spacing),0); glVertex2f((item*spacing),0.1); } glEnd(); /* Set the font size and render a small text. */ ftglSetFontFaceSize(font, 25, 12); for (size_t item=0; item<num_items; item++) { if ((int)item == current_screen) glColor4f(1,0,0,1); else glColor4f(1,1,1,1); glPrintf(0.009+(item*spacing),0.09,"%s",menu_items[item].label); } }
//------------------------------------------------------------------------ // Scroll the Welcome Message //------------------------------------------------------------------------ nodebug int scroll_welcome(int x, int y, fontInfo *pInfo, char *ptr, int numBitScroll) { static int i, loop, scroll, status; status = 0; costate { scroll = LCD_XS - (strlen(ptr)*abs(numBitScroll)); for(i=0; i < strlen(ptr); i++) { glHScroll(0, 16, LCD_XS, 16, numBitScroll); waitfor(DelayMs(30)); glPrintf (LCD_XS+numBitScroll, y, pInfo, "%c", ptr[i]); waitfor(DelayMs(30)); } glHScroll(0, 16, LCD_XS, 16, -scroll); waitfor(DelayMs(2500)); status = 1; } return(status); }
int bgBarGraph ( _AnaSetting *Input, fontInfo *pInfo ) { if ( Input ->Enable ) { glSetBrushType(PIXWHITE);// change brush type to White pixels glBlock(Input->xCoord,Input->yCoord,anaWidth,BARHEIGHT); glSetBrushType(PIXBLACK); /****** These four glPlotLines form the bar graph *******/ glPlotLine(Input->xCoord,Input->yCoord,Input->xCoord + anaWidth, Input->yCoord); glPlotLine(Input->xCoord,Input->yCoord + BARHEIGHT, Input->xCoord + anaWidth,Input->yCoord + BARHEIGHT); glPlotLine(Input->xCoord,Input->yCoord,Input->xCoord, Input->yCoord + BARHEIGHT); glPlotLine(Input->xCoord + anaWidth,Input->yCoord, Input->xCoord + anaWidth,Input->yCoord + BARHEIGHT); Input->anaVal = anaInVolts(Input->In,Input->GainMode); if (Input->anaVal > Input->Range) Input->anaVal = Input->Range; if (Input->anaVal < 0 ) Input->anaVal = 0; glBlock(Input->xCoord, ((Input->yCoord+ BARHEIGHT)-(int)(Input->anaVal* Input->Res)), anaWidth, (int)( Input->anaVal * Input->Res ) ); glPrintf(( Input->xCoord+(anaWidth/2))-((pInfo->pixWidth * 5)/2), Input->yCoord - pInfo->pixHeight, pInfo,"%5.2f", Input->anaVal); /********************************************************/ } return 1; }
void DrawHelpPanel() { GLint viewport[4]; glGetIntegerv( GL_VIEWPORT, viewport ); glPushAttrib( GL_COLOR_BUFFER_BIT | GL_ENABLE_BIT ); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D( 0,viewport[2],0,viewport[3]); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glColor4f(1.0,1.0,1.0,0.5); glBegin(GL_QUADS); glVertex2i(viewport[2]/4,viewport[3]/4); glVertex2i(viewport[2]*3/4,viewport[3]/4); glVertex2i(viewport[2]*3/4,viewport[3]*3/4); glVertex2i(viewport[2]/4,viewport[3]*3/4); glEnd(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); glPopMatrix(); glPopAttrib(); glColor4f(1.0f,1.0f,0.0f,1.0f); glPrintf(">>glut(%i,%i)",viewport[2]/4+10,viewport[3]/4+10); glPrintf("P->Toggle on/off Simulation\n"); glPrintf("H->Toggle on/off HelpPanel\n"); glPrintf("F->Toggle on/off FullScreen\n"); glPrintf("T->Toggle Polygon Mode\n"); glPrintf("Space->Reset Camera\n"); }
main() { auto int i,x,y,z; auto char s[256]; auto int NumPixel; auto int FontWidth, FontHeight; //------------------------------------------------------------------------ // Initialize controller //------------------------------------------------------------------------ brdInit(); // Initialize Controller...Required for controllers!!! glInit(); // Initialize the graphic driver glBackLight(1); glSetContrast(24); glXFontInit(&fi10x16, 10, 16, 32, 127, Font10x16); // Initialize basic font glXFontInit(&fi12x16, 12, 16, 32, 127, Font12x16); // Initialize basic font glXFontInit(&fi17x35, 17, 35, 32, 127, Font17x35); // Initialize basic font while(1) { //------------------------------------------------------------------------ // Text scroll-up example //------------------------------------------------------------------------ glPrintf(0, 0,&fi10x16,"Scroll-up Demo"); msDelay(800); FontWidth = 10; FontHeight = 16; glBuffLock(); glBlankScreen(); for (y = 0, z = 32; y < 240; y += FontHeight) { for (x = 0; x < LCD_XS; x+=FontWidth) { glPrintf(x, y,&fi10x16,"%c",z++); if (z > 64) z = 32; } } glBuffUnlock(); msDelay(750); for(y=0; y<3; y++) { glVScroll(0, 0, LCD_XS, LCD_YS, -FontHeight); for (x = 0; x < LCD_XS; x+=FontWidth) { glPrintf(x, LCD_YS-FontHeight, &fi10x16, "%c",z++); if (z > 126) z = 32; msDelay(5); } msDelay(600); } //------------------------------------------------------------------------ // Text scroll-down example //------------------------------------------------------------------------ glBlankScreen(); glPrintf(0, 0,&fi10x16,"Scroll-Down Demo"); msDelay(800); FontWidth = 10; FontHeight = 16; glBuffLock(); glBlankScreen(); for (y = 0, z=32; y < LCD_XS; y += FontHeight) { for (x = 0; x < LCD_XS; x+=FontWidth) { glPrintf(x, y,&fi10x16,"%c",z++); if (z > 126) z = 32; msDelay(5); } } glBuffUnlock(); msDelay(750); for(y=0; y<4; y++) { glVScroll(0, 0, LCD_XS, LCD_YS, FontHeight); for (x = 0; x < LCD_XS; x+=FontWidth) { glPrintf(x, 0,&fi10x16,"%c",z++); if (z > 64) z = 32; msDelay(5); } msDelay(600); } //------------------------------------------------------------------------ // Text Scrolling left example //------------------------------------------------------------------------ glBlankScreen(); glPrintf(0, 0,&fi10x16,"Scroll-Left Demo"); msDelay(1500); NumPixel = 17; for(y = 0; y < 1; y++) { sprintf(s, "Hello from Z-World....."); i =0; while(s[i] != '\0') { glHScroll(0, 60, LCD_XS, 34, -NumPixel); glPrintf (LCD_XS-NumPixel, 60, &fi17x35, "%c", s[i++]); msDelay(300); } } glBlankScreen(); //------------------------------------------------------------------------ // Text Scrolling right and left example //------------------------------------------------------------------------ glPrintf(0, 0,&fi10x16,"Scroll Right&Left Demo"); msDelay(1200); FontWidth = 10; FontHeight = 16; sprintf(s, "Text to Scroll Right/Left"); glPrintf (0, 40, &fi10x16, "%s", s); msDelay(1000); NumPixel = 4; for(y = 0; y < 3; y++) { for(i=0; i<(LCD_XS -(strlen(s)*FontWidth)); i+=FontWidth) { glHScroll(0, 40, LCD_XS, FontHeight, FontWidth); } msDelay(500); for(i=0; i<(LCD_XS-(strlen(s)*FontWidth)); i+=FontWidth) { glHScroll(0, 40, LCD_XS, FontHeight, -FontWidth); } msDelay(500); } glBlankScreen(); } }
void glprintfz(glCompText * font, GLfloat xpos, GLfloat ypos, GLfloat zpos, GLfloat width, char *bf) { glPrintf(font, xpos, ypos, zpos, width, bf, 0); }
void status_report() { //display text informations glPrintf(">>glut(%i,%i)",4,0); glColor3f(1,1,0); glPrintf("FPS:%4.1f\n",g_fps); glColor3f(1.0f,0.4f,0.4f); glPrintf("\nStatus: %s\n",gPauseSimulation?"Paused":"Running"); glPrintf("Fovy : %.2f Speed: %.2f\n",g_fovy,g_Speed); glPrintf("EYE : %.1f %.1f %.1f\n",g_CameraPos.x,g_CameraPos.y,g_CameraPos.z); glPrintf("Focus: %.1f %.1f %.1f\n",g_CameraPos.x+g_CameraForward.x,g_CameraPos.y+g_CameraForward.y,g_CameraPos.z+g_CameraForward.z); glPrintf(">>glut(%i,%i)",4,120); glPrintf("----------------------------------\n"); glPrintf("NumActors : %i\n",gScene->getNbActors()); glPrintf("NumShapes : %i\n",gScene->getTotalNbShapes()); glPrintf("\nPress H for help\n"); if(g_DisplayHelp) DrawHelpPanel(); glPrintf(">>free"); glCheckError("status_report"); }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)getDisplayWidth() / getDisplayHeight(), 0.1, 100); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); struct timeval t, ta, t1, t2; // fps stuff gettimeofday(&t1, NULL); int num_frames = 0; bool quit = false; mouse = getMouse(); keys = getKeys(); resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)getDisplayWidth()/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } while (!quit) { // the main loop doEvents(); // update mouse and key arrays // mask of 4 is right mouse if (keys[KEY_ESC]) quit = true; glClearColor(0, .5, 1, 1); // render between two gettimeofday calls so // we can sleep long enough to roughly sync // to ~60fps but not on the pi! // TODO find something a tad more elegent long i; gettimeofday(&t, NULL); i = t.tv_sec * 1e6 + t.tv_usec; // render(); float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i fps=%3.2f", frame, lfps); kmVec3 tmp; playerFireCount--; if (keys[KEY_LCTRL] && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); kmMat4RotationPitchYawRoll(&model, rad * 4, 0, -rad * 4); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (keys[KEY_CURSL] && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (keys[KEY_CURSR] && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 320, font1,"mouse %i,%i %i ", mouse[0], mouse[1], mouse[2]); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); swapBuffers(); gettimeofday(&ta, NULL); long j = (ta.tv_sec * 1e6 + ta.tv_usec); i = j - i; if (i < 0) i = 1000000; // pass through - slower that 60fps if (i < 16000) usleep(16000 - i); // every 10 frames average the time taken and store // fps value for later printing with glprintf if (++num_frames % 10 == 0) { gettimeofday(&t2, NULL); float dtf = t2.tv_sec - t1.tv_sec + (t2.tv_usec - t1.tv_usec) * 1e-6; lfps = num_frames / dtf; num_frames = 0; t1 = t2; } } closeContext(); return 0; }
main() { static int led, channel, wKey, keypad_active, prompt_displayed; static int new_keypress_message, release_value, i; //------------------------------------------------------------------------ // Initialize the controller //------------------------------------------------------------------------ brdInit(); // Initialize the controller for this demo // Start-up the keypad driver and // Initialize the graphic driver dispInit(); // Use default key values along with a key release code keyConfig ( 3,'R', '1', 0, 0, 0, 0 ); keyConfig ( 6,'E', '2', 0, 0, 0, 0 ); keyConfig ( 2,'D', '3', 0, 0, 0, 0 ); keyConfig ( 5,'+', '4', 0, 0, 0, 0 ); keyConfig ( 1,'U', '5', 0, 0, 0, 0 ); keyConfig ( 4,'-', '6', 0, 0, 0, 0 ); keyConfig ( 0,'L', '7', 0, 0, 0, 0 ); // Initialize 6x8 font glXFontInit(&fi6x8, 6, 8, 32, 127, Font6x8); // Initialize 6x8 font glXFontInit(&fi8x10, 8, 10, 32, 127, Font8x10); // initialize 8x10 font glBlankScreen(); // Initialize control flags keypad_active = FALSE; prompt_displayed = FALSE; new_keypress_message = FALSE; for(;;) { costate { keyProcess (); waitfor ( DelayMs(10) ); } costate { // Wait for any key to be pressed waitfor((wKey = keyGet()) != 0); release_value = -1; switch(wKey) { case 'L': release_value = '7'; break; case '-': release_value = '6'; break; case 'U': release_value = '5'; break; case '+': release_value = '4'; break; case 'D': release_value = '3'; break; case 'E': release_value = '2'; break; case 'R': release_value = '1'; break; } if(release_value != -1) { keypad_active = TRUE; // Wait for the key to be released waitfor(keyGet() == release_value); keypad_active = FALSE; } } costate { if(!keypad_active) { if(!prompt_displayed) { glBlankScreen(); glPrintf (0, 0, &fi6x8, "Waiting for a Key to"); glPrintf (0, 8, &fi6x8, "be pressed on the "); glPrintf (0, 16, &fi6x8, "LCD Keypad...."); glFillPolygon(4, 115, 26, 121,26, 121,31, 115, 31); prompt_displayed = TRUE; new_keypress_message = FALSE; // Turn-Off leds on the Demo board pbLedOut(DS1, OFF); //DS1 off pbLedOut(DS2, OFF); //DS2 off } for(channel = 0; channel <= 6; channel++) { for(led = 0; led <=6; led++) { if(led != channel) dispLedOut(led, 0); } dispLedOut(channel, 1); waitfor(DelayMs(100)); if(keypad_active) { break; } } } } costate { if(keypad_active && !new_keypress_message) { glBlankScreen(); glFillPolygon(4, 113, 26, 121,26, 121,31, 113, 31); switch(wKey) { case 'L': glPrintf (0, 0, &fi8x10, "Scroll-Left key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(0, 1); channel = 0; break; case '-': glPrintf (0, 0, &fi8x10, "Page-Down key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(1, 1); channel = 1; pbLedOut(DS1, ON); //DS1 on break; case 'U': glPrintf (0, 0, &fi8x10, "Scroll-Up key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(2, 1); channel = 2; break; case '+': glPrintf (0, 0, &fi8x10, "Page-Up key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(3, 1); channel = 3; pbLedOut(DS2, ON); //DS2 on break; case 'D': glPrintf (0, 0, &fi8x10, "Scroll-Down key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(4, 1); channel = 4; break; case 'E': glPrintf (0, 0, &fi8x10, "Enter key"); glPrintf (0, 16, &fi8x10, "is Active."); dispLedOut(5, 1); channel = 5; break; case 'R': glPrintf (0, 0, &fi8x10, "Scroll-Right"); glPrintf (0, 16, &fi8x10, "key is Active."); dispLedOut(6, 1); channel = 6; break; } for(led=0; led <=6; led++) { if(led != channel) { dispLedOut(led, 0); } } prompt_displayed = FALSE; new_keypress_message = TRUE; } } costate { if(keypad_active) { for(i=0; i<(LCD_XS-8); i+=4) { glHScroll(0, 26, LCD_XS, 6, -4); waitfor(DelayMs(5)); if(!keypad_active) abort; } for(i=0; i<(LCD_XS-8); i+=4) { glHScroll(0, 26, LCD_XS, 6, 4); waitfor(DelayMs(5)); if(!keypad_active) abort; } } } } }
int main() { lightDir.x=0.5; lightDir.y=.7; lightDir.z=-0.5; kmVec3Normalize(&lightDir,&lightDir); // creates a window and GLES context // create a window and GLES context if (!glfwInit()) exit(EXIT_FAILURE); window = glfwCreateWindow(width, height, "I N V A D E R S ! ! !", NULL, NULL); if (!window) { glfwTerminate(); exit(EXIT_FAILURE); } glfwSetWindowSizeCallback(window,window_size_callback); glfwMakeContextCurrent(window); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); // The obj shapes and their textures are loaded cubeTex = loadPNG("resources/textures/dice.png"); loadObj(&cubeObj, "resources/models/cube.gbo", "resources/shaders/textured.vert", "resources/shaders/textured.frag"); shipTex = loadPNG("resources/textures/shipv2.png"); loadObjCopyShader(&shipObj,"resources/models/ship.gbo",&cubeObj); alienTex = loadPNG("resources/textures/alien.png"); loadObjCopyShader(&alienObj, "resources/models/alien.gbo", &cubeObj); shotTex = loadPNG("resources/textures/shot.png"); loadObjCopyShader(&shotObj, "resources/models/shot.gbo", &cubeObj); expTex = loadPNG("resources/textures/explosion.png"); playerPos.x = 0; playerPos.y = 0; playerPos.z = 0; kmMat4Identity(&view); pEye.x = 0; pEye.y = 2; pEye.z = 4; pCenter.x = 0; pCenter.y = 0; pCenter.z = -5; pUp.x = 0; pUp.y = 1; pUp.z = 0; kmMat4LookAt(&view, &pEye, &pCenter, &pUp); // projection matrix, as distance increases // the way the model is drawn is effected kmMat4Identity(&projection); kmMat4PerspectiveProjection(&projection, 45, (float)width/ height, 0.1, 1000); glViewport(0, 0, width,height); // these two matrices are pre combined for use with each model render kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); // initialises glprint's matrix shader and texture initGlPrint(width,height); font1=createFont("resources/textures/font.png",0,256,16,16,16); font2=createFont("resources/textures/bigfont.png",32,512,9.5,32,48); glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // only used by glprintf glEnable(GL_DEPTH_TEST); int num_frames = 0; bool quit = false; resetAliens(); for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { playerShots[n].alive = false; } initPointClouds("resources/shaders/particle.vert", "resources/shaders/particle.frag",(float)width/24.0); for (int n = 0; n < MAX_ALIENS; n++) { aliens[n].explosion=createPointCloud(40); resetExposion(aliens[n].explosion); // sets initials positions } glClearColor(0, .5, 1, 1); while (!quit) { // the main loop clock_gettime(0,&ts); // note the time BEFORE we start to render the current frame glfwPollEvents(); if (glfwGetKey(window,GLFW_KEY_ESCAPE)==GLFW_PRESS || glfwWindowShouldClose(window)) quit = true; float rad; // radians rotation based on frame counter glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); frame++; rad = frame * (0.0175f * 2); //kmMat4Identity(&model); kmMat4Translation(&model, playerPos.x, playerPos.y, playerPos.z); playerCroll += (PIDcal(playerRoll, playerCroll, &playerPre_error, &playerIntegral) / 2); // kmMat4RotationPitchYawRoll(&model, 0, 3.1416, playerCroll * 3); // kmMat4RotationYawPitchRoll(&rot,0,3.1416,-playerCroll*3); kmMat4Multiply(&model, &model, &rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shipTex); drawObj(&shipObj, &mvp, &mv, lightDir, viewDir); glPrintf(50 + sinf(rad) * 16, 240 + cosf(rad) * 16, font2,"frame=%i", frame); kmVec3 tmp; playerFireCount--; if (glfwGetKey(window,GLFW_KEY_LEFT_CONTROL)==GLFW_PRESS && playerFireCount < 0) { struct playerShot_t *freeShot; freeShot = getFreeShot(); if (freeShot != 0) { playerFireCount = 15; freeShot->alive = true; kmVec3Assign(&freeShot->pos, &playerPos); } } for (int n = 0; n < MAX_PLAYER_SHOTS; n++) { if (playerShots[n].alive) { playerShots[n].pos.z -= .08; if (playerShots[n].pos.z < -10) playerShots[n].alive = false; //kmMat4Identity(&model); kmMat4Translation(&model, playerShots[n].pos.x, playerShots[n].pos.y, playerShots[n].pos.z); //kmMat4RotationPitchYawRoll(&model, rad * 4, 0, // -rad * 4); kmMat4RotationYawPitchRoll(&rot,rad*4,0,-rad*4); kmMat4Multiply(&model,&model,&rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, shotTex); drawObj(&shotObj, &mvp, &mv, lightDir, viewDir); } } playerRoll = 0; if (glfwGetKey(window,GLFW_KEY_LEFT)==GLFW_PRESS && playerPos.x > -10) { playerPos.x -= 0.1; playerRoll = .2; } if (glfwGetKey(window,GLFW_KEY_RIGHT)==GLFW_PRESS && playerPos.x < 10) { playerPos.x += 0.1; playerRoll = -.2; } pEye.x = playerPos.x * 1.25; pCenter.x = playerPos.x; pCenter.y = playerPos.y + 1; pCenter.z = playerPos.z; int deadAliens; deadAliens = 0; for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].alive == true) { //kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); //kmMat4RotationPitchYawRoll(&model, -.4, 0, 0); kmMat4RotationYawPitchRoll(&rot,.2,0,0); kmMat4Multiply(&model,&model,&rot); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); kmMat4Assign(&mv, &view); kmMat4Multiply(&mv, &mv, &model); glBindTexture(GL_TEXTURE_2D, alienTex); drawObj(&alienObj, &mvp, &mv, lightDir, viewDir); kmVec3 d; for (int i = 0; i < MAX_PLAYER_SHOTS; i++) { kmVec3Subtract(&d, &aliens[n].pos, &playerShots[i].pos); if (kmVec3Length(&d) < .7 && playerShots[i].alive) { aliens[n].alive = false; playerShots[i].alive = false; aliens[n].exploding = true; resetExposion(aliens[n].explosion); } } } if (aliens[n].alive != true && aliens[n].exploding != true) { deadAliens++; } } if (deadAliens == MAX_ALIENS) { resetAliens(); } // draw explosions after ALL aliens for (int n = 0; n < MAX_ALIENS; n++) { if (aliens[n].exploding==true) { kmMat4Identity(&model); kmMat4Translation(&model, aliens[n].pos.x, aliens[n].pos.y, aliens[n].pos.z); kmMat4Assign(&mvp, &vp); kmMat4Multiply(&mvp, &mvp, &model); glBindTexture(GL_TEXTURE_2D, expTex); drawPointCloud(aliens[n].explosion, &mvp); aliens[n].explosion->tick=aliens[n].explosion->tick+0.05; if (aliens[n].explosion->tick>1.25) { aliens[n].exploding=false; } else { // update the explosion for (int i=0; i<aliens[n].explosion->totalPoints; i++) { float t; t=aliens[n].explosion->tick; if (i>aliens[n].explosion->totalPoints/2) t=t/2.0; aliens[n].explosion->pos[i*3]=aliens[n].explosion->vel[i*3] * t; aliens[n].explosion->pos[i*3+1]=aliens[n].explosion->vel[i*3+1] * t; aliens[n].explosion->pos[i*3+2]=aliens[n].explosion->vel[i*3+2] * t; } } } } // move camera kmMat4LookAt(&view, &pEye, &pCenter, &pUp); kmMat4Assign(&vp, &projection); kmMat4Multiply(&vp, &vp, &view); kmVec3Subtract(&viewDir,&pEye,&pCenter); kmVec3Normalize(&viewDir,&viewDir); // dump values glPrintf(100, 280, font1,"eye %3.2f %3.2f %3.2f ", pEye.x, pEye.y, pEye.z); glPrintf(100, 296, font1,"centre %3.2f %3.2f %3.2f ", pCenter.x, pCenter.y, pCenter.z); glPrintf(100, 340, font1,"frame %i %i ", frame, frame % 20); glfwSwapBuffers(window); ts.tv_nsec+=20000000; // 1000000000 / 50 = 50hz less time to render the frame //thrd_sleep(&ts,NULL); // tinycthread usleep(20000); // while I work out why tinycthread that was working isnt.... :/ } glfwDestroyWindow(window); glfwTerminate(); return 0; }
void draw_status(void) { glPrintf(0.1,0.2,"Commander: %s",player.name); glPrintf(0.1,0.3,"Location: %s",planets[player.place].name); glPrintf(0.1,0.4,"Worth: %d",player.cash); }
void draw_planet_info(void) { struct planet * p = &planets[player.place]; glPrintf(0.1,0.2,"Name: %s",p->name); }
void draw_ship_info(void) { glPrintf(0.1,0.2,"Ship Name: %s",ship.name); glPrintf(0.1,0.3,"Avil cargo capacity: %d",ship.cap); glPrintf(0.1,0.4,"Range: %d",ship.fuel); }
void C_API Program::Render(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glInitNames(); if (m_ShowText) { begin2D(m_window_width, m_window_height); glColor3f(1.0f, 1.0f, 1.0f); glPrintf(10, m_window_height-20, "Object Loaded In %f Seconds", m_LoadedObj.fLoadTimeInSecs); glPrintf(10, m_window_height-40, "Vertices: %u", m_LoadedObj.nVertexCount); glPrintf(10, m_window_height-60, "Normals: %u", m_LoadedObj.nNormalCount); glPrintf(10, m_window_height-80, "UVs: %u", m_LoadedObj.nUVCount); glPrintf(10, 20, "FPS: %i", calcFPS()); end2D(); } if (m_LoadedObj.pMesh != NULL) { glPushMatrix(); glTranslatef(0.0f, 0.0f, m_Zoom); glRotatef(-(m_AngleY), 1.0f, 0.0f, 0.0f); glRotatef(-(m_AngleX), 0.0f, 1.0f, 0.0f); Mesh::RenderMode renderMode; if (m_Wireframe) { renderMode = Mesh::Wireframe; glLineWidth(1.0f); // Wireframe Line Color: glColor3f(0.6f, 0.6f, 0.77f); } else { renderMode = Mesh::Solid; glLineWidth(2.0f); } // Render Everything: if (m_LoadedObj.nDrawByGroupID == -1) { // First Pass, Normal Rendering: if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } m_LoadedObj.pMesh->SetRenderMode(renderMode); Mesh::GroupMap::const_iterator GroupIndex = m_LoadedObj.pMesh->Groups().begin(); Mesh::GroupMap::const_iterator LastGroup = m_LoadedObj.pMesh->Groups().end(); GLuint name = 0; while (GroupIndex != LastGroup) { glPushName(name); m_LoadedObj.pMesh->Render(GroupIndex); glPopName(); ++name; ++GroupIndex; } if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); } // Second Pass, Draw Group Outline: if (m_LoadedObj.nSelectedGroup != -1) { glColor3f(0.2f, 0.8f, 0.35f); // Give It A Cool Maya Style Outline Color. m_LoadedObj.pMesh->SetRenderMode(Mesh::Wireframe); m_LoadedObj.pMesh->Render(m_LoadedObj.pMesh->Groups().find(m_vMeshGroups[m_LoadedObj.nSelectedGroup])); } } else // Render The Selected Group Only: { if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); } m_LoadedObj.pMesh->SetRenderMode(renderMode); m_LoadedObj.pMesh->Render(m_LoadedObj.pMesh->Groups().find(m_vMeshGroups[m_LoadedObj.nDrawByGroupID])); if ((m_LoadedObj.nNormalCount > 0) && (!m_Wireframe)) { glDisable(GL_LIGHT0); glDisable(GL_LIGHTING); } } glPopMatrix(); } glFlush(); glutSwapBuffers(); }
int bgBarSet (fontInfo *pInfo ) { auto byte loop,index; auto int TotWidth; anatotal = 0; for (loop = 0 ; loop < 8 ; loop++) { if ( AnaSetting[loop].Enable ) { anatotal++; } } TotWidth = 320 / anatotal; anaOffset = TotWidth / anatotal; anaWidth = TotWidth - ( anaOffset ) ; index = 0; glBuffLock(); for (loop = 0 ; loop < 8 ; loop++) { if (AnaSetting[loop].Enable) { AnaSetting[loop].xCoord = ( anaOffset / 2 ) + ( TotWidth * index ); AnaSetting[loop].Height = BARHEIGHT; AnaSetting[loop].yCoord = BARYCOORD; switch ( AnaSetting[loop].GainMode ) { case 0: AnaSetting[loop].Range = 20.0; // 0 to 20vdc break; case 1: AnaSetting[loop].Range = 10.0; // 0 to 10vdc break; case 2: AnaSetting[loop].Range = 5.0; // 0 to 5vdc break; case 3: AnaSetting[loop].Range = 4.0; // 0 to 4vdc break; case 4: AnaSetting[loop].Range = 2.5; // 0 to 2.5vdc break; case 5: AnaSetting[loop].Range = 2.0; // 0 to 2.0vdc break; case 6: AnaSetting[loop].Range = 1.25; // 0 to 1.25 vdc break; case 7: AnaSetting[loop].Range = 1.00; // 0 to 1.0 vdc break; } glPrintf(( AnaSetting[loop].xCoord + ( anaWidth/2 ) )- ( (pInfo->pixWidth * 2) /2 ), AnaSetting[loop].yCoord - ( pInfo->pixHeight * 3 ), pInfo,"A%d",loop); glPrintf(( AnaSetting[loop].xCoord+( anaWidth/2 ) )- ( (pInfo->pixWidth * 4) /2 ), AnaSetting[loop].yCoord - ( pInfo->pixHeight * 2 ), pInfo,"----",loop); AnaSetting[loop].Res =(float)AnaSetting[loop].Height/(float)AnaSetting[loop].Range; index++; } } glBuffUnlock(); return 1; }