example.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 "TestUserShader2.h"
  17. #include "TestMask.h"
  18. #include "TestPolygon.h"
  19. #include "TestInputText.h"
  20. #include "TestHttp.h"
  21. #include "TestAlphaHitTest.h"
  22. #include "TestCounter.h"
  23. #include "TestTweenText.h"
  24. #include "TestTweenShine.h"
  25. #include "TestTouches.h"
  26. #include "TestColorFont.h"
  27. #include "TestTweenAlphaFade.h"
  28. #ifdef __S3E__
  29. #include "s3eKeyboard.h"
  30. #endif
  31. using namespace oxygine;
  32. //This contains our resources
  33. //In a real project you would have more than one Resources declaration.
  34. //It is important on mobile devices with limited memory and you would load/unload them
  35. Resources resources;
  36. //#define MULTIWINDOW 1
  37. #if MULTIWINDOW
  38. spStage stage2;
  39. #endif
  40. class TestActor: public Test
  41. {
  42. public:
  43. TestActor()
  44. {
  45. _x = 90;//getStage()->getWidth()/2.0f;
  46. _y = 80;
  47. addButton("tweens", "Tweens");
  48. addButton("text", "Text");
  49. addButton("progress_bar", "Progress Bar");
  50. addButton("drag", "Drag and Drop with Test Intersections");
  51. addButton("drag2", "Drag and Drop2");
  52. addButton("hittest", "Alpha Hit Test");
  53. addButton("perf", "Performance");
  54. addButton("manage_res", "Manage Resources");
  55. addButton("texture_format", "Textures Format");
  56. addButton("r2t", "Render to Texture");
  57. addButton("t2p", "Texel to Pixel");
  58. addButton("edges", "Edges");
  59. addButton("touches", "Touches");
  60. addButton("sliding", "Sliding Actor");
  61. addButton("box9sprite", "Box9 Sprite");
  62. addButton("cliprect", "ClipRect Actor");
  63. addButton("usershader", "User Shader");
  64. addButton("usershader2", "User Shader2");
  65. addButton("multicolorfont", "Outer Font Color");
  66. addButton("mask", "Mask");
  67. addButton("polygon", "Polygon");
  68. addButton("inputtext", "Input Text");
  69. addButton("openbrowser", "Open Browser");
  70. addButton("http", "Http requests");
  71. addButton("tweenfade", "Tween Alpha Fade");
  72. _color = Color::Red;
  73. _txtColor = Color::White;
  74. _y = 5;
  75. _x += 200;
  76. addButton("counter", "Counter");
  77. addButton("tweentext", "Tween Text");
  78. addButton("tweenshine", "Tween Shine");
  79. }
  80. void showTest(spActor actor)
  81. {
  82. spStage stage = getStage();
  83. #if MULTIWINDOW
  84. stage = stage2;
  85. #else
  86. setVisible(false);
  87. #endif
  88. stage->addChild(actor);
  89. }
  90. void clicked(string id)
  91. {
  92. if (id == "perf") showTest(new PerfTest);
  93. if (id == "tweens") showTest(new TweensTest);
  94. if (id == "drag") showTest(new DragTest);
  95. if (id == "drag2") showTest(new Drag2Test);
  96. if (id == "hittest") showTest(new TestAlphaHitTest);
  97. if (id == "manage_res") showTest(new ManageResTest);
  98. if (id == "r2t") showTest(new TestRender2Texture);
  99. if (id == "text") showTest(new TestText);
  100. if (id == "progress_bar") showTest(new TestProgressBar);
  101. if (id == "texture_format") showTest(new TestTextureFormat);
  102. if (id == "sliding") showTest(new TestSliding);
  103. if (id == "t2p") showTest(new TestTexel2Pixel);
  104. if (id == "touches") showTest(new TestTouches);
  105. if (id == "box9sprite") showTest(new TestBox9Sprite);
  106. if (id == "cliprect") showTest(new TestClipRect);
  107. if (id == "usershader") showTest(new TestUserShader);
  108. if (id == "usershader2") showTest(new TestUserShader2);
  109. if (id == "mask") showTest(new TestMask);
  110. if (id == "polygon") showTest(new TestPolygon);
  111. if (id == "inputtext") showTest(new TestInputText);
  112. if (id == "http") showTest(new TestHttp);
  113. if (id == "counter") showTest(new TestCounter);
  114. if (id == "tweentext") showTest(new TestTweenText);
  115. if (id == "tweenshine") showTest(new TestTweenShine);
  116. if (id == "multicolorfont") showTest(new TestColorFont);
  117. if (id == "tweenfade") showTest(new TestTweenAlphaFade);
  118. if (id == "openbrowser")
  119. {
  120. core::execute("http://oxygine.org/");
  121. setVisible(true);
  122. }
  123. }
  124. };
  125. void example_preinit()
  126. {
  127. /**
  128. There are 2 modes of loading and blending/rendering sprites: normal and pre-multiplied alpha.
  129. You should set it before loading any assets.
  130. Pre-multiplied mode is more advanced and faster than normal. In this mode RGB pixels of textures pre-multiplying to alpha when textures are loading and using blend_premultiply_alpha as default Sprites blend option.
  131. Default value is pre-multiplied = true
  132. http://blog.rarepebble.com/111/premultiplied-alpha-in-opengl/
  133. I set it to false to simplify shaders for UserShaderDemo
  134. */
  135. //Renderer::setPremultipliedAlphaRender(false);
  136. }
  137. void example_init()
  138. {
  139. //Load resources in xml file
  140. resources.loadXML("xmls/res.xml");
  141. Test::init();
  142. Test::instance = new TestActor;
  143. getStage()->addChild(Test::instance);
  144. //Initialize http requests
  145. HttpRequestTask::init();
  146. #if MULTIWINDOW
  147. SDL_Window* window2 = SDL_CreateWindow("Second Oxygine Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, getStage()->getWidth(), getStage()->getHeight(), SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  148. stage2 = new Stage(false);
  149. stage2->setSize(getStage()->getSize());
  150. stage2->associateWithWindow(window2);
  151. #endif
  152. }
  153. void example_update()
  154. {
  155. #if MULTIWINDOW
  156. stage2->update();
  157. SDL_Window* wnd = stage2->getAssociatedWindow();
  158. if (core::beginRendering(wnd))
  159. {
  160. Color clearColor(32, 32, 32, 255);
  161. Rect viewport(Point(0, 0), core::getDisplaySize());
  162. //render all actors. Actor::render would be called also for all children
  163. stage2->render(clearColor, viewport);
  164. core::swapDisplayBuffers(wnd);
  165. }
  166. #endif
  167. }
  168. void example_destroy()
  169. {
  170. resources.free();
  171. Test::free();
  172. HttpRequestTask::release();
  173. }