Commit 5d4db52cfe19e40ff8eb748c09764d7237556781
1 parent
e1bf40ab
New point and line demos
The point demo shows off multiple points each using a morph from one sampler to another, and applying a hue to each point based on it's angle. The line demo shows off morphing between two position buffers. The textured demo shows a single geometry being used by 2 different renderers each with a different material, and also shows off uniform mapping by animating a "fade-color" property which is mapped to a "uFadeColor" uniform. Change-Id: I53c0ed2f3849dffd4b9461f07bbce75308811d9b Signed-off-by: David Steele <david.steele@partner.samsung.com>
Showing
3 changed files
with
530 additions
and
14 deletions
examples/line-mesh/line-mesh-example.cpp
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2015 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 | +// EXTERNAL INCLUDES | ||
| 19 | + | ||
| 20 | +// INTERNAL INCLUDES | ||
| 21 | +#include "shared/view.h" | ||
| 22 | + | ||
| 23 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 24 | + | ||
| 25 | +using namespace Dali; | ||
| 26 | + | ||
| 27 | +namespace | ||
| 28 | +{ | ||
| 29 | +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); | ||
| 30 | +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); | ||
| 31 | + | ||
| 32 | +#define MAKE_SHADER(A)#A | ||
| 33 | + | ||
| 34 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 35 | +attribute mediump vec2 aPosition1; | ||
| 36 | +attribute mediump vec2 aPosition2; | ||
| 37 | +uniform mediump mat4 uMvpMatrix; | ||
| 38 | +uniform mediump vec3 uSize; | ||
| 39 | +uniform mediump float uMorphAmount; | ||
| 40 | + | ||
| 41 | +void main() | ||
| 42 | +{ | ||
| 43 | + mediump vec2 morphPosition = mix(aPosition1, aPosition2, uMorphAmount); | ||
| 44 | + mediump vec4 vertexPosition = vec4(morphPosition, 0.0, 1.0); | ||
| 45 | + vertexPosition.xyz *= uSize; | ||
| 46 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 47 | + gl_Position = vertexPosition; | ||
| 48 | +} | ||
| 49 | +); | ||
| 50 | + | ||
| 51 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 52 | +uniform lowp vec4 uColor; | ||
| 53 | +uniform sampler2D sTexture; | ||
| 54 | + | ||
| 55 | +void main() | ||
| 56 | +{ | ||
| 57 | + gl_FragColor = uColor; | ||
| 58 | +} | ||
| 59 | +); | ||
| 60 | + | ||
| 61 | +Geometry CreateGeometry() | ||
| 62 | +{ | ||
| 63 | + // Create vertices | ||
| 64 | + struct Vertex { Vector2 position; }; | ||
| 65 | + Vertex pentagonVertexData[5] = | ||
| 66 | + { | ||
| 67 | + { Vector2( 0.0f, 1.00f) }, // 0 | ||
| 68 | + { Vector2( -0.95f, 0.31f) }, // 1 | ||
| 69 | + { Vector2( -0.59f, -0.81f) }, // 2 | ||
| 70 | + { Vector2( 0.59f, -0.81f) }, // 3 | ||
| 71 | + { Vector2( 0.95f, 0.31f) }, // 4 | ||
| 72 | + }; | ||
| 73 | + | ||
| 74 | + Vertex pentacleVertexData[5] = | ||
| 75 | + { | ||
| 76 | + { Vector2( 0.0f, -1.00f) }, // | ||
| 77 | + { Vector2( 0.59f, 0.81f) }, // | ||
| 78 | + { Vector2( -0.95f, -0.31f) }, // | ||
| 79 | + { Vector2( 0.95f, -0.31f) }, // | ||
| 80 | + { Vector2( -0.59f, 0.81f) }, // | ||
| 81 | + }; | ||
| 82 | + | ||
| 83 | + Property::Map pentagonVertexFormat; | ||
| 84 | + pentagonVertexFormat["aPosition1"] = Property::VECTOR2; | ||
| 85 | + PropertyBuffer pentagonVertices = PropertyBuffer::New( PropertyBuffer::STATIC, pentagonVertexFormat, 5 ); | ||
| 86 | + pentagonVertices.SetData(pentagonVertexData); | ||
| 87 | + | ||
| 88 | + Property::Map pentacleVertexFormat; | ||
| 89 | + pentacleVertexFormat["aPosition2"] = Property::VECTOR2; | ||
| 90 | + PropertyBuffer pentacleVertices = PropertyBuffer::New( PropertyBuffer::STATIC, pentacleVertexFormat, 5 ); | ||
| 91 | + pentacleVertices.SetData(pentacleVertexData); | ||
| 92 | + | ||
| 93 | + // Create indices | ||
| 94 | + unsigned short indexData[10] = { 0, 1, 1, 2, 2, 3, 3, 4, 4, 0 }; | ||
| 95 | + Property::Map indexFormat; | ||
| 96 | + indexFormat["indices"] = Property::UNSIGNED_INTEGER; | ||
| 97 | + PropertyBuffer indices = PropertyBuffer::New( PropertyBuffer::STATIC, indexFormat, 5 ); | ||
| 98 | + indices.SetData(indexData); | ||
| 99 | + | ||
| 100 | + // Create the geometry object | ||
| 101 | + Geometry pentagonGeometry = Geometry::New(); | ||
| 102 | + pentagonGeometry.AddVertexBuffer( pentagonVertices ); | ||
| 103 | + pentagonGeometry.AddVertexBuffer( pentacleVertices ); | ||
| 104 | + pentagonGeometry.SetIndexBuffer( indices ); | ||
| 105 | + | ||
| 106 | + pentagonGeometry.SetGeometryType( Geometry::LINES ); | ||
| 107 | + | ||
| 108 | + return pentagonGeometry; | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | +} // anonymous namespace | ||
| 112 | + | ||
| 113 | +// This example shows how to morph between 2 meshes with the same number of | ||
| 114 | +// vertices. | ||
| 115 | +class ExampleController : public ConnectionTracker | ||
| 116 | +{ | ||
| 117 | +public: | ||
| 118 | + | ||
| 119 | + /** | ||
| 120 | + * The example controller constructor. | ||
| 121 | + * @param[in] application The application instance | ||
| 122 | + */ | ||
| 123 | + ExampleController( Application& application ) | ||
| 124 | + : mApplication( application ) | ||
| 125 | + { | ||
| 126 | + // Connect to the Application's Init signal | ||
| 127 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + /** | ||
| 131 | + * The example controller destructor | ||
| 132 | + */ | ||
| 133 | + ~ExampleController() | ||
| 134 | + { | ||
| 135 | + // Nothing to do here; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + /** | ||
| 139 | + * Invoked upon creation of application | ||
| 140 | + * @param[in] application The application instance | ||
| 141 | + */ | ||
| 142 | + void Create( Application& application ) | ||
| 143 | + { | ||
| 144 | + Stage stage = Stage::GetCurrent(); | ||
| 145 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 146 | + | ||
| 147 | + mStageSize = stage.GetSize(); | ||
| 148 | + | ||
| 149 | + // The Init signal is received once (only) during the Application lifetime | ||
| 150 | + | ||
| 151 | + // Hide the indicator bar | ||
| 152 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 153 | + | ||
| 154 | + mImage = ResourceImage::New( MATERIAL_SAMPLE ); | ||
| 155 | + mSampler = Sampler::New(mImage, "sTexture"); | ||
| 156 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 157 | + | ||
| 158 | + mMaterial = Material::New( mShader ); | ||
| 159 | + mMaterial.AddSampler( mSampler ); | ||
| 160 | + | ||
| 161 | + mGeometry = CreateGeometry(); | ||
| 162 | + | ||
| 163 | + mRenderer = Renderer::New( mGeometry, mMaterial ); | ||
| 164 | + | ||
| 165 | + mMeshActor = Actor::New(); | ||
| 166 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 167 | + mMeshActor.SetSize(200, 200); | ||
| 168 | + | ||
| 169 | + Property::Index morphAmountIndex = mMeshActor.RegisterProperty( "morph-amount", 0.0f ); | ||
| 170 | + mMeshActor.AddUniformMapping( morphAmountIndex, std::string("uMorphAmount") ); | ||
| 171 | + | ||
| 172 | + mRenderer.SetDepthIndex(0); | ||
| 173 | + | ||
| 174 | + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 175 | + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 176 | + stage.Add( mMeshActor ); | ||
| 177 | + | ||
| 178 | + mChangeImageTimer = Timer::New( 5000 ); | ||
| 179 | + mChangeImageTimer.TickSignal().Connect( this, &ExampleController::OnTimer ); | ||
| 180 | + mChangeImageTimer.Start(); | ||
| 181 | + | ||
| 182 | + Animation animation = Animation::New(5); | ||
| 183 | + KeyFrames keyFrames = KeyFrames::New(); | ||
| 184 | + keyFrames.Add(0.0f, 0.0f); | ||
| 185 | + keyFrames.Add(1.0f, 1.0f); | ||
| 186 | + | ||
| 187 | + animation.AnimateBetween( Property( mMeshActor, morphAmountIndex ), keyFrames, AlphaFunctions::Sin ); | ||
| 188 | + animation.SetLooping(true); | ||
| 189 | + animation.Play(); | ||
| 190 | + | ||
| 191 | + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | ||
| 192 | + } | ||
| 193 | + | ||
| 194 | + /** | ||
| 195 | + * Invoked whenever the quit button is clicked | ||
| 196 | + * @param[in] button the quit button | ||
| 197 | + */ | ||
| 198 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 199 | + { | ||
| 200 | + // quit the application | ||
| 201 | + mApplication.Quit(); | ||
| 202 | + return true; | ||
| 203 | + } | ||
| 204 | + | ||
| 205 | + bool OnTimer() | ||
| 206 | + { | ||
| 207 | + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | ||
| 208 | + mSampler.SetImage( image ); | ||
| 209 | + return false; | ||
| 210 | + } | ||
| 211 | + | ||
| 212 | + void OnKeyEvent(const KeyEvent& event) | ||
| 213 | + { | ||
| 214 | + if(event.state == KeyEvent::Down) | ||
| 215 | + { | ||
| 216 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 217 | + { | ||
| 218 | + mApplication.Quit(); | ||
| 219 | + } | ||
| 220 | + } | ||
| 221 | + } | ||
| 222 | + | ||
| 223 | +private: | ||
| 224 | + | ||
| 225 | + Application& mApplication; ///< Application instance | ||
| 226 | + Vector3 mStageSize; ///< The size of the stage | ||
| 227 | + | ||
| 228 | + Image mImage; | ||
| 229 | + Sampler mSampler; | ||
| 230 | + Shader mShader; | ||
| 231 | + Material mMaterial; | ||
| 232 | + Geometry mGeometry; | ||
| 233 | + Renderer mRenderer; | ||
| 234 | + Actor mMeshActor; | ||
| 235 | + Renderer mRenderer2; | ||
| 236 | + Actor mMeshActor2; | ||
| 237 | + Timer mChangeImageTimer; | ||
| 238 | +}; | ||
| 239 | + | ||
| 240 | +void RunTest( Application& application ) | ||
| 241 | +{ | ||
| 242 | + ExampleController test( application ); | ||
| 243 | + | ||
| 244 | + application.MainLoop(); | ||
| 245 | +} | ||
| 246 | + | ||
| 247 | +// Entry point for Linux & SLP applications | ||
| 248 | +// | ||
| 249 | +int main( int argc, char **argv ) | ||
| 250 | +{ | ||
| 251 | + Application application = Application::New( &argc, &argv ); | ||
| 252 | + | ||
| 253 | + RunTest( application ); | ||
| 254 | + | ||
| 255 | + return 0; | ||
| 256 | +} |
examples/point-mesh/point-mesh-example.cpp
0 → 100644
| 1 | +/* | ||
| 2 | + * Copyright (c) 2015 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 | +// EXTERNAL INCLUDES | ||
| 19 | + | ||
| 20 | +// INTERNAL INCLUDES | ||
| 21 | +#include "shared/view.h" | ||
| 22 | + | ||
| 23 | +#include <dali-toolkit/dali-toolkit.h> | ||
| 24 | + | ||
| 25 | +using namespace Dali; | ||
| 26 | + | ||
| 27 | +namespace | ||
| 28 | +{ | ||
| 29 | +const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); | ||
| 30 | +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); | ||
| 31 | + | ||
| 32 | +#define MAKE_SHADER(A)#A | ||
| 33 | + | ||
| 34 | +const char* VERTEX_SHADER = MAKE_SHADER( | ||
| 35 | +attribute mediump vec2 aPosition; | ||
| 36 | +attribute highp float aHue; | ||
| 37 | +varying mediump vec2 vTexCoord; | ||
| 38 | +uniform mediump mat4 uMvpMatrix; | ||
| 39 | +uniform mediump vec3 uSize; | ||
| 40 | +uniform lowp vec4 uFadeColor; | ||
| 41 | +varying mediump vec3 vVertexColor; | ||
| 42 | +varying mediump float vHue; | ||
| 43 | + | ||
| 44 | +vec3 hsv2rgb(vec3 c) | ||
| 45 | +{ | ||
| 46 | + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); | ||
| 47 | + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); | ||
| 48 | + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); | ||
| 49 | +} | ||
| 50 | + | ||
| 51 | +void main() | ||
| 52 | +{ | ||
| 53 | + mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | ||
| 54 | + vertexPosition.xyz *= uSize; | ||
| 55 | + vertexPosition = uMvpMatrix * vertexPosition; | ||
| 56 | + vVertexColor = hsv2rgb( vec3( aHue, 0.6, 0.7 ) ); | ||
| 57 | + vHue = aHue; | ||
| 58 | + gl_PointSize = 80.0; | ||
| 59 | + gl_Position = vertexPosition; | ||
| 60 | +} | ||
| 61 | +); | ||
| 62 | + | ||
| 63 | +const char* FRAGMENT_SHADER = MAKE_SHADER( | ||
| 64 | +varying mediump vec3 vVertexColor; | ||
| 65 | +varying mediump float vHue; | ||
| 66 | +uniform lowp vec4 uColor; | ||
| 67 | +uniform sampler2D sTexture1; | ||
| 68 | +uniform sampler2D sTexture2; | ||
| 69 | +uniform lowp vec4 uFadeColor; | ||
| 70 | + | ||
| 71 | +void main() | ||
| 72 | +{ | ||
| 73 | + mediump vec4 texCol1 = texture2D(sTexture1, gl_PointCoord); | ||
| 74 | + mediump vec4 texCol2 = texture2D(sTexture2, gl_PointCoord); | ||
| 75 | + gl_FragColor = vec4(vVertexColor, 1.0) * ((texCol1*vHue) + (texCol2*(1.0-vHue))); | ||
| 76 | +} | ||
| 77 | +); | ||
| 78 | + | ||
| 79 | +Geometry CreateGeometry() | ||
| 80 | +{ | ||
| 81 | + // Create vertices | ||
| 82 | + struct Vertex { Vector2 position; float hue; }; | ||
| 83 | + | ||
| 84 | + unsigned int numSides = 20; | ||
| 85 | + Vertex polyhedraVertexData[numSides]; | ||
| 86 | + float angle=0; | ||
| 87 | + float sectorAngle = 2.0f * Math::PI / (float) numSides; | ||
| 88 | + for(unsigned int i=0; i<numSides; ++i) | ||
| 89 | + { | ||
| 90 | + polyhedraVertexData[i].position.x = sinf(angle); | ||
| 91 | + polyhedraVertexData[i].position.y = cosf(angle); | ||
| 92 | + polyhedraVertexData[i].hue = angle / ( 2.0f * Math::PI); | ||
| 93 | + angle += sectorAngle; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + Property::Map polyhedraVertexFormat; | ||
| 97 | + polyhedraVertexFormat["aPosition"] = Property::VECTOR2; | ||
| 98 | + polyhedraVertexFormat["aHue"] = Property::FLOAT; | ||
| 99 | + PropertyBuffer polyhedraVertices = PropertyBuffer::New( PropertyBuffer::STATIC, polyhedraVertexFormat, numSides ); | ||
| 100 | + polyhedraVertices.SetData(polyhedraVertexData); | ||
| 101 | + | ||
| 102 | + // Create the geometry object | ||
| 103 | + Geometry polyhedraGeometry = Geometry::New(); | ||
| 104 | + polyhedraGeometry.AddVertexBuffer( polyhedraVertices ); | ||
| 105 | + polyhedraGeometry.SetGeometryType( Geometry::POINTS ); | ||
| 106 | + | ||
| 107 | + return polyhedraGeometry; | ||
| 108 | +} | ||
| 109 | + | ||
| 110 | +} // anonymous namespace | ||
| 111 | + | ||
| 112 | +// This example shows how to use a simple mesh | ||
| 113 | +// | ||
| 114 | +class ExampleController : public ConnectionTracker | ||
| 115 | +{ | ||
| 116 | +public: | ||
| 117 | + | ||
| 118 | + /** | ||
| 119 | + * The example controller constructor. | ||
| 120 | + * @param[in] application The application instance | ||
| 121 | + */ | ||
| 122 | + ExampleController( Application& application ) | ||
| 123 | + : mApplication( application ) | ||
| 124 | + { | ||
| 125 | + // Connect to the Application's Init signal | ||
| 126 | + mApplication.InitSignal().Connect( this, &ExampleController::Create ); | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + /** | ||
| 130 | + * The example controller destructor | ||
| 131 | + */ | ||
| 132 | + ~ExampleController() | ||
| 133 | + { | ||
| 134 | + // Nothing to do here; | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + /** | ||
| 138 | + * Invoked upon creation of application | ||
| 139 | + * @param[in] application The application instance | ||
| 140 | + */ | ||
| 141 | + void Create( Application& application ) | ||
| 142 | + { | ||
| 143 | + Stage stage = Stage::GetCurrent(); | ||
| 144 | + stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | ||
| 145 | + | ||
| 146 | + mStageSize = stage.GetSize(); | ||
| 147 | + | ||
| 148 | + // The Init signal is received once (only) during the Application lifetime | ||
| 149 | + | ||
| 150 | + // Hide the indicator bar | ||
| 151 | + application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | ||
| 152 | + | ||
| 153 | + mImage = ResourceImage::New( MATERIAL_SAMPLE ); | ||
| 154 | + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | ||
| 155 | + mSampler1 = Sampler::New(mImage, "sTexture1"); | ||
| 156 | + mSampler2 = Sampler::New(image, "sTexture2"); | ||
| 157 | + | ||
| 158 | + mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | ||
| 159 | + | ||
| 160 | + mMaterial = Material::New( mShader ); | ||
| 161 | + mMaterial.AddSampler( mSampler1 ); | ||
| 162 | + mMaterial.AddSampler( mSampler2 ); | ||
| 163 | + | ||
| 164 | + mGeometry = CreateGeometry(); | ||
| 165 | + | ||
| 166 | + mRenderer = Renderer::New( mGeometry, mMaterial ); | ||
| 167 | + | ||
| 168 | + mMeshActor = Actor::New(); | ||
| 169 | + mMeshActor.AddRenderer( mRenderer ); | ||
| 170 | + mMeshActor.SetSize(200, 200); | ||
| 171 | + | ||
| 172 | + Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "fade-color", Color::GREEN ); | ||
| 173 | + mMeshActor.AddUniformMapping( fadeColorIndex, std::string("uFadeColor") ); | ||
| 174 | + | ||
| 175 | + fadeColorIndex = mRenderer.RegisterProperty( "fade-color", Color::MAGENTA ); | ||
| 176 | + mRenderer.AddUniformMapping( fadeColorIndex, std::string("uFadeColor" ) ); | ||
| 177 | + mRenderer.SetDepthIndex(0); | ||
| 178 | + | ||
| 179 | + mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | ||
| 180 | + mMeshActor.SetAnchorPoint( AnchorPoint::CENTER ); | ||
| 181 | + stage.Add( mMeshActor ); | ||
| 182 | + | ||
| 183 | + Animation animation = Animation::New(15); | ||
| 184 | + KeyFrames keyFrames = KeyFrames::New(); | ||
| 185 | + keyFrames.Add(0.0f, Vector4::ZERO); | ||
| 186 | + keyFrames.Add(1.0f, Vector4( 1.0f, 0.0f, 1.0f, 1.0f )); | ||
| 187 | + | ||
| 188 | + animation.RotateBy( mMeshActor, Degree(360), Vector3::ZAXIS ); | ||
| 189 | + | ||
| 190 | + animation.SetLooping(true); | ||
| 191 | + animation.Play(); | ||
| 192 | + | ||
| 193 | + stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | ||
| 194 | + } | ||
| 195 | + | ||
| 196 | + /** | ||
| 197 | + * Invoked whenever the quit button is clicked | ||
| 198 | + * @param[in] button the quit button | ||
| 199 | + */ | ||
| 200 | + bool OnQuitButtonClicked( Toolkit::Button button ) | ||
| 201 | + { | ||
| 202 | + // quit the application | ||
| 203 | + mApplication.Quit(); | ||
| 204 | + return true; | ||
| 205 | + } | ||
| 206 | + | ||
| 207 | + void OnKeyEvent(const KeyEvent& event) | ||
| 208 | + { | ||
| 209 | + if(event.state == KeyEvent::Down) | ||
| 210 | + { | ||
| 211 | + if( IsKey( event, Dali::DALI_KEY_ESCAPE) || IsKey( event, Dali::DALI_KEY_BACK) ) | ||
| 212 | + { | ||
| 213 | + mApplication.Quit(); | ||
| 214 | + } | ||
| 215 | + } | ||
| 216 | + } | ||
| 217 | + | ||
| 218 | +private: | ||
| 219 | + | ||
| 220 | + Application& mApplication; ///< Application instance | ||
| 221 | + Vector3 mStageSize; ///< The size of the stage | ||
| 222 | + | ||
| 223 | + Image mImage; | ||
| 224 | + Sampler mSampler1; | ||
| 225 | + Sampler mSampler2; | ||
| 226 | + Shader mShader; | ||
| 227 | + Material mMaterial; | ||
| 228 | + Geometry mGeometry; | ||
| 229 | + Renderer mRenderer; | ||
| 230 | + Actor mMeshActor; | ||
| 231 | + Renderer mRenderer2; | ||
| 232 | + Actor mMeshActor2; | ||
| 233 | + Timer mChangeImageTimer; | ||
| 234 | +}; | ||
| 235 | + | ||
| 236 | +void RunTest( Application& application ) | ||
| 237 | +{ | ||
| 238 | + ExampleController test( application ); | ||
| 239 | + | ||
| 240 | + application.MainLoop(); | ||
| 241 | +} | ||
| 242 | + | ||
| 243 | +// Entry point for Linux & SLP applications | ||
| 244 | +// | ||
| 245 | +int main( int argc, char **argv ) | ||
| 246 | +{ | ||
| 247 | + Application application = Application::New( &argc, &argv ); | ||
| 248 | + | ||
| 249 | + RunTest( application ); | ||
| 250 | + | ||
| 251 | + return 0; | ||
| 252 | +} |
examples/mesh/mesh-example.cpp renamed to examples/textured-mesh/textured-mesh-example.cpp
| @@ -27,6 +27,7 @@ using namespace Dali; | @@ -27,6 +27,7 @@ using namespace Dali; | ||
| 27 | namespace | 27 | namespace |
| 28 | { | 28 | { |
| 29 | const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); | 29 | const char* MATERIAL_SAMPLE( DALI_IMAGE_DIR "gallery-small-48.jpg" ); |
| 30 | +const char* MATERIAL_SAMPLE2( DALI_IMAGE_DIR "gallery-medium-19.jpg" ); | ||
| 30 | 31 | ||
| 31 | #define MAKE_SHADER(A)#A | 32 | #define MAKE_SHADER(A)#A |
| 32 | 33 | ||
| @@ -50,9 +51,9 @@ void main() | @@ -50,9 +51,9 @@ void main() | ||
| 50 | 51 | ||
| 51 | const char* FRAGMENT_SHADER = MAKE_SHADER( | 52 | const char* FRAGMENT_SHADER = MAKE_SHADER( |
| 52 | varying mediump vec2 vTexCoord; | 53 | varying mediump vec2 vTexCoord; |
| 53 | -uniform lowp vec4 uColor; | 54 | +uniform lowp vec4 uColor; |
| 54 | uniform sampler2D sTexture; | 55 | uniform sampler2D sTexture; |
| 55 | -uniform lowp vec4 uFadeColor; | 56 | +uniform lowp vec4 uFadeColor; |
| 56 | 57 | ||
| 57 | void main() | 58 | void main() |
| 58 | { | 59 | { |
| @@ -62,7 +63,6 @@ void main() | @@ -62,7 +63,6 @@ void main() | ||
| 62 | 63 | ||
| 63 | Geometry CreateGeometry() | 64 | Geometry CreateGeometry() |
| 64 | { | 65 | { |
| 65 | - | ||
| 66 | // Create vertices | 66 | // Create vertices |
| 67 | const float halfQuadSize = .5f; | 67 | const float halfQuadSize = .5f; |
| 68 | struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; | 68 | struct TexturedQuadVertex { Vector2 position; Vector2 textureCoordinates; }; |
| @@ -74,7 +74,7 @@ Geometry CreateGeometry() | @@ -74,7 +74,7 @@ Geometry CreateGeometry() | ||
| 74 | 74 | ||
| 75 | Property::Map texturedQuadVertexFormat; | 75 | Property::Map texturedQuadVertexFormat; |
| 76 | texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; | 76 | texturedQuadVertexFormat["aPosition"] = Property::VECTOR2; |
| 77 | - texturedQuadVertexFormat["aVertexCoord"] = Property::VECTOR2; | 77 | + texturedQuadVertexFormat["aTexCoord"] = Property::VECTOR2; |
| 78 | PropertyBuffer texturedQuadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, texturedQuadVertexFormat, 4 ); | 78 | PropertyBuffer texturedQuadVertices = PropertyBuffer::New( PropertyBuffer::STATIC, texturedQuadVertexFormat, 4 ); |
| 79 | texturedQuadVertices.SetData(texturedQuadVertexData); | 79 | texturedQuadVertices.SetData(texturedQuadVertexData); |
| 80 | 80 | ||
| @@ -137,15 +137,22 @@ public: | @@ -137,15 +137,22 @@ public: | ||
| 137 | application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | 137 | application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); |
| 138 | 138 | ||
| 139 | mImage = ResourceImage::New( MATERIAL_SAMPLE ); | 139 | mImage = ResourceImage::New( MATERIAL_SAMPLE ); |
| 140 | - mSampler = Sampler::New(mImage, "sTexture"); | 140 | + mSampler1 = Sampler::New(mImage, "sTexture"); |
| 141 | + | ||
| 142 | + Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | ||
| 143 | + mSampler2 = Sampler::New(image, "sTexture"); | ||
| 144 | + | ||
| 141 | mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | 145 | mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); |
| 142 | 146 | ||
| 143 | - mMaterial = Material::New( mShader ); | ||
| 144 | - mMaterial.AddSampler( mSampler ); | 147 | + mMaterial1 = Material::New( mShader ); |
| 148 | + mMaterial1.AddSampler( mSampler1 ); | ||
| 149 | + | ||
| 150 | + mMaterial2 = Material::New( mShader ); | ||
| 151 | + mMaterial2.AddSampler( mSampler2); | ||
| 145 | 152 | ||
| 146 | mGeometry = CreateGeometry(); | 153 | mGeometry = CreateGeometry(); |
| 147 | 154 | ||
| 148 | - mRenderer = Renderer::New( mGeometry, mMaterial ); | 155 | + mRenderer = Renderer::New( mGeometry, mMaterial1 ); |
| 149 | 156 | ||
| 150 | mMeshActor = Actor::New(); | 157 | mMeshActor = Actor::New(); |
| 151 | mMeshActor.AddRenderer( mRenderer ); | 158 | mMeshActor.AddRenderer( mRenderer ); |
| @@ -162,8 +169,7 @@ public: | @@ -162,8 +169,7 @@ public: | ||
| 162 | mMeshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER ); | 169 | mMeshActor.SetAnchorPoint( AnchorPoint::TOP_CENTER ); |
| 163 | stage.Add( mMeshActor ); | 170 | stage.Add( mMeshActor ); |
| 164 | 171 | ||
| 165 | - | ||
| 166 | - mRenderer2 = Renderer::New( mGeometry, mMaterial ); | 172 | + mRenderer2 = Renderer::New( mGeometry, mMaterial2 ); |
| 167 | 173 | ||
| 168 | mMeshActor2 = Actor::New(); | 174 | mMeshActor2 = Actor::New(); |
| 169 | mMeshActor2.AddRenderer( mRenderer2 ); | 175 | mMeshActor2.AddRenderer( mRenderer2 ); |
| @@ -174,7 +180,7 @@ public: | @@ -174,7 +180,7 @@ public: | ||
| 174 | mMeshActor2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor") ); | 180 | mMeshActor2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor") ); |
| 175 | 181 | ||
| 176 | mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO ); | 182 | mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO ); |
| 177 | - mRenderer2.RegisterProperty( "winning-formula", 8008.135f ); | 183 | + mRenderer2.RegisterProperty( "a-coefficient", 0.008f ); |
| 178 | fadeColorIndex2 = mRenderer2.RegisterProperty( "another-fade-color", Color::GREEN ); | 184 | fadeColorIndex2 = mRenderer2.RegisterProperty( "another-fade-color", Color::GREEN ); |
| 179 | mRenderer2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor" ) ); | 185 | mRenderer2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor" ) ); |
| 180 | mRenderer2.SetDepthIndex(0); | 186 | mRenderer2.SetDepthIndex(0); |
| @@ -183,7 +189,6 @@ public: | @@ -183,7 +189,6 @@ public: | ||
| 183 | mMeshActor2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); | 189 | mMeshActor2.SetAnchorPoint( AnchorPoint::BOTTOM_CENTER ); |
| 184 | stage.Add( mMeshActor2 ); | 190 | stage.Add( mMeshActor2 ); |
| 185 | 191 | ||
| 186 | - | ||
| 187 | Animation animation = Animation::New(5); | 192 | Animation animation = Animation::New(5); |
| 188 | KeyFrames keyFrames = KeyFrames::New(); | 193 | KeyFrames keyFrames = KeyFrames::New(); |
| 189 | keyFrames.Add(0.0f, Vector4::ZERO); | 194 | keyFrames.Add(0.0f, Vector4::ZERO); |
| @@ -229,14 +234,17 @@ private: | @@ -229,14 +234,17 @@ private: | ||
| 229 | Vector3 mStageSize; ///< The size of the stage | 234 | Vector3 mStageSize; ///< The size of the stage |
| 230 | 235 | ||
| 231 | Image mImage; | 236 | Image mImage; |
| 232 | - Sampler mSampler; | 237 | + Sampler mSampler1; |
| 238 | + Sampler mSampler2; | ||
| 233 | Shader mShader; | 239 | Shader mShader; |
| 234 | - Material mMaterial; | 240 | + Material mMaterial1; |
| 241 | + Material mMaterial2; | ||
| 235 | Geometry mGeometry; | 242 | Geometry mGeometry; |
| 236 | Renderer mRenderer; | 243 | Renderer mRenderer; |
| 237 | Actor mMeshActor; | 244 | Actor mMeshActor; |
| 238 | Renderer mRenderer2; | 245 | Renderer mRenderer2; |
| 239 | Actor mMeshActor2; | 246 | Actor mMeshActor2; |
| 247 | + Timer mChangeImageTimer; | ||
| 240 | }; | 248 | }; |
| 241 | 249 | ||
| 242 | void RunTest( Application& application ) | 250 | void RunTest( Application& application ) |