void G2DTestSystemDriver::DrawTextTest () { // Draw a grid of lines so that transparent text background will be visible int w = myG2D->GetWidth (); int h = myG2D->GetHeight (); int i; for (i = 0; i < w; i += 4) { myG2D->DrawLine (float(i), 0.0f, float(i) + 50.0f, float(h), dsteel); myG2D->DrawLine (float(w - i), 0.0f, float(w - i) - 50.0f, float(h), dsteel); } SetFont (fontItalic); WriteCentered (0,-16*7, white, -1, "TEXT DRAWING TEST"); SetFont (fontLarge); WriteCentered (0,-16*5, blue, -1, "This is blue text with transparent background"); WriteCentered (0,-16*4, green, blue, "This is green text on blue background"); WriteCentered (0,-16*3, yellow, gray, "Yellow text on gray background"); WriteCentered (0,-16*2, red, black, "Red text on black background"); WriteCentered (0,-16*1, black, white, "Black text on white background"); SetFont (fontCourier); int sx = 0, sy = h / 2 + 48, sw = w, sh = h / 2 - 48; myG2D->DrawBox (sx, sy, sw, sh, dsteel); const char *text = "Crystal Space rulez"; int tw, th; font->GetDimensions (text, tw, th); size_t cc = strlen (text); // Test text drawing performance for 1/4 seconds int colors [4] = { red, green, blue, yellow }; sx += 20; sw -= 40 + tw; sy += 10; sh -= 20 + th; csRandomGen rng (csGetTicks ()); csTicks start_time = csGetTicks (), delta_time; size_t char_count = 0; do { for (i = 0; i < 2000; i++) { float x = sx + rng.Get () * sw; float y = sy + rng.Get () * sh; myG2D->Write (font, int(x), int(y), colors [rng.Get (4)], black, text); char_count += cc; } myG2D->PerformExtension ("flush"); delta_time = csGetTicks () - start_time; } while (delta_time < 500); float perf = char_count * (1000.0f / delta_time); SetFont (fontLarge); WriteCentered (0, 16*1, green, black, " Performance: %20.1f characters/second ", perf); }
void G2DTestSystemDriver::DrawLinePerf () { SetFont (fontItalic); WriteCentered (0,-16*4, white, -1, "LINE SLOPE AND PERFORMANCE TEST"); int w2 = myG2D->GetWidth () / 2; int colors [4] = { red, green, blue, yellow }; int a; for (a = 0; a < 360; a += 5) { float angle = (a * TWO_PI) / 360.0; float x = w2 + 80 * cos (angle); float y = 100 + 80 * sin (angle); myG2D->DrawLine (w2, 100, x, y, colors [a & 3]); } // Compute the size for the random lines box int sx = 0; int sw = myG2D->GetWidth (); int sy = myG2D->GetHeight () / 2; int sh = sy; myG2D->DrawBox (sx, sy + 16, sw, sh - 16, dsteel); SetFont (fontLarge); WriteCentered (0,-16*2, gray, -1, "Above this text you should see a uniformly hashed circle,"); WriteCentered (0,-16*1, gray, -1, "while below you should see some random lines, and the"); WriteCentered (0, 16*0, gray, -1, "measured line drawing performance in pixels per second."); // Test line drawing performance for 1/4 seconds sx += 20; sw -= 40; sy += 30; sh -= 40; csRandomGen rng (csGetTicks ()); csTicks start_time = csGetTicks (), delta_time; float pix_count = 0; do { for (a = 0; a < 5000; a++) { float x1 = sx + rng.Get () * sw; float y1 = sy + rng.Get () * sh; float x2 = sx + rng.Get () * sw; float y2 = sy + rng.Get () * sh; myG2D->DrawLine (x1, y1, x2, y2, colors [rng.Get (4)]); x2 = csQint (x2 - x1); y2 = csQint (y2 - y1); pix_count += csQsqrt (x2 * x2 + y2 * y2); } myG2D->PerformExtension ("flush"); delta_time = csGetTicks () - start_time; } while (delta_time < 500); pix_count = pix_count * (1000.0 / delta_time); WriteCentered (0, 16*1, green, black, " Performance: %20.1f pixels/second ", pix_count); }