textrenderer.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "Crown.h"
  2. #include <cstdlib>
  3. #include <GL/glew.h>
  4. using namespace Crown;
  5. class WndCtrl: public KeyboardListener
  6. {
  7. public:
  8. WndCtrl()
  9. {
  10. GetDevice()->GetInputManager()->RegisterKeyboardListener(this);
  11. }
  12. virtual void KeyReleased(const KeyboardEvent& event)
  13. {
  14. if (event.key == KC_ESCAPE)
  15. {
  16. GetDevice()->StopRunning();
  17. }
  18. }
  19. };
  20. class MainScene
  21. {
  22. public:
  23. MainScene(uint windowWidth, uint windowHeight)
  24. {
  25. }
  26. virtual ~MainScene()
  27. {
  28. }
  29. virtual void OnLoad()
  30. {
  31. mOrtho.BuildProjectionOrtho2dRH(800, 600, 10, -10);
  32. Crown::Renderer* renderer = Crown::GetDevice()->GetRenderer();
  33. renderer->SetClearColor(Crown::Color4(0.8f, 0.8f, 0.8f, 0.8f));
  34. // Load and select the font
  35. mLargeFont = GetFontManager()->Load("res/arial.tga");
  36. renderer->_SetLighting(false);
  37. }
  38. virtual void RenderScene()
  39. {
  40. Scene::RenderScene();
  41. Renderer* renderer = GetDevice()->GetRenderer();
  42. Scene::RenderScene();
  43. renderer->SetMatrix(MT_PROJECTION, mOrtho);
  44. //text.SetFont(mLargeFont);
  45. //text.SetColor(Color4::SILVER);
  46. text.Draw("abcdef ABCDEF .@#^?=()&%!", 100, 90, mLargeFont);
  47. text.Draw("Hello world! This is the new TextRenderer.\n", 100, 120, mLargeFont);
  48. text.Draw("It supports a lot of new features!", 100, 150, mLargeFont);
  49. }
  50. private:
  51. Mat4 mOrtho;
  52. Crown::Font* mLargeFont;
  53. Crown::Font* mSmallFont;
  54. Crown::Font* mTimesFont;
  55. TextRenderer text;
  56. };
  57. int main(int argc, char** argv)
  58. {
  59. int wndW = 800;
  60. int wndH = 600;
  61. if (argc == 3)
  62. {
  63. wndW = atoi(argv[1]);
  64. wndH = atoi(argv[2]);
  65. }
  66. Device* mDevice = GetDevice();
  67. if (!mDevice->Init(wndW, wndH, 32, false))
  68. {
  69. return 0;
  70. }
  71. WndCtrl ctrl;
  72. MainScene* mainScene = new MainScene(wndW, wndH);
  73. GetDevice()->GetSceneManager()->SelectNextScene(mainScene);
  74. mDevice->GetMainWindow()->SetTitle("Crown Engine v0.1 - TextRenderer Test");
  75. while (mDevice->IsRunning())
  76. {
  77. mDevice->Frame();
  78. }
  79. mDevice->Shutdown();
  80. return 0;
  81. }