2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-toolkit/dali-toolkit.h>
22 #include "shared/utility.h"
23 #include "shared/view.h"
24 #include "generated/point-mesh-vert.h"
25 #include "generated/point-mesh-frag.h"
31 const char* MATERIAL_SAMPLE(DEMO_IMAGE_DIR "gallery-small-48.jpg");
32 const char* MATERIAL_SAMPLE2(DEMO_IMAGE_DIR "gallery-medium-19.jpg");
34 Geometry CreateGeometry()
43 const unsigned int numSides = 20;
44 Vertex polyhedraVertexData[numSides];
46 float sectorAngle = 2.0f * Math::PI / (float)numSides;
48 for(unsigned int i = 0; i < numSides; ++i)
50 polyhedraVertexData[i].position.x = sinf(angle) * 0.5f;
51 polyhedraVertexData[i].position.y = cosf(angle) * 0.5f;
52 polyhedraVertexData[i].hue = angle / (2.0f * Math::PI);
56 Property::Map polyhedraVertexFormat;
57 polyhedraVertexFormat["aPosition"] = Property::VECTOR2;
58 polyhedraVertexFormat["aHue"] = Property::FLOAT;
59 VertexBuffer polyhedraVertices = VertexBuffer::New(polyhedraVertexFormat);
60 polyhedraVertices.SetData(polyhedraVertexData, numSides);
62 // Create the geometry object
63 Geometry polyhedraGeometry = Geometry::New();
64 polyhedraGeometry.AddVertexBuffer(polyhedraVertices);
65 polyhedraGeometry.SetType(Geometry::POINTS);
67 return polyhedraGeometry;
70 } // anonymous namespace
72 // This example shows how to use a simple mesh
74 class ExampleController : public ConnectionTracker
78 * The example controller constructor.
79 * @param[in] application The application instance
81 ExampleController(Application& application)
82 : mApplication(application)
84 // Connect to the Application's Init signal
85 mApplication.InitSignal().Connect(this, &ExampleController::Create);
89 * The example controller destructor
93 // Nothing to do here;
97 * Invoked upon creation of application
98 * @param[in] application The application instance
100 void Create(Application& application)
102 Window window = application.GetWindow();
103 window.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent);
105 mWindowSize = window.GetSize();
107 // The Init signal is received once (only) during the Application lifetime
109 Texture texture0 = DemoHelper::LoadTexture(MATERIAL_SAMPLE);
110 Texture texture1 = DemoHelper::LoadTexture(MATERIAL_SAMPLE2);
112 Shader shader = Shader::New(SHADER_POINT_MESH_VERT, SHADER_POINT_MESH_FRAG);
114 TextureSet textureSet = TextureSet::New();
115 textureSet.SetTexture(0u, texture0);
116 textureSet.SetTexture(1u, texture1);
118 Geometry geometry = CreateGeometry();
120 mRenderer = Renderer::New(geometry, shader);
121 mRenderer.SetTextures(textureSet);
123 mMeshActor = Actor::New();
124 mMeshActor.AddRenderer(mRenderer);
125 mMeshActor.SetProperty(Actor::Property::SIZE, Vector2(400, 400));
127 mMeshActor.RegisterProperty("uFadeColor", Color::GREEN);
129 mRenderer.RegisterProperty("uFadeColor", Color::MAGENTA);
130 mRenderer.RegisterProperty("uPointSize", 80.0f);
131 mRenderer.SetProperty(Renderer::Property::DEPTH_INDEX, 0);
133 mMeshActor.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
134 mMeshActor.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
135 window.Add(mMeshActor);
137 Animation animation = Animation::New(15);
138 KeyFrames keyFrames = KeyFrames::New();
139 keyFrames.Add(0.0f, Vector4::ZERO);
140 keyFrames.Add(1.0f, Vector4(1.0f, 0.0f, 1.0f, 1.0f));
142 animation.AnimateBy(Property(mMeshActor, Actor::Property::ORIENTATION), Quaternion(Degree(360), Vector3::ZAXIS));
144 animation.SetLooping(true);
147 window.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));
151 * Invoked whenever the quit button is clicked
152 * @param[in] button the quit button
154 bool OnQuitButtonClicked(Toolkit::Button button)
156 // quit the application
161 void OnKeyEvent(const KeyEvent& event)
163 if(event.GetState() == KeyEvent::DOWN)
165 if(IsKey(event, Dali::DALI_KEY_ESCAPE) || IsKey(event, Dali::DALI_KEY_BACK))
173 Application& mApplication; ///< Application instance
174 Vector3 mWindowSize; ///< The size of the window
180 Timer mChangeImageTimer;
183 int DALI_EXPORT_API main(int argc, char** argv)
185 Application application = Application::New(&argc, &argv);
186 ExampleController test(application);
187 application.MainLoop();