1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| #include <graphics.h> #include <string>
#define WINDOW_WDITH 640 #define WINDOW_HEIGHT 260
size_t idx_char = 0;
void RenderNormalText() { #ifdef UNICODE static const std::wstring TEXT_LIST[3] = #else static const std::string TEXT_LIST[3] = #endif { _T("Wake up, Neo... "), _T("The Matrix has you... "), _T("Follow the white rabbit. "), }; static int idx_text = 0; for (int i = 0; i <= idx_text; i++) { if (idx_char >= TEXT_LIST[i].length()) idx_text++, idx_char = 0; if (idx_text >= 3) idx_text = 2, idx_char = TEXT_LIST[2].length(); outtextxy(40, 40 + i * 60, i != idx_text ? TEXT_LIST[i].c_str() : TEXT_LIST[i].substr(0, idx_char).c_str()); } }
int main(int argc, char** argv) { initgraph(WINDOW_WDITH, WINDOW_HEIGHT, EW_SHOWCONSOLE); SetWindowText(GetHWnd(), _T("EasyX Bloom Text"));
BeginBatchDraw();
while (true) { cleardevice();
settextstyle(30, 0, L"Fusion Pixel 12px Monospaced latin Regular"); settextcolor(GREEN); setbkmode(TRANSPARENT);
static const size_t TIMES = 2; static const float THRESHOLD = 0.15f; static const size_t LEN_PIX = WINDOW_WDITH * WINDOW_HEIGHT; DWORD* tmp_color_buffer = new DWORD[LEN_PIX];
RenderNormalText();
DWORD* screen_color_buffer = GetImageBuffer(NULL); for (int y = 0; y < WINDOW_HEIGHT; y++) { for (int x = 0; x < WINDOW_WDITH; x++) { DWORD r, g, b; int idx = y * WINDOW_WDITH + x; r = (screen_color_buffer[idx] & 0x00ff0000) >> 16; g = (screen_color_buffer[idx] & 0x0000ff00) >> 8; b = screen_color_buffer[idx] & 0x000000ff; float brightness = (r / 255.0f) * 0.2126f + (g / 255.0f) * 0.7152f + (b / 255.0f) * 0.0722f; tmp_color_buffer[idx] = brightness > THRESHOLD ? screen_color_buffer[idx] : BGR(RGB(0, 0, 0)); } }
for (size_t i = 0; i < TIMES; i++) { static const float GAUSSIAN_KERNEL[5][5] = { 1.0f / 256.0f, 4.0f / 256.0f, 6.0f / 256.0f, 4.0f / 256.0f, 1.0f / 256.0f, 4.0f / 256.0f, 16.0f / 256.0f, 24.0f / 256.0f, 16.0f / 256.0f, 4.0f / 256.0f, 6.0f / 256.0f, 24.0f / 256.0f, 36.0f / 256.0f, 24.0f / 256.0f, 6.0f / 256.0f, 4.0f / 256.0f, 16.0f / 256.0f, 24.0f / 256.0f, 16.0f / 256.0f, 4.0f / 256.0f, 1.0f / 256.0f, 4.0f / 256.0f, 6.0f / 256.0f, 4.0f / 256.0f, 1.0f / 256.0f, }; for (int y = 0; y < WINDOW_HEIGHT; y++) { for (int x = 0; x < WINDOW_WDITH; x++) { int dst_idx = y * WINDOW_WDITH + x; float dst_r = 0, dst_g = 0, dst_b = 0; for (int i = -2; i <= 2; i++) { for (int j = -2; j <= 2; j++) { if (x + j < 0 || x + j >= WINDOW_WDITH || y + i < 0 || y + i >= WINDOW_HEIGHT) continue;
DWORD src_r, src_g, src_b; int src_idx = (y + i) * WINDOW_WDITH + (x + j); src_r = (tmp_color_buffer[src_idx] & 0x00ff0000) >> 16; src_g = (tmp_color_buffer[src_idx] & 0x0000ff00) >> 8; src_b = tmp_color_buffer[src_idx] & 0x000000ff; dst_r += src_r * GAUSSIAN_KERNEL[i + 2][j + 2]; dst_g += src_g * GAUSSIAN_KERNEL[i + 2][j + 2]; dst_b += src_b * GAUSSIAN_KERNEL[i + 2][j + 2]; } } screen_color_buffer[dst_idx] = BGR(RGB(dst_r, dst_g, dst_b)); } } memcpy(tmp_color_buffer, screen_color_buffer, LEN_PIX * sizeof(DWORD)); }
delete[] tmp_color_buffer; tmp_color_buffer = nullptr;
RenderNormalText();
static int line_y = 0; static IMAGE img_screen; static const int OFFSET_X = 10; static const int LINE_THICKNESS = 5; line_y = (line_y + 2) % (WINDOW_HEIGHT - LINE_THICKNESS); getimage(&img_screen, 0, 0, WINDOW_WDITH, WINDOW_HEIGHT); cleardevice(); putimage(0, 0, WINDOW_WDITH, line_y, &img_screen, 0, 0); putimage(OFFSET_X, line_y, WINDOW_WDITH, LINE_THICKNESS, &img_screen, 0, line_y); putimage(0, line_y + LINE_THICKNESS, WINDOW_WDITH, WINDOW_WDITH - line_y - LINE_THICKNESS, &img_screen, 0, line_y + LINE_THICKNESS);
static int counter = 0; if (!(counter = (counter++) % 5)) idx_char++;
FlushBatchDraw(); }
EndBatchDraw();
return 0; }
|