|
- #include <stdio.h>
- #include <GL/gl.h>
-
- #include "example.h"
- #include "helper.h"
- #include "..\..\libTextSuite.hpp"
-
- #if _WIN64
- static const std::string LibName("..\\..\\..\\libTextSuite-x86_64-win64.dll");
- #elif _WIN32
- static const std::string LibName("..\\..\\..\\libTextSuite-i386-win32.dll");
- #elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__)
- static const std::string LibName("../../../libTextSuite-x86_64-linux.so");
- #elif __linux__ && (__i386 || _X86_)
- static const std::string LibName("../../../libTextSuite-i386-linux.so");
- #else
- # error 'unknown operation system'
- #endif
-
- typedef std::unique_ptr<lts::PostProcessor> PostProcessorPtrU;
-
- std::shared_ptr<lts::Library> library;
- std::shared_ptr<lts::Context> context;
- std::shared_ptr<lts::FontCreator> creator;
- std::shared_ptr<lts::Renderer> renderer;
- std::shared_ptr<lts::Image> pattern;
- std::shared_ptr<lts::Font> font;
-
- std::shared_ptr<lts::PostProcessorList<PostProcessorPtrU>> ppList;
-
- const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
- const wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 };
- const wchar_t CHAR_RANGE_E[] = { 'e', 0 };
-
- const uint8_t PATTER_DATA[] = {
- 0xFF, 0xBF, 0x7F, 0xBF,
- 0xBF, 0xFF, 0xBF, 0x7F,
- 0x7F, 0xBF, 0xFF, 0xBF,
- 0xBF, 0x7F, 0xBF, 0xFF
- };
-
- bool exampleInit()
- {
- library.reset(new lts::Library(LibName));
- context.reset(new lts::Context(*library));
- creator.reset(new lts::FontCreatorGDI(*context));
- renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8));
- ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context));
-
- pattern.reset(new lts::Image(*context));
- pattern->createEmpty(lts::Format::Alpha8, 4, 4);
- memcpy(pattern->getData(), &PATTER_DATA[0], 16);
-
- PostProcessorPtrU ppFillPattern(new lts::PostProcessorFillPattern(
- *context,
- *pattern,
- lts::Position{0, 0},
- lts::ImageModeModulateAll,
- lts::ColorChannelsRGBA));
- ppFillPattern->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_LOREM[0]);
- ppList->push_back(std::move(ppFillPattern));
-
- PostProcessorPtrU ppFillColor(new lts::PostProcessorFillColor(
- *context,
- lts::Color4f{ 0.0, 0.0, 0.5, 1.0 },
- lts::ImageModeReplaceAll,
- lts::ColorChannelsRGB));
- ppFillColor->addChars(lts::CharRangeUsage::Exclude, &CHAR_RANGE_E[0]);
- ppList->push_back(std::move(ppFillColor));
-
- PostProcessorPtrU ppBorder(new lts::PostProcessorBorder(
- *context,
- 3.0,
- 0.5,
- lts::Color4f{ 0.0, 0.5, 0.0, 1.0 },
- true));
- ppBorder->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_E[0]);
- ppList->push_back(std::move(ppBorder));
-
- font = creator->getFontByFile(
- "../Prototype.ttf",
- 40,
- lts::FontStyles(),
- lts::AntiAliasing::Normal);
- font->setPostProcessor(ppList.get());
-
- return true;
- }
-
- bool exampleRender(int width, int height)
- {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- auto textBlock = renderer->beginBlock(10, 10, width-20, height-20, lts::BlockFlags({ lts::BlockFlag::WordWrap }));
- textBlock->setHorzAlign(lts::HorzAlign::Justify);
- textBlock->setFont(font.get());
- textBlock->setColor(lts::Color4f{ 1.0, 1.0, 1.0, 1.0 });
- textBlock->textOutA(TEST_TEXT);
- renderer->endBlock(std::move(textBlock));
-
- glDisable(GL_BLEND);
-
- return true;
- }
-
- void exampleFinish()
- {
- font.reset();
- ppList.reset();
- pattern.reset();
- renderer.reset();
- creator.reset();
- context.reset();
- library.reset();
- }
|