Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 

127 Zeilen
4.2 KiB

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