SimpleCommand.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /******************************************************************************
  2. * Spine Runtimes Software License v2.5
  3. *
  4. * Copyright (c) 2013-2016, Esoteric Software
  5. * All rights reserved.
  6. *
  7. * You are granted a perpetual, non-exclusive, non-sublicensable, and
  8. * non-transferable license to use, install, execute, and perform the Spine
  9. * Runtimes software and derivative works solely for personal or internal
  10. * use. Without the written permission of Esoteric Software (see Section 2 of
  11. * the Spine Software License Agreement), you may not (a) modify, translate,
  12. * adapt, or develop new applications using the Spine Runtimes or otherwise
  13. * create derivative works or improvements of the Spine Runtimes or (b) remove,
  14. * delete, alter, or obscure any trademarks or any copyright, trademark, patent,
  15. * or other intellectual property or proprietary rights notices on or in the
  16. * Software, including any copy thereof. Redistributions in binary or source
  17. * form must include this license and terms.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY ESOTERIC SOFTWARE "AS IS" AND ANY EXPRESS OR
  20. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  21. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
  22. * EVENT SHALL ESOTERIC SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  23. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, BUSINESS INTERRUPTION, OR LOSS OF
  25. * USE, DATA, OR PROFITS) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  26. * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  27. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  28. * POSSIBILITY OF SUCH DAMAGE.
  29. *****************************************************************************/
  30. #include "SimpleCommand.h"
  31. USING_NS_CC;
  32. using namespace std;
  33. Scene* SimpleCommand::scene () {
  34. Scene *scene = Scene::create();
  35. scene->addChild(SimpleCommand::create());
  36. return scene;
  37. }
  38. bool SimpleCommand::init () {
  39. if (!Node::init()) return false;
  40. setGLProgramState(GLProgramState::getOrCreateWithGLProgramName(GLProgram::SHADER_NAME_POSITION_TEXTURE_COLOR_NO_MVP));
  41. _texture = _director->getTextureCache()->addImage("sprite.png");
  42. setPosition(100, 100);
  43. return true;
  44. }
  45. void SimpleCommand::draw (Renderer* renderer, const Mat4& transform, uint32_t transformFlags) {
  46. TrianglesCommand::Triangles* triangles = new TrianglesCommand::Triangles();
  47. float x = 0, y = 0;
  48. float w = 80, h = 80;
  49. triangles->vertCount = 4;
  50. triangles->verts = new V3F_C4B_T2F[4];
  51. triangles->verts[0].colors = Color4B::WHITE;
  52. triangles->verts[0].texCoords.u = 0;
  53. triangles->verts[0].texCoords.v = 1;
  54. triangles->verts[0].vertices.x = 0;
  55. triangles->verts[0].vertices.y = 0;
  56. triangles->verts[0].vertices.z = 0;
  57. triangles->verts[1].colors = Color4B::WHITE;
  58. triangles->verts[1].texCoords.u = 0;
  59. triangles->verts[1].texCoords.v = 0;
  60. triangles->verts[1].vertices.x = 0;
  61. triangles->verts[1].vertices.y = h;
  62. triangles->verts[1].vertices.z = 0;
  63. triangles->verts[2].colors = Color4B::WHITE;
  64. triangles->verts[2].texCoords.u = 1;
  65. triangles->verts[2].texCoords.v = 1;
  66. triangles->verts[2].vertices.x = w;
  67. triangles->verts[2].vertices.y = 0;
  68. triangles->verts[2].vertices.z = 0;
  69. triangles->verts[3].colors = Color4B::WHITE;
  70. triangles->verts[3].texCoords.u = 1;
  71. triangles->verts[3].texCoords.v = 0;
  72. triangles->verts[3].vertices.x = w;
  73. triangles->verts[3].vertices.y = h;
  74. triangles->verts[3].vertices.z = 0;
  75. triangles->indexCount = 6;
  76. triangles->indices = new GLushort[6];
  77. triangles->indices[0] = 0;
  78. triangles->indices[1] = 1;
  79. triangles->indices[2] = 2;
  80. triangles->indices[3] = 3;
  81. triangles->indices[4] = 2;
  82. triangles->indices[5] = 1;
  83. TrianglesCommand* trianglesCommand = new TrianglesCommand();
  84. trianglesCommand->init(_globalZOrder, _texture->getName(), getGLProgramState(), BlendFunc::ALPHA_PREMULTIPLIED, *triangles, transform, transformFlags);
  85. renderer->addCommand(trianglesCommand);
  86. }