texture.cpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #define countTextures 64
  2. class TextureTestImage : public Image {
  3. private:
  4. TVector<TRef<Surface> > m_vecSurfaces;
  5. public:
  6. TextureTestImage(Engine* pengine) :
  7. m_vecSurfaces(countTextures)
  8. {
  9. TRef<IEngineFont> pfont =
  10. CreateEngineFont(
  11. CreateFont(
  12. 128,
  13. 0, 0, 0,
  14. FW_DONTCARE, FALSE, FALSE, FALSE, ANSI_CHARSET,
  15. OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
  16. DEFAULT_QUALITY, DEFAULT_PITCH | FF_MODERN,
  17. "tahoma"
  18. )
  19. );
  20. char pch[2];
  21. pch[1] = 0;
  22. for (int index = 0; index < countTextures; index++) {
  23. int size = PowerOf2(randomInt(1, 256));
  24. TRef<Surface> psurface =
  25. pengine->CreateSurface(
  26. WinRect(0, 0, size, size),
  27. new PixelFormat(16, 0xf800, 0x07e0, 0x001f, 0x0000)
  28. );
  29. pch[0] = '0' + index;
  30. Color color;
  31. color.SetHSBA(random(0, 1), 1, 0.5);
  32. psurface->FillSurface(color);
  33. psurface->SetFont(pfont);
  34. psurface->DrawString(WinPoint(0, 0), pch);
  35. m_vecSurfaces.Set(index, psurface);
  36. }
  37. }
  38. void DrawTextures(Context* pcontext)
  39. {
  40. float scale = 0.125f;
  41. pcontext->PushState();
  42. pcontext->Scale(scale);
  43. int indexTexture = randomInt(0, countTextures - 1);
  44. ZAssert(indexTexture < countTextures);
  45. int count = randomInt(1, 16);
  46. for (int numtri = 0; numtri < count; numtri++) {
  47. pcontext->DrawImage3D(
  48. m_vecSurfaces[indexTexture],
  49. true,
  50. Point(
  51. 640 * random(-0.25, 0.25) / scale,
  52. 480 * random(-0.25, 0.25) / scale
  53. )
  54. );
  55. }
  56. pcontext->PopState();
  57. }
  58. void BltTextures(Context* pcontext)
  59. {
  60. int indexTexture = randomInt(0, countTextures - 1);
  61. pcontext->DrawImage(
  62. m_vecSurfaces[indexTexture],
  63. true,
  64. Point(
  65. random(0, 640),
  66. random(0, 480)
  67. )
  68. );
  69. }
  70. void DrawText(Context* pcontext)
  71. {
  72. if (randomInt(0, 10) == 0) {
  73. pcontext->DrawString("Hello world");
  74. }
  75. }
  76. void Render(Context* pcontext)
  77. {
  78. int count = randomInt(1, 32);
  79. for (int index = 0; index < count; index++) {
  80. switch(randomInt(0, 2)) {
  81. case 0: DrawTextures(pcontext); break;
  82. case 1: BltTextures(pcontext); break;
  83. case 2: DrawText(pcontext); break;
  84. }
  85. }
  86. }
  87. };
  88. void StartTextureTest()
  89. {
  90. m_pgroupImage->AddImage(new TextureTestImage(GetEngine()));
  91. }