example.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. #include "oxygine-framework.h"
  2. #include "test.h"
  3. #include "TestPerf.h"
  4. #include "TestTweens.h"
  5. #include "TestDrag.h"
  6. #include "TestManageRes.h"
  7. #include "TestRender2Texture.h"
  8. #include "TestText.h"
  9. #include "TestTextureFormat.h"
  10. #include "TestTexel2Pixel.h"
  11. #include "TestSliding.h"
  12. #include "TestProgressBar.h"
  13. #include "TestBox9Sprite.h"
  14. #include "TestClipRect.h"
  15. #include "TestUserShader.h"
  16. #include "TestMask.h"
  17. #include "core/STDFileSystem.h"
  18. #ifdef __S3E__
  19. #include "s3eKeyboard.h"
  20. #endif
  21. using namespace oxygine;
  22. spActor _tests;
  23. //it is our resources
  24. //in real project you would have more than one Resources declarations. It is important on mobile devices with limited memory and you would load/unload them
  25. Resources resources;
  26. Resources resourcesUI;
  27. class TestActor: public Test
  28. {
  29. public:
  30. TestActor()
  31. {
  32. _x = 90;//getRoot()->getWidth()/2.0f;
  33. _y = 80;
  34. addButton("tweens", "Tweens");
  35. addButton("text", "Text");
  36. addButton("progress_bar", "Progress Bar");
  37. addButton("drag", "Drag and Drop");
  38. addButton("drag2", "Drag and Drop2");
  39. addButton("perf", "Performance");
  40. addButton("manage_res", "Manage Resources");
  41. addButton("texture_format", "Textures Format");
  42. addButton("r2t", "Render to Texture");
  43. addButton("t2p", "Texel to Pixel");
  44. addButton("sliding", "Sliding Actor");
  45. addButton("box9sprite", "Box9 Sprite");
  46. addButton("cliprect", "ClipRect Actor");
  47. addButton("usershader", "User Shader");
  48. addButton("mask", "Mask");
  49. }
  50. void clicked(string id)
  51. {
  52. setVisible(false);
  53. if (id == "perf")
  54. {
  55. getRoot()->addChild(new PerfTest);
  56. }
  57. if (id == "tweens")
  58. {
  59. getRoot()->addChild(new TweensTest);
  60. }
  61. if (id == "drag")
  62. {
  63. getRoot()->addChild(new DragTest);
  64. }
  65. if (id == "drag2")
  66. {
  67. getRoot()->addChild(new Drag2Test);
  68. }
  69. if (id == "manage_res")
  70. {
  71. getRoot()->addChild(new ManageResTest);
  72. }
  73. if (id == "r2t")
  74. {
  75. getRoot()->addChild(new TestRender2Texture);
  76. }
  77. if (id == "text")
  78. {
  79. getRoot()->addChild(new TestText);
  80. }
  81. if (id == "progress_bar")
  82. {
  83. getRoot()->addChild(new TestProgressBar);
  84. }
  85. if (id == "texture_format")
  86. {
  87. getRoot()->addChild(new TestTextureFormat);
  88. }
  89. if (id == "sliding")
  90. {
  91. getRoot()->addChild(new TestSliding);
  92. }
  93. if (id == "t2p")
  94. {
  95. getRoot()->addChild(new TestTexel2Pixel);
  96. }
  97. if (id == "box9sprite")
  98. {
  99. getRoot()->addChild(new TestBox9Sprite);
  100. }
  101. if (id == "cliprect")
  102. {
  103. getRoot()->addChild(new TestClipRect);
  104. }
  105. if (id == "usershader")
  106. {
  107. getRoot()->addChild(new TestUserShader);
  108. }
  109. if (id == "mask")
  110. {
  111. getRoot()->addChild(new TestMask);
  112. }
  113. }
  114. };
  115. void example_preinit()
  116. {
  117. /**
  118. There are 2 modes of loading and blending/rendering sprites: normal and premultiplied alpha.
  119. You should set it before loading any assets.
  120. Premultiplied mode is more advanced and faster than normal. In this mode RGB pixels of textures premultiplying to alpha when textures are loading and using blend_premultiply_alpha as default Sprites blend option.
  121. Default value is premultiplied = true
  122. http://blog.rarepebble.com/111/premultiplied-alpha-in-opengl/
  123. I set it to false to simplify shaders for UserShaderDemo
  124. */
  125. Renderer::setPremultipliedAlphaRender(false);
  126. }
  127. file::STDFileSystem extfs(true);
  128. void example_init()
  129. {
  130. //mount additional file system with inner path "ext"
  131. //it would be used for searching path in data/ext
  132. extfs.setPath(file::fs().getFullPath("ext").c_str());
  133. file::mount(&extfs);
  134. //load xml file with resources definition
  135. resources.loadXML("xmls/res.xml");
  136. resourcesUI.loadXML("demo/res_ui.xml");
  137. resourcesUI.loadXML("demo/fonts.xml");
  138. spSprite sp = initActor(new Sprite,
  139. arg_resAnim = resourcesUI.getResAnim("logo2"),
  140. arg_input = false,
  141. arg_attachTo = getRoot(),
  142. arg_priority = 10,
  143. arg_alpha = 128
  144. );
  145. sp->setX(getRoot()->getWidth() - sp->getWidth());
  146. sp->setY(getRoot()->getHeight() - sp->getHeight());
  147. _tests = new TestActor;
  148. getRoot()->addChild(_tests);
  149. }
  150. void example_update()
  151. {
  152. }
  153. void example_destroy()
  154. {
  155. _tests->detach();
  156. _tests = 0;
  157. resources.free();
  158. resourcesUI.free();
  159. }