您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 

116 行
3.9 KiB

  1. #include <stdio.h>
  2. #include <GL/gl.h>
  3. #include "example.h"
  4. #include "helper.h"
  5. #include "..\..\libTextSuite.hpp"
  6. #if _WIN64
  7. static const std::string LibName("..\\..\\..\\libTextSuite-x86_64-win64.dll");
  8. #elif _WIN32
  9. static const std::string LibName("..\\..\\..\\libTextSuite-i386-win32.dll");
  10. #elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__)
  11. static const std::string LibName("../../../libTextSuite-x86_64-linux.so");
  12. #elif __linux__ && (__i386 || _X86_)
  13. static const std::string LibName("../../../libTextSuite-i386-linux.so");
  14. #else
  15. # error 'unknown operation system'
  16. #endif
  17. typedef std::unique_ptr<lts::PostProcessor> PostProcessorPtrU;
  18. std::shared_ptr<lts::Library> library;
  19. std::shared_ptr<lts::Context> context;
  20. std::shared_ptr<lts::FontCreator> creator;
  21. std::shared_ptr<lts::Renderer> renderer;
  22. std::shared_ptr<lts::Image> pattern;
  23. std::shared_ptr<lts::Font> font;
  24. std::shared_ptr<lts::PostProcessorList<PostProcessorPtrU>> ppList;
  25. 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.";
  26. const wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 };
  27. const wchar_t CHAR_RANGE_E[] = { 'e', 0 };
  28. const uint8_t PATTER_DATA[] = {
  29. 0xFF, 0xBF, 0x7F, 0xBF,
  30. 0xBF, 0xFF, 0xBF, 0x7F,
  31. 0x7F, 0xBF, 0xFF, 0xBF,
  32. 0xBF, 0x7F, 0xBF, 0xFF
  33. };
  34. bool exampleInit()
  35. {
  36. library.reset(new lts::Library(LibName));
  37. context.reset(new lts::Context(*library));
  38. creator.reset(new lts::FontCreatorGDI(*context));
  39. renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8));
  40. ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context));
  41. pattern.reset(new lts::Image(*context));
  42. pattern->createEmpty(lts::Format::Alpha8, 4, 4);
  43. memcpy(pattern->getData(), &PATTER_DATA[0], 16);
  44. PostProcessorPtrU ppFillPattern(new lts::PostProcessorFillPattern(
  45. *context,
  46. *pattern,
  47. lts::Position{0, 0},
  48. lts::ImageModeModulateAll,
  49. lts::ColorChannelsRGBA));
  50. ppFillPattern->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_LOREM[0]);
  51. ppList->push_back(std::move(ppFillPattern));
  52. PostProcessorPtrU ppFillColor(new lts::PostProcessorFillColor(
  53. *context,
  54. lts::Color4f{ 0.0, 0.0, 0.5, 1.0 },
  55. lts::ImageModeReplaceAll,
  56. lts::ColorChannelsRGB));
  57. ppFillColor->addChars(lts::CharRangeUsage::Exclude, &CHAR_RANGE_E[0]);
  58. ppList->push_back(std::move(ppFillColor));
  59. PostProcessorPtrU ppBorder(new lts::PostProcessorBorder(
  60. *context,
  61. 3.0,
  62. 0.5,
  63. lts::Color4f{ 0.0, 0.5, 0.0, 1.0 },
  64. true));
  65. ppBorder->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_E[0]);
  66. ppList->push_back(std::move(ppBorder));
  67. font = creator->getFontByFile(
  68. "../Prototype.ttf",
  69. 40,
  70. lts::FontStyles(),
  71. lts::AntiAliasing::Normal);
  72. font->setPostProcessor(ppList.get());
  73. return true;
  74. }
  75. bool exampleRender(int width, int height)
  76. {
  77. glEnable(GL_BLEND);
  78. glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  79. auto textBlock = renderer->beginBlock(10, 10, width-20, height-20, lts::BlockFlags({ lts::BlockFlag::WordWrap }));
  80. textBlock->setHorzAlign(lts::HorzAlign::Justify);
  81. textBlock->setFont(font.get());
  82. textBlock->setColor(lts::Color4f{ 1.0, 1.0, 1.0, 1.0 });
  83. textBlock->textOutA(TEST_TEXT);
  84. renderer->endBlock(std::move(textBlock));
  85. glDisable(GL_BLEND);
  86. return true;
  87. }
  88. void exampleFinish()
  89. {
  90. font.reset();
  91. ppList.reset();
  92. pattern.reset();
  93. renderer.reset();
  94. creator.reset();
  95. context.reset();
  96. library.reset();
  97. }