Commit a0e18d232dc3a8a590c0bfd302f4e5787a6159c6
Committed by
Paul Wisbey
1 parent
a523d825
Added Rendering tutorials
- Drawing line - Drawing triangle - Drawing colored cube - Drawing textured cube Change-Id: Ief3c47871b0f06ba764fa86a260ad8561c78acd3
Showing
16 changed files
with
1077 additions
and
1 deletions
examples-reel/dali-examples-reel.cpp
| ... | ... | @@ -61,6 +61,10 @@ int DALI_EXPORT_API main(int argc, char **argv) |
| 61 | 61 | demo.AddExample(Example("popup.example", DALI_DEMO_STR_TITLE_POPUP)); |
| 62 | 62 | demo.AddExample(Example("primitive-shapes.example", DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES)); |
| 63 | 63 | demo.AddExample(Example("progress-bar.example", DALI_DEMO_STR_TITLE_PROGRESS_BAR)); |
| 64 | + demo.AddExample(Example("rendering-line.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE)); | |
| 65 | + demo.AddExample(Example("rendering-triangle.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE)); | |
| 66 | + demo.AddExample(Example("rendering-cube.example", DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE)); | |
| 67 | + demo.AddExample(Example("rendering-textured-cube.example", DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE)); | |
| 64 | 68 | demo.AddExample(Example("scroll-view.example", DALI_DEMO_STR_TITLE_SCROLL_VIEW)); |
| 65 | 69 | demo.AddExample(Example("size-negotiation.example", DALI_DEMO_STR_TITLE_NEGOTIATE_SIZE)); |
| 66 | 70 | demo.AddExample(Example("styling.example", DALI_DEMO_STR_TITLE_STYLING)); |
| ... | ... | @@ -70,7 +74,7 @@ int DALI_EXPORT_API main(int argc, char **argv) |
| 70 | 74 | demo.AddExample(Example("text-label-multi-language.example", DALI_DEMO_STR_TITLE_TEXT_LABEL_MULTI_LANGUAGE)); |
| 71 | 75 | demo.AddExample(Example("text-label-emojis.example", DALI_DEMO_STR_TITLE_EMOJI_TEXT)); |
| 72 | 76 | demo.AddExample(Example("text-scrolling.example", DALI_DEMO_STR_TITLE_TEXT_SCROLLING)); |
| 73 | - demo.AddExample(Example("textured-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH)); | |
| 77 | + demo.AddExample(Example("texturedss-mesh.example", DALI_DEMO_STR_TITLE_TEXTURED_MESH)); | |
| 74 | 78 | demo.AddExample(Example("tilt.example", DALI_DEMO_STR_TITLE_TILT_SENSOR)); |
| 75 | 79 | demo.AddExample(Example("tooltip.example", DALI_DEMO_STR_TITLE_TOOLTIP)); |
| 76 | 80 | demo.AddExample(Example("transitions.example", DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS)); | ... | ... |
examples/rendering-cube/rendering-cube.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 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 | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 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. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include <dali/dali.h> | |
| 19 | +#include <dali-toolkit/dali-toolkit.h> | |
| 20 | + | |
| 21 | +using namespace Dali; | |
| 22 | +using namespace Toolkit; | |
| 23 | + | |
| 24 | +namespace | |
| 25 | +{ | |
| 26 | + | |
| 27 | +/* | |
| 28 | + * Vertex shader | |
| 29 | + */ | |
| 30 | +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 31 | +attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 32 | +attribute mediump vec3 aColor;\n // DALi shader builtin | |
| 33 | +uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 34 | +uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 35 | +\n | |
| 36 | +varying mediump vec4 vColor;\n | |
| 37 | +\n | |
| 38 | +void main()\n | |
| 39 | +{\n | |
| 40 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 41 | + vertexPosition.xyz *= uSize;\n | |
| 42 | + vColor = vec4( aColor, 1.0 );\n | |
| 43 | + gl_Position = uMvpMatrix * vertexPosition;\n | |
| 44 | +}\n | |
| 45 | +); | |
| 46 | + | |
| 47 | +/* | |
| 48 | + * Fragment shader | |
| 49 | + */ | |
| 50 | +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 51 | +varying mediump vec4 vColor;\n | |
| 52 | +\n | |
| 53 | +void main()\n | |
| 54 | +{\n | |
| 55 | + gl_FragColor = vColor;\n | |
| 56 | +}\n | |
| 57 | +); | |
| 58 | + | |
| 59 | +} | |
| 60 | + | |
| 61 | +// This example shows how to create a cube with colors on each side | |
| 62 | +// | |
| 63 | +class DrawCubeController : public ConnectionTracker | |
| 64 | +{ | |
| 65 | +public: | |
| 66 | + | |
| 67 | + DrawCubeController( Application& application ) | |
| 68 | + : mApplication( application ) | |
| 69 | + { | |
| 70 | + // Connect to the Application's Init signal | |
| 71 | + mApplication.InitSignal().Connect( this, &DrawCubeController::Create ); | |
| 72 | + } | |
| 73 | + | |
| 74 | + ~DrawCubeController() | |
| 75 | + { | |
| 76 | + // Nothing to do here; | |
| 77 | + } | |
| 78 | + | |
| 79 | + // The Init signal is received once (only) during the Application lifetime | |
| 80 | + void Create( Application& application ) | |
| 81 | + { | |
| 82 | + // Get a handle to the stage | |
| 83 | + Stage stage = Stage::GetCurrent(); | |
| 84 | + stage.SetBackgroundColor( Color::WHITE ); | |
| 85 | + | |
| 86 | + // Step 1. Create shader | |
| 87 | + CreateCubeShader(); | |
| 88 | + | |
| 89 | + // Step 2. Prepare geometry | |
| 90 | + CreateCubeGeometry(); | |
| 91 | + | |
| 92 | + // Step 3. Create a renderer | |
| 93 | + CreateRenderer(); | |
| 94 | + | |
| 95 | + // Step 4. Create an Actor | |
| 96 | + CreateActor(); | |
| 97 | + | |
| 98 | + // Step 5. Play animation to rotate the cube | |
| 99 | + PlayAnimation(); | |
| 100 | + | |
| 101 | + // Respond to a click anywhere on the stage | |
| 102 | + stage.GetRootLayer().TouchSignal().Connect( this, &DrawCubeController::OnTouch ); | |
| 103 | + } | |
| 104 | + | |
| 105 | + bool OnTouch( Actor actor, const TouchData& touch ) | |
| 106 | + { | |
| 107 | + // quit the application | |
| 108 | + mApplication.Quit(); | |
| 109 | + return true; | |
| 110 | + } | |
| 111 | + | |
| 112 | + /** | |
| 113 | + * This function creates a cube geometry including texture coordinates. | |
| 114 | + * Also it demonstrates using the indexed draw feature by setting an index array. | |
| 115 | + */ | |
| 116 | + void CreateCubeGeometry() | |
| 117 | + { | |
| 118 | + struct Vertex | |
| 119 | + { | |
| 120 | + Vector3 aPosition; | |
| 121 | + Vector3 aColor; | |
| 122 | + }; | |
| 123 | + | |
| 124 | + const Vector3 COLOR0( 1.0f, 1.0f, 0.0f ); | |
| 125 | + const Vector3 COLOR1( 0.0f, 1.0f, 1.0f ); | |
| 126 | + const Vector3 COLOR2( 1.0f, 0.0f, 1.0f ); | |
| 127 | + const Vector3 COLOR3( 0.0f, 1.0f, 0.0f ); | |
| 128 | + const Vector3 COLOR4( 0.0f, 0.0f, 1.0f ); | |
| 129 | + const Vector3 COLOR5( 1.0f, 0.0f, 0.0f ); | |
| 130 | + | |
| 131 | + Vertex vertices[] = { | |
| 132 | + { Vector3( 1.0f,-1.0f,-1.0f ), COLOR5 }, | |
| 133 | + { Vector3( -1.0f, 1.0f,-1.0f ), COLOR5 }, | |
| 134 | + { Vector3( 1.0f, 1.0f,-1.0f ), COLOR5 }, | |
| 135 | + { Vector3( -1.0f, 1.0f, 1.0f ), COLOR3 }, | |
| 136 | + { Vector3( 1.0f,-1.0f, 1.0f ), COLOR3 }, | |
| 137 | + { Vector3( 1.0f, 1.0f, 1.0f ), COLOR3 }, | |
| 138 | + { Vector3( 1.0f, 1.0f, 1.0f ), COLOR4 }, | |
| 139 | + { Vector3( 1.0f,-1.0f,-1.0f ), COLOR4 }, | |
| 140 | + { Vector3( 1.0f, 1.0f,-1.0f ), COLOR4 }, | |
| 141 | + { Vector3( 1.0f,-1.0f, 1.0f ), COLOR1 }, | |
| 142 | + { Vector3( -1.0f,-1.0f,-1.0f ), COLOR1 }, | |
| 143 | + { Vector3( 1.0f,-1.0f,-1.0f ), COLOR1 }, | |
| 144 | + { Vector3( -1.0f,-1.0f,-1.0f ), COLOR0 }, | |
| 145 | + { Vector3( -1.0f, 1.0f, 1.0f ), COLOR0 }, | |
| 146 | + { Vector3( -1.0f, 1.0f,-1.0f ), COLOR0 }, | |
| 147 | + { Vector3( 1.0f, 1.0f,-1.0f ), COLOR2 }, | |
| 148 | + { Vector3( -1.0f, 1.0f, 1.0f ), COLOR2 }, | |
| 149 | + { Vector3( 1.0f, 1.0f, 1.0f ), COLOR2 }, | |
| 150 | + { Vector3( 1.0f,-1.0f,-1.0f ), COLOR5 }, | |
| 151 | + { Vector3( -1.0f,-1.0f,-1.0f ), COLOR5 }, | |
| 152 | + { Vector3( -1.0f, 1.0f,-1.0f ), COLOR5 }, | |
| 153 | + { Vector3( -1.0f, 1.0f, 1.0f ), COLOR3 }, | |
| 154 | + { Vector3( -1.0f,-1.0f, 1.0f ), COLOR3 }, | |
| 155 | + { Vector3( 1.0f,-1.0f, 1.0f ), COLOR3 }, | |
| 156 | + { Vector3( 1.0f, 1.0f, 1.0f ), COLOR4 }, | |
| 157 | + { Vector3( 1.0f,-1.0f, 1.0f ), COLOR4 }, | |
| 158 | + { Vector3( 1.0f,-1.0f,-1.0f ), COLOR4 }, | |
| 159 | + { Vector3( 1.0f,-1.0f, 1.0f ), COLOR1 }, | |
| 160 | + { Vector3( -1.0f,-1.0f, 1.0f ), COLOR1 }, | |
| 161 | + { Vector3( -1.0f,-1.0f,-1.0f ), COLOR1 }, | |
| 162 | + { Vector3( -1.0f,-1.0f,-1.0f ), COLOR0 }, | |
| 163 | + { Vector3( -1.0f,-1.0f, 1.0f ), COLOR0 }, | |
| 164 | + { Vector3( -1.0f, 1.0f, 1.0f ), COLOR0 }, | |
| 165 | + { Vector3( 1.0f, 1.0f,-1.0f ), COLOR2 }, | |
| 166 | + { Vector3( -1.0f, 1.0f,-1.0f ), COLOR2 }, | |
| 167 | + { Vector3( -1.0f, 1.0f, 1.0f ), COLOR2 }, | |
| 168 | + }; | |
| 169 | + | |
| 170 | + PropertyBuffer vertexBuffer = PropertyBuffer::New( Property::Map() | |
| 171 | + .Add( "aPosition", Property::VECTOR3 ) | |
| 172 | + .Add( "aColor", Property::VECTOR3 ) ); | |
| 173 | + vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vertex) ); | |
| 174 | + | |
| 175 | + // create indices | |
| 176 | + const unsigned short INDEX_CUBE[] = { | |
| 177 | + 2, 1, 0, | |
| 178 | + 5, 4, 3, | |
| 179 | + 8, 7, 6, | |
| 180 | + 11, 10, 9, | |
| 181 | + 14, 13, 12, | |
| 182 | + 17, 16, 15, | |
| 183 | + 20, 19, 18, | |
| 184 | + 23, 22, 21, | |
| 185 | + 26, 25, 24, | |
| 186 | + 29, 28, 27, | |
| 187 | + 32, 31, 30, | |
| 188 | + 35, 34, 33 | |
| 189 | + }; | |
| 190 | + mGeometry = Geometry::New(); | |
| 191 | + mGeometry.AddVertexBuffer( vertexBuffer ); | |
| 192 | + mGeometry.SetIndexBuffer( INDEX_CUBE, | |
| 193 | + sizeof(INDEX_CUBE)/sizeof(INDEX_CUBE[0]) | |
| 194 | + ); | |
| 195 | + mGeometry.SetType( Geometry::TRIANGLES ); | |
| 196 | + } | |
| 197 | + | |
| 198 | + /** | |
| 199 | + * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 200 | + * | |
| 201 | + * Shaders are very basic and all they do is transforming vertices and interpolating | |
| 202 | + * input per-vertex color. | |
| 203 | + */ | |
| 204 | + void CreateCubeShader() | |
| 205 | + { | |
| 206 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | |
| 207 | + } | |
| 208 | + | |
| 209 | + /** | |
| 210 | + * Function creates renderer. It turns on depth test and depth write. | |
| 211 | + */ | |
| 212 | + void CreateRenderer() | |
| 213 | + { | |
| 214 | + mRenderer = Renderer::New( mGeometry, mShader ); | |
| 215 | + | |
| 216 | + // Face culling is enabled to hide the backwards facing sides of the cube | |
| 217 | + // This is sufficient to render a single object; for more complex scenes depth-testing might be required | |
| 218 | + mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); | |
| 219 | + } | |
| 220 | + | |
| 221 | + /** | |
| 222 | + * Creates new actor and attaches renderer. | |
| 223 | + */ | |
| 224 | + void CreateActor() | |
| 225 | + { | |
| 226 | + Stage stage = Stage::GetCurrent(); | |
| 227 | + | |
| 228 | + float quarterStageWidth = stage.GetSize().x * 0.25f; | |
| 229 | + mActor = Actor::New(); | |
| 230 | + mActor.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 231 | + mActor.SetParentOrigin( ParentOrigin::CENTER ); | |
| 232 | + mActor.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); | |
| 233 | + mActor.SetSize( Vector3( quarterStageWidth, quarterStageWidth, quarterStageWidth ) ); | |
| 234 | + mActor.AddRenderer( mRenderer ); | |
| 235 | + stage.Add( mActor ); | |
| 236 | + } | |
| 237 | + | |
| 238 | + /** | |
| 239 | + * Plays animation | |
| 240 | + */ | |
| 241 | + void PlayAnimation() | |
| 242 | + { | |
| 243 | + mAnimation = Animation::New( 5.0f ); | |
| 244 | + mAnimation.SetLooping( true ); | |
| 245 | + mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::ZAXIS ) ); | |
| 246 | + mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ) ); | |
| 247 | + mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::XAXIS ) ); | |
| 248 | + mAnimation.Play(); | |
| 249 | + } | |
| 250 | + | |
| 251 | +private: | |
| 252 | + Application& mApplication; | |
| 253 | + | |
| 254 | + Renderer mRenderer; | |
| 255 | + Shader mShader; | |
| 256 | + Geometry mGeometry; | |
| 257 | + Actor mActor; | |
| 258 | + Animation mAnimation; | |
| 259 | +}; | |
| 260 | + | |
| 261 | +void RunTest( Application& application ) | |
| 262 | +{ | |
| 263 | + DrawCubeController test( application ); | |
| 264 | + | |
| 265 | + application.MainLoop(); | |
| 266 | +} | |
| 267 | + | |
| 268 | +// Entry point for Linux & Tizen applications | |
| 269 | +// | |
| 270 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 271 | +{ | |
| 272 | + Application application = Application::New( &argc, &argv ); | |
| 273 | + | |
| 274 | + RunTest( application ); | |
| 275 | + | |
| 276 | + return 0; | |
| 277 | +} | ... | ... |
examples/rendering-line/rendering-line.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 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 | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 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. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include <dali/dali.h> | |
| 19 | +#include <dali-toolkit/dali-toolkit.h> | |
| 20 | + | |
| 21 | +using namespace Dali; | |
| 22 | +using namespace Toolkit; | |
| 23 | + | |
| 24 | +namespace | |
| 25 | +{ | |
| 26 | + | |
| 27 | +/* | |
| 28 | + * Vertex shader | |
| 29 | + */ | |
| 30 | +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 31 | +attribute mediump vec2 aPosition;\n // DALi shader builtin | |
| 32 | +uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 33 | +uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 34 | +\n | |
| 35 | +void main()\n | |
| 36 | +{\n | |
| 37 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n | |
| 38 | + vertexPosition.xyz *= uSize;\n | |
| 39 | + gl_Position = uMvpMatrix * vertexPosition;\n | |
| 40 | +}\n | |
| 41 | +); | |
| 42 | + | |
| 43 | +/* | |
| 44 | + * Fragment shader | |
| 45 | + */ | |
| 46 | +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 47 | +uniform mediump vec4 uColor;\n | |
| 48 | +\n | |
| 49 | +void main()\n | |
| 50 | +{\n | |
| 51 | + gl_FragColor = uColor;\n | |
| 52 | +}\n | |
| 53 | +); | |
| 54 | + | |
| 55 | +} | |
| 56 | + | |
| 57 | +// This example shows how to draw a line in actor's color | |
| 58 | +// | |
| 59 | +class DrawLineController : public ConnectionTracker | |
| 60 | +{ | |
| 61 | +public: | |
| 62 | + | |
| 63 | + DrawLineController( Application& application ) | |
| 64 | + : mApplication( application ) | |
| 65 | + { | |
| 66 | + // Connect to the Application's Init signal | |
| 67 | + mApplication.InitSignal().Connect( this, &DrawLineController::Create ); | |
| 68 | + } | |
| 69 | + | |
| 70 | + ~DrawLineController() | |
| 71 | + { | |
| 72 | + // Nothing to do here; | |
| 73 | + } | |
| 74 | + | |
| 75 | + // The Init signal is received once (only) during the Application lifetime | |
| 76 | + void Create( Application& application ) | |
| 77 | + { | |
| 78 | + // Get a handle to the stage | |
| 79 | + Stage stage = Stage::GetCurrent(); | |
| 80 | + stage.SetBackgroundColor( Color::WHITE ); | |
| 81 | + | |
| 82 | + // Step 1. Create shader | |
| 83 | + CreateLineShader(); | |
| 84 | + | |
| 85 | + // Step 2. Prepare geometry | |
| 86 | + CreateLineGeometry(); | |
| 87 | + | |
| 88 | + // Step 3. Create a renderer | |
| 89 | + CreateRenderer(); | |
| 90 | + | |
| 91 | + // Step 4. Create an Actor | |
| 92 | + CreateActor(); | |
| 93 | + | |
| 94 | + // Respond to a click anywhere on the stage | |
| 95 | + stage.GetRootLayer().TouchSignal().Connect( this, &DrawLineController::OnTouch ); | |
| 96 | + } | |
| 97 | + | |
| 98 | + bool OnTouch( Actor actor, const TouchData& touch ) | |
| 99 | + { | |
| 100 | + // quit the application | |
| 101 | + mApplication.Quit(); | |
| 102 | + return true; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * This function creates a line geometry made of two vertices in order | |
| 107 | + * to draw a diagonal line. | |
| 108 | + */ | |
| 109 | + void CreateLineGeometry() | |
| 110 | + { | |
| 111 | + Vector2 vertices[] = { | |
| 112 | + Vector2( -1.0f, -1.0f ), | |
| 113 | + Vector2( 1.0f, 1.0f ) | |
| 114 | + }; | |
| 115 | + | |
| 116 | + PropertyBuffer vertexBuffer = PropertyBuffer::New( Property::Map() | |
| 117 | + .Add( "aPosition", Property::VECTOR2 ) ); | |
| 118 | + vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vector2) ); | |
| 119 | + | |
| 120 | + mGeometry = Geometry::New(); | |
| 121 | + mGeometry.AddVertexBuffer( vertexBuffer ); | |
| 122 | + mGeometry.SetType( Geometry::LINES ); | |
| 123 | + } | |
| 124 | + | |
| 125 | + /** | |
| 126 | + * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 127 | + * | |
| 128 | + * Shaders are very basic and all they do is transforming vertices and applying actor's colour. | |
| 129 | + */ | |
| 130 | + void CreateLineShader() | |
| 131 | + { | |
| 132 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | |
| 133 | + } | |
| 134 | + | |
| 135 | + /** | |
| 136 | + * Function creates renderer. | |
| 137 | + */ | |
| 138 | + void CreateRenderer() | |
| 139 | + { | |
| 140 | + mRenderer = Renderer::New( mGeometry, mShader ); | |
| 141 | + } | |
| 142 | + | |
| 143 | + /** | |
| 144 | + * Creates new actor and attaches renderer. | |
| 145 | + */ | |
| 146 | + void CreateActor() | |
| 147 | + { | |
| 148 | + Stage stage = Stage::GetCurrent(); | |
| 149 | + Size size = stage.GetSize() * 0.25f; | |
| 150 | + mActor = Actor::New(); | |
| 151 | + mActor.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 152 | + mActor.SetParentOrigin( ParentOrigin::CENTER ); | |
| 153 | + mActor.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); | |
| 154 | + mActor.SetColor( Color::BLACK ); | |
| 155 | + mActor.SetSize( Vector3( size.x, size.x, size.x ) ); | |
| 156 | + mActor.AddRenderer( mRenderer ); | |
| 157 | + stage.Add( mActor ); | |
| 158 | + } | |
| 159 | + | |
| 160 | +private: | |
| 161 | + Application& mApplication; | |
| 162 | + | |
| 163 | + Renderer mRenderer; | |
| 164 | + Shader mShader; | |
| 165 | + Geometry mGeometry; | |
| 166 | + Actor mActor; | |
| 167 | +}; | |
| 168 | + | |
| 169 | +void RunTest( Application& application ) | |
| 170 | +{ | |
| 171 | + DrawLineController test( application ); | |
| 172 | + | |
| 173 | + application.MainLoop(); | |
| 174 | +} | |
| 175 | + | |
| 176 | +// Entry point for Linux & Tizen applications | |
| 177 | +// | |
| 178 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 179 | +{ | |
| 180 | + Application application = Application::New( &argc, &argv ); | |
| 181 | + | |
| 182 | + RunTest( application ); | |
| 183 | + | |
| 184 | + return 0; | |
| 185 | +} | ... | ... |
examples/rendering-textured-cube/rendering-textured-cube.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 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 | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 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. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include <dali/dali.h> | |
| 19 | +#include <dali-toolkit/dali-toolkit.h> | |
| 20 | + | |
| 21 | +using namespace Dali; | |
| 22 | +using namespace Toolkit; | |
| 23 | + | |
| 24 | +namespace | |
| 25 | +{ | |
| 26 | + | |
| 27 | +/* | |
| 28 | + * Vertex shader | |
| 29 | + */ | |
| 30 | +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 31 | +attribute mediump vec3 aPosition;\n // DALi shader builtin | |
| 32 | +attribute mediump vec2 aTexCoord;\n // DALi shader builtin | |
| 33 | +uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 34 | +uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 35 | +\n | |
| 36 | +varying mediump vec2 vTexCoord;\n | |
| 37 | +void main()\n | |
| 38 | +{\n | |
| 39 | + mediump vec4 vertexPosition = vec4(aPosition, 1.0);\n | |
| 40 | + vertexPosition.xyz *= uSize;\n | |
| 41 | + vTexCoord = aTexCoord;\n | |
| 42 | + gl_Position = uMvpMatrix * vertexPosition;\n | |
| 43 | +}\n | |
| 44 | +); | |
| 45 | + | |
| 46 | +/* | |
| 47 | + * Fragment shader | |
| 48 | + */ | |
| 49 | +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 50 | +uniform sampler2D uTexture;\n | |
| 51 | +\n | |
| 52 | +varying mediump vec2 vTexCoord;\n | |
| 53 | +void main()\n | |
| 54 | +{\n | |
| 55 | + mediump vec4 texColor = texture2D( uTexture, vTexCoord );\n | |
| 56 | + gl_FragColor = texColor;\n | |
| 57 | +}\n | |
| 58 | +); | |
| 59 | + | |
| 60 | +const char* TEXTURE_URL = DEMO_IMAGE_DIR "wood.png"; | |
| 61 | + | |
| 62 | +} | |
| 63 | + | |
| 64 | +// This example shows how to create textured cube | |
| 65 | +// | |
| 66 | +class TexturedCubeController : public ConnectionTracker | |
| 67 | +{ | |
| 68 | +public: | |
| 69 | + | |
| 70 | + TexturedCubeController( Application& application ) | |
| 71 | + : mApplication( application ) | |
| 72 | + { | |
| 73 | + // Connect to the Application's Init signal | |
| 74 | + mApplication.InitSignal().Connect( this, &TexturedCubeController::Create ); | |
| 75 | + } | |
| 76 | + | |
| 77 | + ~TexturedCubeController() | |
| 78 | + { | |
| 79 | + // Nothing to do here; | |
| 80 | + } | |
| 81 | + | |
| 82 | + // The Init signal is received once (only) during the Application lifetime | |
| 83 | + void Create( Application& application ) | |
| 84 | + { | |
| 85 | + // Get a handle to the stage | |
| 86 | + Stage stage = Stage::GetCurrent(); | |
| 87 | + stage.SetBackgroundColor( Color::WHITE ); | |
| 88 | + | |
| 89 | + // Step 1. Create shader | |
| 90 | + CreateCubeShader(); | |
| 91 | + | |
| 92 | + // Step 2. Load a texture | |
| 93 | + CreateTexture(); | |
| 94 | + | |
| 95 | + // Step 3. Prepare geometry | |
| 96 | + CreateCubeGeometry(); | |
| 97 | + | |
| 98 | + // Step 4. Create a renderer | |
| 99 | + CreateRenderer(); | |
| 100 | + | |
| 101 | + // Step 5. Create an Actor | |
| 102 | + CreateActor(); | |
| 103 | + | |
| 104 | + // Step 6. Play animation to rotate the cube | |
| 105 | + PlayAnimation(); | |
| 106 | + | |
| 107 | + // Respond to a click anywhere on the stage | |
| 108 | + stage.GetRootLayer().TouchSignal().Connect( this, &TexturedCubeController::OnTouch ); | |
| 109 | + } | |
| 110 | + | |
| 111 | + bool OnTouch( Actor actor, const TouchData& touch ) | |
| 112 | + { | |
| 113 | + // quit the application | |
| 114 | + mApplication.Quit(); | |
| 115 | + return true; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * @brief CreateCubeGeometry | |
| 120 | + * This function creates a cube geometry including texture coordinates. | |
| 121 | + * Also it demonstrates using the indexed draw feature by setting an index array. | |
| 122 | + */ | |
| 123 | + void CreateCubeGeometry() | |
| 124 | + { | |
| 125 | + struct Vertex | |
| 126 | + { | |
| 127 | + Vector3 aPosition; | |
| 128 | + Vector2 aTexCoord; | |
| 129 | + }; | |
| 130 | + | |
| 131 | + Vertex vertices[] = { | |
| 132 | + { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 133 | + { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 134 | + { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, | |
| 135 | + { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 136 | + { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 137 | + { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 0.0, 1.0 ) }, | |
| 138 | + { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 139 | + { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 140 | + { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, | |
| 141 | + { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 142 | + { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 143 | + { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, | |
| 144 | + { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 145 | + { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 146 | + { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 1.0 ) }, | |
| 147 | + { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 148 | + { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 149 | + { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 0.0, 1.0 ) }, | |
| 150 | + { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 151 | + { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 0.0 ) }, | |
| 152 | + { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 153 | + { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 154 | + { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, | |
| 155 | + { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 156 | + { Vector3( 1.0f, 1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 157 | + { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, | |
| 158 | + { Vector3( 1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 159 | + { Vector3( 1.0f,-1.0f, 1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 160 | + { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, | |
| 161 | + { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 162 | + { Vector3( -1.0f,-1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 163 | + { Vector3( -1.0f,-1.0f, 1.0f ), Vector2( 1.0, 0.0 ) }, | |
| 164 | + { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 165 | + { Vector3( 1.0f, 1.0f,-1.0f ), Vector2( 1.0, 1.0 ) }, | |
| 166 | + { Vector3( -1.0f, 1.0f,-1.0f ), Vector2( 1.0, 0.0 ) }, | |
| 167 | + { Vector3( -1.0f, 1.0f, 1.0f ), Vector2( 0.0, 0.0 ) }, | |
| 168 | + }; | |
| 169 | + | |
| 170 | + PropertyBuffer vertexBuffer = PropertyBuffer::New( Property::Map() | |
| 171 | + .Add( "aPosition", Property::VECTOR3 ) | |
| 172 | + .Add( "aTexCoord", Property::VECTOR2 ) ); | |
| 173 | + vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vertex) ); | |
| 174 | + | |
| 175 | + // create indices | |
| 176 | + const unsigned short INDEX_CUBE[] = { | |
| 177 | + 2, 1, 0, | |
| 178 | + 5, 4, 3, | |
| 179 | + 8, 7, 6, | |
| 180 | + 11, 10, 9, | |
| 181 | + 14, 13, 12, | |
| 182 | + 17, 16, 15, | |
| 183 | + 20, 19, 18, | |
| 184 | + 23, 22, 21, | |
| 185 | + 26, 25, 24, | |
| 186 | + 29, 28, 27, | |
| 187 | + 32, 31, 30, | |
| 188 | + 35, 34, 33 | |
| 189 | + }; | |
| 190 | + mGeometry = Geometry::New(); | |
| 191 | + mGeometry.AddVertexBuffer( vertexBuffer ); | |
| 192 | + mGeometry.SetIndexBuffer( INDEX_CUBE, | |
| 193 | + sizeof(INDEX_CUBE)/sizeof(INDEX_CUBE[0]) ); | |
| 194 | + mGeometry.SetType( Geometry::TRIANGLES ); | |
| 195 | + } | |
| 196 | + | |
| 197 | + /** | |
| 198 | + * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 199 | + * | |
| 200 | + * Shaders are very basic and all they do is transforming vertices and sampling | |
| 201 | + * a texture. | |
| 202 | + */ | |
| 203 | + void CreateCubeShader() | |
| 204 | + { | |
| 205 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | |
| 206 | + } | |
| 207 | + | |
| 208 | + /** | |
| 209 | + * This function loads a pixel data from a file. In order to load it we use SyncImageLoader utility. | |
| 210 | + * If loading succeeds returned PixelData object can be used to create a texture. | |
| 211 | + * Texture must be uploaded. In the end the texture must be set on the TextureSet object. | |
| 212 | + */ | |
| 213 | + void CreateTexture() | |
| 214 | + { | |
| 215 | + // Load image from file | |
| 216 | + PixelData pixels = SyncImageLoader::Load( TEXTURE_URL ); | |
| 217 | + | |
| 218 | + Texture texture = Texture::New( TextureType::TEXTURE_2D, pixels.GetPixelFormat(), pixels.GetWidth(), pixels.GetHeight() ); | |
| 219 | + texture.Upload( pixels, 0, 0, 0, 0, pixels.GetWidth(), pixels.GetHeight() ); | |
| 220 | + | |
| 221 | + // create TextureSet | |
| 222 | + mTextureSet = TextureSet::New(); | |
| 223 | + mTextureSet.SetTexture( 0, texture ); | |
| 224 | + } | |
| 225 | + | |
| 226 | + /** | |
| 227 | + * Function creates renderer. It turns on depth test and depth write. | |
| 228 | + */ | |
| 229 | + void CreateRenderer() | |
| 230 | + { | |
| 231 | + mRenderer = Renderer::New( mGeometry, mShader ); | |
| 232 | + mRenderer.SetTextures( mTextureSet ); | |
| 233 | + | |
| 234 | + // Face culling is enabled to hide the backwards facing sides of the cube | |
| 235 | + // This is sufficient to render a single object; for more complex scenes depth-testing might be required | |
| 236 | + mRenderer.SetProperty( Renderer::Property::FACE_CULLING_MODE, FaceCullingMode::BACK ); | |
| 237 | + } | |
| 238 | + | |
| 239 | + /** | |
| 240 | + * Creates new actor and attaches renderer. | |
| 241 | + */ | |
| 242 | + void CreateActor() | |
| 243 | + { | |
| 244 | + Stage stage = Stage::GetCurrent(); | |
| 245 | + | |
| 246 | + float quarterStageWidth = stage.GetSize().x * 0.25f; | |
| 247 | + mActor = Actor::New(); | |
| 248 | + mActor.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 249 | + mActor.SetParentOrigin( ParentOrigin::CENTER ); | |
| 250 | + mActor.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); | |
| 251 | + mActor.SetSize( Vector3( quarterStageWidth, quarterStageWidth, quarterStageWidth ) ); | |
| 252 | + mActor.AddRenderer( mRenderer ); | |
| 253 | + stage.Add( mActor ); | |
| 254 | + } | |
| 255 | + | |
| 256 | + /** | |
| 257 | + * Plays animation | |
| 258 | + */ | |
| 259 | + void PlayAnimation() | |
| 260 | + { | |
| 261 | + mAnimation = Animation::New( 5.0f ); | |
| 262 | + mAnimation.SetLooping( true ); | |
| 263 | + mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::ZAXIS ) ); | |
| 264 | + mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::YAXIS ) ); | |
| 265 | + mAnimation.AnimateBy( Property( mActor, Actor::Property::ORIENTATION ), Quaternion( Radian( Degree( 360 )), Vector3::XAXIS ) ); | |
| 266 | + mAnimation.Play(); | |
| 267 | + } | |
| 268 | + | |
| 269 | +private: | |
| 270 | + Application& mApplication; | |
| 271 | + | |
| 272 | + Renderer mRenderer; | |
| 273 | + Shader mShader; | |
| 274 | + Geometry mGeometry; | |
| 275 | + TextureSet mTextureSet; | |
| 276 | + Actor mActor; | |
| 277 | + Animation mAnimation; | |
| 278 | +}; | |
| 279 | + | |
| 280 | +void RunTest( Application& application ) | |
| 281 | +{ | |
| 282 | + TexturedCubeController test( application ); | |
| 283 | + | |
| 284 | + application.MainLoop(); | |
| 285 | +} | |
| 286 | + | |
| 287 | +// Entry point for Linux & Tizen applications | |
| 288 | +// | |
| 289 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 290 | +{ | |
| 291 | + Application application = Application::New( &argc, &argv ); | |
| 292 | + | |
| 293 | + RunTest( application ); | |
| 294 | + | |
| 295 | + return 0; | |
| 296 | +} | ... | ... |
examples/rendering-triangle/rendering-triangle.cpp
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (c) 2017 Samsung Electronics Co., Ltd. | |
| 3 | + * | |
| 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 | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 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. | |
| 15 | + * | |
| 16 | + */ | |
| 17 | + | |
| 18 | +#include <dali/dali.h> | |
| 19 | +#include <dali-toolkit/dali-toolkit.h> | |
| 20 | + | |
| 21 | +using namespace Dali; | |
| 22 | +using namespace Toolkit; | |
| 23 | + | |
| 24 | +namespace | |
| 25 | +{ | |
| 26 | + | |
| 27 | +/* | |
| 28 | + * Vertex shader | |
| 29 | + */ | |
| 30 | +const char* VERTEX_SHADER = DALI_COMPOSE_SHADER( | |
| 31 | +attribute mediump vec2 aPosition;\n // DALi shader builtin | |
| 32 | +uniform mediump mat4 uMvpMatrix;\n // DALi shader builtin | |
| 33 | +uniform mediump vec3 uSize;\n // DALi shader builtin | |
| 34 | +\n | |
| 35 | +void main()\n | |
| 36 | +{\n | |
| 37 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0);\n | |
| 38 | + vertexPosition.xyz *= uSize;\n | |
| 39 | + gl_Position = uMvpMatrix * vertexPosition;\n | |
| 40 | +}\n | |
| 41 | +); | |
| 42 | + | |
| 43 | +/* | |
| 44 | + * Fragment shader | |
| 45 | + */ | |
| 46 | +const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER( | |
| 47 | +uniform mediump vec4 uColor;\n | |
| 48 | +\n | |
| 49 | +void main()\n | |
| 50 | +{\n | |
| 51 | + gl_FragColor = uColor;\n | |
| 52 | +}\n | |
| 53 | +); | |
| 54 | + | |
| 55 | +} | |
| 56 | + | |
| 57 | +// This example shows how to draw a triangle in actor's color | |
| 58 | +// | |
| 59 | +class DrawTriangleController : public ConnectionTracker | |
| 60 | +{ | |
| 61 | +public: | |
| 62 | + | |
| 63 | + DrawTriangleController( Application& application ) | |
| 64 | + : mApplication( application ) | |
| 65 | + { | |
| 66 | + // Connect to the Application's Init signal | |
| 67 | + mApplication.InitSignal().Connect( this, &DrawTriangleController::Create ); | |
| 68 | + } | |
| 69 | + | |
| 70 | + ~DrawTriangleController() | |
| 71 | + { | |
| 72 | + // Nothing to do here; | |
| 73 | + } | |
| 74 | + | |
| 75 | + // The Init signal is received once (only) during the Application lifetime | |
| 76 | + void Create( Application& application ) | |
| 77 | + { | |
| 78 | + // Get a handle to the stage | |
| 79 | + Stage stage = Stage::GetCurrent(); | |
| 80 | + stage.SetBackgroundColor( Color::WHITE ); | |
| 81 | + | |
| 82 | + // Step 1. Create shader | |
| 83 | + CreateTriangleShader(); | |
| 84 | + | |
| 85 | + // Step 2. Prepare geometry | |
| 86 | + CreateTriangleGeometry(); | |
| 87 | + | |
| 88 | + // Step 3. Create a renderer | |
| 89 | + CreateRenderer(); | |
| 90 | + | |
| 91 | + // Step 4. Create an Actor | |
| 92 | + CreateActor(); | |
| 93 | + | |
| 94 | + // Respond to a click anywhere on the stage | |
| 95 | + stage.GetRootLayer().TouchSignal().Connect( this, &DrawTriangleController::OnTouch ); | |
| 96 | + } | |
| 97 | + | |
| 98 | + bool OnTouch( Actor actor, const TouchData& touch ) | |
| 99 | + { | |
| 100 | + // quit the application | |
| 101 | + mApplication.Quit(); | |
| 102 | + return true; | |
| 103 | + } | |
| 104 | + | |
| 105 | + /** | |
| 106 | + * This function creates a triangle geometry made of three vertices in order | |
| 107 | + * to draw a coloured triangle. | |
| 108 | + */ | |
| 109 | + void CreateTriangleGeometry() | |
| 110 | + { | |
| 111 | + Vector2 vertices[] = { | |
| 112 | + Vector2( -1.0f, -1.0f ), | |
| 113 | + Vector2( 1.0f, 1.0f ), | |
| 114 | + Vector2( -1.0f, 1.0f ) | |
| 115 | + }; | |
| 116 | + | |
| 117 | + PropertyBuffer vertexBuffer = PropertyBuffer::New( Property::Map() | |
| 118 | + .Add( "aPosition", Property::VECTOR2 ) ); | |
| 119 | + vertexBuffer.SetData( vertices, sizeof(vertices) / sizeof(Vector2) ); | |
| 120 | + | |
| 121 | + mGeometry = Geometry::New(); | |
| 122 | + mGeometry.AddVertexBuffer( vertexBuffer ); | |
| 123 | + mGeometry.SetType( Geometry::TRIANGLES ); | |
| 124 | + } | |
| 125 | + | |
| 126 | + /** | |
| 127 | + * Creates a shader using inlined variable VERTEX_SHADER and FRAGMENT_SHADER | |
| 128 | + * | |
| 129 | + * Shaders are very basic and all they do is transforming vertices and applying actor's colour. | |
| 130 | + */ | |
| 131 | + void CreateTriangleShader() | |
| 132 | + { | |
| 133 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | |
| 134 | + } | |
| 135 | + | |
| 136 | + /** | |
| 137 | + * Function creates renderer. | |
| 138 | + */ | |
| 139 | + void CreateRenderer() | |
| 140 | + { | |
| 141 | + mRenderer = Renderer::New( mGeometry, mShader ); | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * Creates new actor and attaches renderer. | |
| 146 | + */ | |
| 147 | + void CreateActor() | |
| 148 | + { | |
| 149 | + Stage stage = Stage::GetCurrent(); | |
| 150 | + Size size = stage.GetSize() * 0.25f; | |
| 151 | + mActor = Actor::New(); | |
| 152 | + mActor.SetAnchorPoint( AnchorPoint::CENTER ); | |
| 153 | + mActor.SetParentOrigin( ParentOrigin::CENTER ); | |
| 154 | + mActor.SetPosition( Vector3( 0.0f, 0.0f, 0.0f ) ); | |
| 155 | + mActor.SetColor( Color::RED ); | |
| 156 | + mActor.SetSize( Vector3( size.x, size.x, size.x ) ); | |
| 157 | + mActor.AddRenderer( mRenderer ); | |
| 158 | + stage.Add( mActor ); | |
| 159 | + } | |
| 160 | + | |
| 161 | +private: | |
| 162 | + Application& mApplication; | |
| 163 | + | |
| 164 | + Renderer mRenderer; | |
| 165 | + Shader mShader; | |
| 166 | + Geometry mGeometry; | |
| 167 | + Actor mActor; | |
| 168 | +}; | |
| 169 | + | |
| 170 | +void RunTest( Application& application ) | |
| 171 | +{ | |
| 172 | + DrawTriangleController test( application ); | |
| 173 | + | |
| 174 | + application.MainLoop(); | |
| 175 | +} | |
| 176 | + | |
| 177 | +// Entry point for Linux & Tizen applications | |
| 178 | +// | |
| 179 | +int DALI_EXPORT_API main( int argc, char **argv ) | |
| 180 | +{ | |
| 181 | + Application application = Application::New( &argc, &argv ); | |
| 182 | + | |
| 183 | + RunTest( application ); | |
| 184 | + | |
| 185 | + return 0; | |
| 186 | +} | ... | ... |
resources/po/as.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "Tooltip" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP খেলা" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "ৰেণ্ডাৰিং গাঁথনি" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "ৰেণ্ডাৰিং ঘনক" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "ৰেণ্ডাৰিং ত্ৰিকোণমিতি" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "ৰেণ্ডাৰিং শাৰী" | ... | ... |
resources/po/de.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "Kurzinfo" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP Spiel" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "Texturierter Würfel" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "Würfel zeichnen" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "Dreieck zeichnen" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "Zeichnen" | ... | ... |
resources/po/en_GB.po
| ... | ... | @@ -150,3 +150,15 @@ msgstr "FPP Game" |
| 150 | 150 | |
| 151 | 151 | msgid "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS" |
| 152 | 152 | msgstr "Visual Transitions" |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 155 | +msgstr "Textured cube" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 158 | +msgstr "Draw cube" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 161 | +msgstr "Draw triangle" | |
| 162 | + | |
| 163 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 164 | +msgstr "Draw line" | ... | ... |
resources/po/en_US.po
| ... | ... | @@ -150,3 +150,15 @@ msgstr "FPP Game" |
| 150 | 150 | |
| 151 | 151 | msgid "DALI_DEMO_STR_TITLE_VISUAL_TRANSITIONS" |
| 152 | 152 | msgstr "Visual Transitions" |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 155 | +msgstr "Textured cube" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 158 | +msgstr "Draw cube" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 161 | +msgstr "Draw triangle" | |
| 162 | + | |
| 163 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 164 | +msgstr "Draw line" | ... | ... |
resources/po/es.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "Tooltip" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "Juego FPP" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "Cubo con textura" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "Dibujar cubo" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "Dibujar triángulo" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "Dibujar linea" | ... | ... |
resources/po/fi.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "Tooltip" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP peli" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "kuvioitu kuutio" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "piirtää kuutio" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "Piirrä kolmio" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "Draw linja" | ... | ... |
resources/po/ko.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "툴팁" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP Game" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "질감 입방체" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "큐브 그리기" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "삼각형 그리기" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "선 그리기" | ... | ... |
resources/po/ml.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "കൂടുതൽ വിവരങ്ങൾ" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP Game" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "ടെക്സ്ചർ ക്യൂബ്" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "ക്യൂബ് വരയ്ക്കുക" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "ത്രികോണം വരയ്ക്കുക" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "സമനില ലൈൻ" | ... | ... |
resources/po/ur.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "مزید معلومات" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP گیم" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "بویک ٹوانب " | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "ارڈ بویک " | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "ارڈ ثلثم " | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "انچنیھک ریکل " | ... | ... |
resources/po/zn_CH.po
| ... | ... | @@ -147,3 +147,15 @@ msgstr "更多信息" |
| 147 | 147 | |
| 148 | 148 | msgid "DALI_DEMO_STR_TITLE_FPP_GAME" |
| 149 | 149 | msgstr "FPP游戏" |
| 150 | + | |
| 151 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE" | |
| 152 | +msgstr "纹理的多维数据集" | |
| 153 | + | |
| 154 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE" | |
| 155 | +msgstr "绘制多维数据集" | |
| 156 | + | |
| 157 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE" | |
| 158 | +msgstr "绘制三角形" | |
| 159 | + | |
| 160 | +msgid "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE" | |
| 161 | +msgstr "画线" | ... | ... |
shared/dali-demo-strings.h
| ... | ... | @@ -67,6 +67,10 @@ extern "C" |
| 67 | 67 | #define DALI_DEMO_STR_TITLE_POPUP dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_POPUP") |
| 68 | 68 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES") |
| 69 | 69 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_PROGRESS_BAR") |
| 70 | +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE") | |
| 71 | +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE") | |
| 72 | +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE") | |
| 73 | +#define DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE") | |
| 70 | 74 | #define DALI_DEMO_STR_TITLE_REFRACTION dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_REFRACTION") |
| 71 | 75 | #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_RENDERER_STENCIL") |
| 72 | 76 | #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI dgettext(DALI_DEMO_DOMAIN_LOCAL, "DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI") |
| ... | ... | @@ -120,6 +124,10 @@ extern "C" |
| 120 | 124 | #define DALI_DEMO_STR_TITLE_POPUP "Popup" |
| 121 | 125 | #define DALI_DEMO_STR_TITLE_PRIMITIVE_SHAPES "Primitive Shapes" |
| 122 | 126 | #define DALI_DEMO_STR_TITLE_PROGRESS_BAR "Progress Bar" |
| 127 | +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_LINE "Draw Line" | |
| 128 | +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_TRIANGLE "Draw Triangle" | |
| 129 | +#define DALI_DEMO_STR_TITLE_RENDERING_DRAW_CUBE "Draw Cube" | |
| 130 | +#define DALI_DEMO_STR_TITLE_RENDERING_TEXTURED_CUBE "Textured Cube" | |
| 123 | 131 | #define DALI_DEMO_STR_TITLE_REFRACTION "Refract Effect" |
| 124 | 132 | #define DALI_DEMO_STR_TITLE_RENDERER_STENCIL "Renderer Stencils" |
| 125 | 133 | #define DALI_DEMO_STR_TITLE_SCRIPT_BASED_UI "Script Based UI" | ... | ... |