void drawGuiBackground(void) { checkGLError("gui background start"); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rasonly(gScreen); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, gScreen->textures[TEX_GUI]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(0, 0); glTexCoord2f(1.0, 0.0); glVertex2i(gScreen->vp_w, 0); glTexCoord2f(1.0, .75); glVertex2i(gScreen->vp_w, gScreen->vp_h); glTexCoord2f(0.0, .75); glVertex2i(0, gScreen->vp_h); glEnd(); }
void drawAI(Visual *d) { char ai[] = "computer player"; rasonly(d); glColor3f(1.0, 1.0, 1.0); drawText(gameFtx, d->vp_w / 4, 10, d->vp_w / (2 * strlen(ai)), ai); /* glRasterPos2i(100, 0); */ }
void drawScore(Player *p, Visual *d) { char tmp[10]; /* hey, they won't reach such a score */ sprintf(tmp, "%d", p->data->score); rasonly(d); glColor4f(1.0, 1.0, 0.2f, 1.0); drawText(gameFtx, 5, 5, 32, tmp); }
void drawGuiLogo() { float pos[] = { 512 - 10 - 256, 384 - 64 }; float size[] = { 256, 64 }; float glpos = 64; float glsize = 32; float font_shift[] = { 0.5, 0.00 }; checkGLError("gui logo start"); rasonly(game->screen); pos[0] *= game->screen->vp_w / 512.0; pos[1] *= game->screen->vp_h / 384.0; size[0] *= game->screen->vp_w / 512.0; size[1] *= game->screen->vp_h / 384.0; glpos *= game->screen->vp_w / 512.0; glsize *= game->screen->vp_w / 512.0; glEnable(GL_TEXTURE_2D); if(game->settings->show_gl_logo == 1) { glPushMatrix(); glTranslatef(pos[0] - glpos + glsize * font_shift[0], pos[1] + glsize * font_shift[1], 0); glScalef(glsize, glsize, glsize); glColor3f(0.2, 0.4, 0.8); ftxRenderString(gameFtx, "gl", 2); glPopMatrix(); } glBindTexture(GL_TEXTURE_2D, game->screen->textures[TEX_LOGO]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(pos[0], pos[1]); glTexCoord2f(1.0, 0.0); glVertex2f(pos[0] + size[0], pos[1]); glTexCoord2f(1.0, 1.0); glVertex2f(pos[0] + size[0], pos[1] + size[1]); glTexCoord2f(0.0, 1.0); glVertex2f(pos[0], pos[1] + size[1]); glEnd(); glDisable(GL_BLEND); checkGLError("gui background end"); }
void displayTrackerScreen() { rasonly(game->screen); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); updateControls(tracker.trackerControls); drawMouse(); SystemSwapBuffers(); }
void drawPause(Visual *display) { char pause[] = "Game is paused"; char winner[] = "Player %d wins!"; char nowinner[] = "No one wins!"; char buf[100]; char *message; static float d = 0; static float lt = 0; float delta; int now; now = SystemGetElapsedTime(); delta = now - lt; lt = now; delta /= 500.0; d += delta; /* printf("%.5f\n", delta); */ if (d > 2 * PI) { d -= 2 * PI; } if ((game->pauseflag & PAUSE_GAME_FINISHED) && game->winner != -1) { if (game->winner >= -1) { float* player_color = gPlayerVisuals[game->winner].pColorAlpha; /* make the 'Player wins' message oscillate between white and the winning bike's color */ //TODO: check this glColor4f((player_color[0] + ((sinf(d) + 1) / 2) * (1 - player_color[0])), (player_color[1] + ((sinf(d) + 1) / 2) * (1 - player_color[1])), (player_color[2] + ((sinf(d) + 1) / 2) * (1 - player_color[2])), 1.0); message = buf; sprintf(message, winner, game->winner + 1); } else { //TODO:DONE redo for gles glColor4f(1.0, (sin(d) + 1) / 2, (sin(d) + 1) / 2,1.0f); message = nowinner; } } else { //TODO:DONE redo for gles glColor4f(1.0, (sin(d) + 1) / 2, (sin(d) + 1) / 2,1.0f); message = pause; } rasonly(gScreen); drawText(gameFtx, display->vp_w / 6, 20, display->vp_w / (6.0f / 4.0f * strlen(message)), message); }
void displayConfigure(void) { char message[] = "Press a key for this action!"; drawGuiBackground(); drawGuiLogo(); drawMenu(gScreen); rasonly(gScreen); glColor3f(1.0, 1.0, 1.0); drawText(guiFtx, gScreen->vp_w / 6, 20, gScreen->vp_w / (6.0f / 4.0f * strlen(message)), message); SystemSwapBuffers(); }
void displayConfigure() { char message[] = "Press a key for this action!"; drawGuiBackground(); if(!game->settings->softwareRendering) drawGuiLogo(); drawMenu(game->screen); rasonly(game->screen); glColor3f(1.0, 1.0, 1.0); drawText(guiFtx, game->screen->vp_w / 6, 20, game->screen->vp_w / (6.0 / 4.0 * strlen(message)), message); SystemSwapBuffers(); }
void displayTport() { char message[] = "Enter port of tracker ..."; drawGuiBackground(); if(!game->settings->softwareRendering) drawGuiLogo(); drawMenu(game->screen); rasonly(game->screen); glColor3f(1.0, 1.0, 1.0); drawText(guiFtx, game->screen->vp_w / 6, 20, game->screen->vp_w / (6.0 / 4.0 * strlen(message)), message); SystemSwapBuffers(); }
void drawHUD(Player *p, PlayerVisual *pV) { char temp[1024]; char pause_message[128]; float pause_color[3]; getPauseString(pause_message, pause_color); glDisable(GL_DEPTH_TEST); glDepthMask(GL_FALSE); rasonly(&pV->display); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* drawHud: parameters - Viewport Width - Viewport Height - Score (or -1 if disabled) - AI status ("computer player" or "") - Speed digital (absolute value) - Speed analog (1 for default speed, > 1 during acceleration) - Booster value (between 0 and 1) - fps - pause message - pause message r,g,b colors */ sprintf(temp, "drawHUD(%d, %d, %d, \"%s\", %f, %f, %f, %f, %d, \"%s\", %f, %f, %f)", pV->display.vp_w, pV->display.vp_h, gSettingsCache.show_scores ? p->data->score : -1, gSettingsCache.show_ai_status ? (p->ai->active ? "AI_COMPUTER" : "") : "", p->data->speed, p->data->speed / (2 * game2->rules.speed), p->data->booster / getSettingf("booster_max"), p->data->wall_buster / getSettingf("wall_buster_max"), getFPS(), pause_message, pause_color[0], pause_color[1], pause_color[2] ); glScalef(pV->display.vp_w / 1024.0f, pV->display.vp_w / 1024.0f, 1.0f); // fprintf(stderr, "%s\n", temp); scripting_Run(temp); glDisable(GL_BLEND); glDepthMask(GL_TRUE); glEnable(GL_DEPTH_TEST); }
void drawGuiLogo(void) { float pos[] = { 512 - 10 - 320, 384 - 80 }; float size[] = { 320, 80 }; float glpos = 64; float glsize = 32; checkGLError("gui logo start"); rasonly(gScreen); pos[0] *= gScreen->vp_w / 512.0f; pos[1] *= gScreen->vp_h / 384.0f; size[0] *= gScreen->vp_w / 512.0f; size[1] *= gScreen->vp_h / 384.0f; glpos *= gScreen->vp_w / 512.0f; glsize *= gScreen->vp_w / 512.0f; glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, gScreen->textures[TEX_LOGO]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); { // float texy = 1.0f - 256.0f / 320.0f; float texy = 0.0f; glTexCoord2f(0.0, texy); glVertex2f(pos[0], pos[1]); glTexCoord2f(1.0, texy); glVertex2f(pos[0] + size[0], pos[1]); glTexCoord2f(1.0, 1.0); glVertex2f(pos[0] + size[0], pos[1] + size[1]); glTexCoord2f(0.0, 1.0); glVertex2f(pos[0], pos[1] + size[1]); } glEnd(); glDisable(GL_BLEND); checkGLError("gui background end"); }
void keyboardConfigure(int key, int unicode, int x, int y) { *configureKeyEntry = key; initMenuCaption(configureKeyMenu); #ifdef SOUND playMenuFX(fx_action); #endif drawGuiBackground(); if(!game->settings->softwareRendering) drawGuiLogo(); drawMenu(game->screen); rasonly(game->screen); SystemSwapBuffers(); restoreCallbacks(); }
void drawConsole(Visual *d) { int lines; rasonly(d); glColor3f(1.0, 0.3f, 0.3f); if (gSettingsCache.softwareRendering) { lines = 1; } else if (gScreen->vp_h < 600) { lines = 3; } else { lines = 5; } consoleDisplay(drawConsoleLines, lines); }
void drawFPS(Visual *d) { #define FPS_HSIZE 20 /* draws FPS in upper left corner of Display d */ static int fps_h[FPS_HSIZE]; static int pos = -FPS_HSIZE; static int fps_min = 0; static int fps_avg = 0; char tmp[20]; int diff; rasonly(d); diff = (game2->time.dt > 0) ? game2->time.dt : 1; if(pos < 0) { fps_avg = 1000 / diff; fps_min = 1000 / diff; fps_h[pos + FPS_HSIZE] = 1000 / diff; pos++; } else { fps_h[pos] = 1000 / diff; pos = (pos + 1) % FPS_HSIZE; if(pos % 10 == 0) { int i; int sum = 0; int min = 1000; for(i = 0; i < FPS_HSIZE; i++) { sum += fps_h[i]; if(fps_h[i] < min) min = fps_h[i]; } fps_min = min; fps_avg = sum / FPS_HSIZE; } } sprintf(tmp, "average FPS: %d", fps_avg); glColor4f(1.0, 0.4f, 0.2f, 1.0); drawText(gameFtx, d->vp_w - 180, d->vp_h - 20, 10, tmp); sprintf(tmp, "minimum FPS: %d", fps_min); drawText(gameFtx, d->vp_w - 180, d->vp_h - 35, 10, tmp); sprintf(tmp, "triangles: %d", polycount); drawText(gameFtx, d->vp_w - 180, d->vp_h - 50, 10, tmp); }
void drawFPS(gDisplay *d) { #define FPS_HSIZE 20 /* draws FPS in upper left corner of Display d */ static int fps_h[FPS_HSIZE]; static int pos = -FPS_HSIZE; static int fps_min = 0; static int fps_avg = 0; char tmp[20]; int diff; rasonly(d); diff = (dt > 0) ? dt : 1; if(pos < 0) { fps_avg = 1000 / diff; fps_min = 1000 / diff; fps_h[pos + FPS_HSIZE] = 1000 / diff; pos++; } else { fps_h[pos] = 1000 / diff; pos = (pos + 1) % FPS_HSIZE; if(pos % 10 == 0) { int i; int sum = 0; int min = 1000; for(i = 0; i < FPS_HSIZE; i++) { sum += fps_h[i]; if(fps_h[i] < min) min = fps_h[i]; } fps_min = min; fps_avg = sum / FPS_HSIZE; // printf("minimum FPS: %d - average FPS: %d\n", min, sum / FPS_HSIZE); } } sprintf(tmp, "average FPS: %d", fps_avg); glColor4f(1.0, 0.4, 0.2, 1.0); drawText(d->vp_w - 180, d->vp_h - 20, 10, tmp); sprintf(tmp, "minimum FPS: %d", fps_min); drawText(d->vp_w - 180, d->vp_h - 35, 10, tmp); }
void readTport(int key, int unicode, int x, int y) { printf("entering readPort\n"); if( nbreads == 0 ) { strcpy(game->settings->tport, ""); } switch(key) { case 13://return case SDLK_ESCAPE://escape nbreads=0; restoreCallbacks(); break; case SDLK_BACKSPACE://backspace if( nbreads > 0 ) { nbreads--; game->settings->tport[nbreads]='\0'; } break; default: if( unicode < 0x80 && unicode > 0 ) { sprintf(game->settings->tport, "%s%c", game->settings->tport, unicode); nbreads++; } break; } initMenuCaptions(); #ifdef SOUND playMenuFX(fx_action); #endif drawGuiBackground(); if(!game->settings->softwareRendering) drawGuiLogo(); drawMenu(game->screen); rasonly(game->screen); SystemSwapBuffers(); }
void drawCredits(void) { int time; float x = 10.0f; float y; float h = gScreen->vp_h / 36.0f; int i; float colors[][3] = { { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } }; time = nebu_Time_GetElapsed() - coffset; glClearColor(.0, .0, .0, .0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rasonly(gScreen); for(i = 0; i < time / 250; i++) { glColor3fv(colors[i % 2]); if(credits[i] == NULL) break; y = gScreen->vp_h - 3.0f * h * (i + 1) / 2; drawText(gameFtx, x, y, h, credits[i]); } }
void drawNetwait() { int time; int x, y; int h; float colors[][3] = { { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } }; time = SDL_GetTicks() - coffset; glClearColor(.0, .0, .0, .0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rasonly(game->screen); //Message h = game->screen->vp_h / (24 * 1.5); glColor3fv(colors[1]); x = 50; y = game->screen->vp_h - 1.5 * h * 12; drawText(gameFtx, x, y, h, "Game has already started"); y = game->screen->vp_h - 1.5 * h * 13; drawText(gameFtx, x, y, h, "Try again later...\n"); }
void readNickname(int key, int unicode, int x, int y) { fprintf(stderr, "%c", key); if( nbreads == 0 ) { strcpy(game->settings->nickname, ""); } nbreads++; switch(key) { case 13: nbreads=0; restoreCallbacks(); break; case ';': sprintf(game->settings->nickname, "%s%c", game->settings->nickname, '.'); break; case 304: break; default: if( key > 'A' && key < 'z' ) { sprintf(game->settings->nickname, "%s%c", game->settings->nickname, key); } else { nbreads=0; restoreCallbacks(); } break; } initMenuCaptions(); #ifdef SOUND playMenuFX(fx_action); #endif drawGuiBackground(); if(!game->settings->softwareRendering) drawGuiLogo(); drawMenu(game->screen); rasonly(game->screen); SystemSwapBuffers(); }
void drawCredits() { int time; int x, y; int h; int i; float colors[][3] = { { 1.0, 0.0, 0.0 }, { 1.0, 1.0, 1.0 } }; time = SDL_GetTicks() - coffset; glClearColor(.0, .0, .0, .0); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rasonly(game->screen); h = game->screen->vp_h / (24 * 1.5); for(i = 0; i < time; i++) { glColor3fv(colors[i % 2]); if(credits[i] == NULL) break; x = 10; y = game->screen->vp_h - 1.5 * h * (i + 1); drawText(gameFtx, x, y, h, credits[i]); } }
void drawGuiBackground() { checkGLError("gui background start"); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); rasonly(game->screen); if(game->settings->softwareRendering) { glRasterPos2i(0, 0); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glDrawPixels(game->screen->vp_w, game->screen->vp_h, GL_RGB, GL_UNSIGNED_BYTE, game->screen->pixelGui); } else { glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, game->screen->textures[TEX_GUI]); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glColor3f(1.0, 1.0, 1.0); glBegin(GL_QUADS); glTexCoord2f(0.0, 0.0); glVertex2f(0, 0); glTexCoord2f(1.0, 0.0); glVertex2f(game->screen->vp_w, 0); glTexCoord2f(1.0, .75); glVertex2f(game->screen->vp_w, game->screen->vp_h); glTexCoord2f(0.0, .75); glVertex2f(0, game->screen->vp_h); glEnd(); } }
void drawMenu(Visual *d) { /* draw Menu pCurrent */ int i; int x, y, size, lineheight; int hsize, vsize; int max_label = 0; int max_data = 0; int nEntries; char pMenuName[200]; int iActiveItem; rasonly(d); #define MENU_TEXT_START_X 0.08 #define MENU_TEXT_START_Y 0.40 #define MENU_WIDTH 0.80 #define MENU_HEIGHT 0.40 #define MENU_TEXT_LINEHEIGHT 1.5 x = (int) (d->vp_w * MENU_TEXT_START_X); y = (int) (d->vp_h * MENU_TEXT_START_Y); /* obtain menu name */ scripting_Run("return Menu.current"); scripting_CopyStringResult(pMenuName, 200); /* obtain some information about the active menu */ scripting_RunFormat("return table.getn( Menu.%s.items )", pMenuName); scripting_GetIntegerResult(&nEntries); /* new stuff: calculate menu dimensions */ for(i = 0; i < nEntries; i++) { int len_label = 0; int len_data = 0; scripting_RunFormat("return string.len( Menu[Menu.%s.items[%d]].caption )", pMenuName, i + 1); scripting_GetIntegerResult(&len_label); len_label += 2; /* add ': ' */ scripting_RunFormat("return GetMenuValueWidth( Menu.%s.items[%d] )", pMenuName, i + 1); scripting_GetIntegerResult(&len_data); if(len_label > max_label) max_label = len_label; if(len_data > max_data) max_data = len_data; } /* adjust size so menu fits into MENU_WIDTH/HEIGHT */ hsize = (int) ((float)d->vp_w * MENU_WIDTH / (float) (max_label + max_data)); vsize = (int) ((float)d->vp_h * MENU_HEIGHT / ( (float)nEntries * MENU_TEXT_LINEHEIGHT)); size = (hsize < vsize) ? hsize : vsize; lineheight = (int)( (float) size * MENU_TEXT_LINEHEIGHT); /* printf("%d %d %d %d %d\n", x, y, size, maxw, pCurrent->nEntries); */ /* draw the entries */ scripting_Run("return Menu.active"); scripting_GetIntegerResult(&iActiveItem); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); for(i = 0; i < nEntries; i++) { if(i == iActiveItem - 1) { float color[4]; float active1[4]; float active2[4]; int j; float t; int time = nebu_Time_GetElapsed() & 4095; t = sinf( time * PI / 2048.0 ) / 2.0f + 0.5f; scripting_GetGlobal("menu_item_active1", NULL); scripting_GetFloatArrayResult(active1, 4); scripting_GetGlobal("menu_item_active2", NULL); scripting_GetFloatArrayResult(active2, 4); for(j = 0; j < 4; j++) { color[j] = t * active1[j] + (1 - t) * active2[j]; } glColor4fv(color); /* fprintf(stderr, "%.2f: %.2f %.2f %.2f\n", t, color[0], color[1], color[2]); */ } else { float color[4]; scripting_GetGlobal("menu_item", NULL); scripting_GetFloatArrayResult(color, 4); glColor4fv(color); } { char line_label[100]; char line_data[100]; scripting_RunFormat("return " "GetMenuValueString( Menu.%s.items[%d] )", pMenuName, i + 1); scripting_CopyStringResult(line_data, sizeof(line_data)); if(line_data[0] != 0) scripting_RunFormat("return " "Menu[Menu.%s.items[%d]].caption .. ': '", pMenuName, i + 1); else scripting_RunFormat("return " "Menu[Menu.%s.items[%d]].caption", pMenuName, i + 1); scripting_CopyStringResult(line_label, sizeof(line_label)); drawText(guiFtx, (float)x, (float)y, (float)size, line_label); drawText(guiFtx, (float)x + max_label * size, (float)y, (float)size, line_data); } /* if(i == pCurrent->iHighlight) drawSoftwareHighlight(x, y, size, ((Menu*)*(pCurrent->pEntries + i))->display.szCaption); */ y -= lineheight; } glDisable(GL_BLEND); }