ConsoleGameEngine
80 строк · 1.3 Кб
1#define CGE_IMPL2#include "ConsoleGameEngine.hpp"3
4#include "escapi.h"5
6constexpr int nVariates = 16;7
8class Example : public ConsoleGameEngine9{
10public:11Example()12{13sAppName = L"Example";14sFont = L"Times New Roman";15}16
17SimpleCapParams capture;18int nCameras;19
20private:21union Color22{23int rgb;24uint8_t c[4];25};26
27protected:28bool OnUserCreate() override29{30nCameras = setupESCAPI();31
32if (nCameras == 0)33return false;34
35capture.mWidth = ScreenWidth();36capture.mHeight = ScreenHeight();37capture.mTargetBuf = new int[capture.mWidth * capture.mHeight];38
39if (initCapture(0, &capture) == 0)40return false;41
42return true;43}44
45bool OnUserUpdate(float fDeltaTime) override46{47doCapture(0);48while (isCaptureDone(0) == 0) {}49
50for (int x = 0; x < ScreenWidth(); x++)51for (int y = 0; y < ScreenHeight(); y++)52{53// Get a pixel54
55Color pixel;56pixel.rgb = capture.mTargetBuf[y * ScreenWidth() + x];57
58// Convert to the Command Prompt pixel analogue59
60float fLuminance = (0.2987 * pixel.c[2] + 0.587 * pixel.c[1] + 0.114 * pixel.c[0]) / 255.0 * nVariates;61
62wchar_t c = (int)fLuminance + 'A';63
64// Display the pixel65Draw(x, y, c, FG_WHITE);66}67
68return true;69}70};71
72int main()73{
74Example demo;75
76if (demo.ConstructConsole(256, 240, 4, 4) == rcode::OK)77demo.Run();78
79return 0;80}
81