Commit bda3e2def06ef74d4d7a82ef0fdc66be74098fd1
1 parent
661d97a3
Minor Fixes to demos
Change-Id: I089eedc9dc7ca3a14fe3a1b43d7a4e75ebc653ad
Showing
2 changed files
with
57 additions
and
16 deletions
examples/point-mesh/point-mesh-example.cpp
| @@ -37,6 +37,7 @@ attribute highp float aHue; | @@ -37,6 +37,7 @@ attribute highp float aHue; | ||
| 37 | varying mediump vec2 vTexCoord; | 37 | varying mediump vec2 vTexCoord; |
| 38 | uniform mediump mat4 uMvpMatrix; | 38 | uniform mediump mat4 uMvpMatrix; |
| 39 | uniform mediump vec3 uSize; | 39 | uniform mediump vec3 uSize; |
| 40 | +uniform mediump float uPointSize; | ||
| 40 | uniform lowp vec4 uFadeColor; | 41 | uniform lowp vec4 uFadeColor; |
| 41 | varying mediump vec3 vVertexColor; | 42 | varying mediump vec3 vVertexColor; |
| 42 | varying mediump float vHue; | 43 | varying mediump float vHue; |
| @@ -51,11 +52,11 @@ vec3 hsv2rgb(vec3 c) | @@ -51,11 +52,11 @@ vec3 hsv2rgb(vec3 c) | ||
| 51 | void main() | 52 | void main() |
| 52 | { | 53 | { |
| 53 | mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); | 54 | mediump vec4 vertexPosition = vec4(aPosition, 0.0, 1.0); |
| 54 | - vertexPosition.xyz *= uSize; | 55 | + vertexPosition.xyz *= (uSize-uPointSize); |
| 55 | vertexPosition = uMvpMatrix * vertexPosition; | 56 | vertexPosition = uMvpMatrix * vertexPosition; |
| 56 | - vVertexColor = hsv2rgb( vec3( aHue, 0.6, 0.7 ) ); | 57 | + vVertexColor = hsv2rgb( vec3( aHue, 0.7, 1.0 ) ); |
| 57 | vHue = aHue; | 58 | vHue = aHue; |
| 58 | - gl_PointSize = 80.0; | 59 | + gl_PointSize = uPointSize; |
| 59 | gl_Position = vertexPosition; | 60 | gl_Position = vertexPosition; |
| 60 | } | 61 | } |
| 61 | ); | 62 | ); |
| @@ -85,10 +86,11 @@ Geometry CreateGeometry() | @@ -85,10 +86,11 @@ Geometry CreateGeometry() | ||
| 85 | Vertex polyhedraVertexData[numSides]; | 86 | Vertex polyhedraVertexData[numSides]; |
| 86 | float angle=0; | 87 | float angle=0; |
| 87 | float sectorAngle = 2.0f * Math::PI / (float) numSides; | 88 | float sectorAngle = 2.0f * Math::PI / (float) numSides; |
| 89 | + | ||
| 88 | for(unsigned int i=0; i<numSides; ++i) | 90 | for(unsigned int i=0; i<numSides; ++i) |
| 89 | { | 91 | { |
| 90 | - polyhedraVertexData[i].position.x = sinf(angle); | ||
| 91 | - polyhedraVertexData[i].position.y = cosf(angle); | 92 | + polyhedraVertexData[i].position.x = sinf(angle)*0.5f; |
| 93 | + polyhedraVertexData[i].position.y = cosf(angle)*0.5f; | ||
| 92 | polyhedraVertexData[i].hue = angle / ( 2.0f * Math::PI); | 94 | polyhedraVertexData[i].hue = angle / ( 2.0f * Math::PI); |
| 93 | angle += sectorAngle; | 95 | angle += sectorAngle; |
| 94 | } | 96 | } |
| @@ -167,13 +169,15 @@ public: | @@ -167,13 +169,15 @@ public: | ||
| 167 | 169 | ||
| 168 | mMeshActor = Actor::New(); | 170 | mMeshActor = Actor::New(); |
| 169 | mMeshActor.AddRenderer( mRenderer ); | 171 | mMeshActor.AddRenderer( mRenderer ); |
| 170 | - mMeshActor.SetSize(200, 200); | 172 | + mMeshActor.SetSize(400, 400); |
| 171 | 173 | ||
| 172 | Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "fade-color", Color::GREEN ); | 174 | Property::Index fadeColorIndex = mMeshActor.RegisterProperty( "fade-color", Color::GREEN ); |
| 173 | mMeshActor.AddUniformMapping( fadeColorIndex, std::string("uFadeColor") ); | 175 | mMeshActor.AddUniformMapping( fadeColorIndex, std::string("uFadeColor") ); |
| 174 | 176 | ||
| 175 | fadeColorIndex = mRenderer.RegisterProperty( "fade-color", Color::MAGENTA ); | 177 | fadeColorIndex = mRenderer.RegisterProperty( "fade-color", Color::MAGENTA ); |
| 178 | + Property::Index pointSizeIndex = mRenderer.RegisterProperty( "point-size", 80.0f ); | ||
| 176 | mRenderer.AddUniformMapping( fadeColorIndex, std::string("uFadeColor" ) ); | 179 | mRenderer.AddUniformMapping( fadeColorIndex, std::string("uFadeColor" ) ); |
| 180 | + mRenderer.AddUniformMapping( pointSizeIndex, std::string("uPointSize" ) ); | ||
| 177 | mRenderer.SetDepthIndex(0); | 181 | mRenderer.SetDepthIndex(0); |
| 178 | 182 | ||
| 179 | mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); | 183 | mMeshActor.SetParentOrigin( ParentOrigin::CENTER ); |
examples/textured-mesh/textured-mesh-example.cpp
| @@ -93,6 +93,14 @@ Geometry CreateGeometry() | @@ -93,6 +93,14 @@ Geometry CreateGeometry() | ||
| 93 | return texturedQuadGeometry; | 93 | return texturedQuadGeometry; |
| 94 | } | 94 | } |
| 95 | 95 | ||
| 96 | +/** | ||
| 97 | + * Sinusoidal curve starting at zero with 2 cycles | ||
| 98 | + */ | ||
| 99 | +float AlphaFunctionSineX2(float progress) | ||
| 100 | +{ | ||
| 101 | + return 0.5f - cosf(progress * 4.0f * Math::PI) * 0.5f; | ||
| 102 | +} | ||
| 103 | + | ||
| 96 | } // anonymous namespace | 104 | } // anonymous namespace |
| 97 | 105 | ||
| 98 | // This example shows how to use a simple mesh | 106 | // This example shows how to use a simple mesh |
| @@ -126,29 +134,28 @@ public: | @@ -126,29 +134,28 @@ public: | ||
| 126 | */ | 134 | */ |
| 127 | void Create( Application& application ) | 135 | void Create( Application& application ) |
| 128 | { | 136 | { |
| 137 | + // The Init signal is received once (only) during the Application lifetime | ||
| 138 | + | ||
| 129 | Stage stage = Stage::GetCurrent(); | 139 | Stage stage = Stage::GetCurrent(); |
| 130 | stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); | 140 | stage.KeyEventSignal().Connect(this, &ExampleController::OnKeyEvent); |
| 131 | 141 | ||
| 132 | mStageSize = stage.GetSize(); | 142 | mStageSize = stage.GetSize(); |
| 133 | 143 | ||
| 134 | - // The Init signal is received once (only) during the Application lifetime | ||
| 135 | - | ||
| 136 | // Hide the indicator bar | 144 | // Hide the indicator bar |
| 137 | application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); | 145 | application.GetWindow().ShowIndicator( Dali::Window::INVISIBLE ); |
| 138 | 146 | ||
| 139 | - mImage = ResourceImage::New( MATERIAL_SAMPLE ); | 147 | + mImage = ResourceImage::New( MATERIAL_SAMPLE, ResourceImage::ON_DEMAND, Image::NEVER ); |
| 140 | mSampler1 = Sampler::New(mImage, "sTexture"); | 148 | mSampler1 = Sampler::New(mImage, "sTexture"); |
| 141 | 149 | ||
| 142 | Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); | 150 | Image image = ResourceImage::New( MATERIAL_SAMPLE2 ); |
| 143 | mSampler2 = Sampler::New(image, "sTexture"); | 151 | mSampler2 = Sampler::New(image, "sTexture"); |
| 144 | 152 | ||
| 145 | mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); | 153 | mShader = Shader::New( VERTEX_SHADER, FRAGMENT_SHADER ); |
| 146 | - | ||
| 147 | mMaterial1 = Material::New( mShader ); | 154 | mMaterial1 = Material::New( mShader ); |
| 148 | mMaterial1.AddSampler( mSampler1 ); | 155 | mMaterial1.AddSampler( mSampler1 ); |
| 149 | 156 | ||
| 150 | mMaterial2 = Material::New( mShader ); | 157 | mMaterial2 = Material::New( mShader ); |
| 151 | - mMaterial2.AddSampler( mSampler2); | 158 | + mMaterial2.AddSampler( mSampler2 ); |
| 152 | 159 | ||
| 153 | mGeometry = CreateGeometry(); | 160 | mGeometry = CreateGeometry(); |
| 154 | 161 | ||
| @@ -181,7 +188,7 @@ public: | @@ -181,7 +188,7 @@ public: | ||
| 181 | 188 | ||
| 182 | mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO ); | 189 | mRenderer2.RegisterProperty( "a-n-other-property", Vector3::ZERO ); |
| 183 | mRenderer2.RegisterProperty( "a-coefficient", 0.008f ); | 190 | mRenderer2.RegisterProperty( "a-coefficient", 0.008f ); |
| 184 | - fadeColorIndex2 = mRenderer2.RegisterProperty( "another-fade-color", Color::GREEN ); | 191 | + fadeColorIndex2 = mRenderer2.RegisterProperty( "another-fade-color", Color::BLUE ); |
| 185 | mRenderer2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor" ) ); | 192 | mRenderer2.AddUniformMapping( fadeColorIndex2, std::string("uFadeColor" ) ); |
| 186 | mRenderer2.SetDepthIndex(0); | 193 | mRenderer2.SetDepthIndex(0); |
| 187 | 194 | ||
| @@ -192,20 +199,50 @@ public: | @@ -192,20 +199,50 @@ public: | ||
| 192 | Animation animation = Animation::New(5); | 199 | Animation animation = Animation::New(5); |
| 193 | KeyFrames keyFrames = KeyFrames::New(); | 200 | KeyFrames keyFrames = KeyFrames::New(); |
| 194 | keyFrames.Add(0.0f, Vector4::ZERO); | 201 | keyFrames.Add(0.0f, Vector4::ZERO); |
| 195 | - keyFrames.Add(1.0f, Vector4( 1.0f, 0.0f, 1.0f, 1.0f )); | 202 | + keyFrames.Add(1.0f, Vector4( Color::GREEN )); |
| 196 | 203 | ||
| 197 | KeyFrames keyFrames2 = KeyFrames::New(); | 204 | KeyFrames keyFrames2 = KeyFrames::New(); |
| 198 | keyFrames2.Add(0.0f, Vector4::ZERO); | 205 | keyFrames2.Add(0.0f, Vector4::ZERO); |
| 199 | - keyFrames2.Add(1.0f, Color::GREEN); | 206 | + keyFrames2.Add(1.0f, Color::MAGENTA); |
| 200 | 207 | ||
| 201 | - animation.AnimateBetween( Property( mRenderer, fadeColorIndex ), keyFrames, AlphaFunction(AlphaFunction::EASE_OUT_SINE) ); | ||
| 202 | - animation.AnimateBetween( Property( mRenderer2, fadeColorIndex2 ), keyFrames2, AlphaFunction(AlphaFunction::EASE_IN_SINE) ); | 208 | + animation.AnimateBetween( Property( mRenderer, fadeColorIndex ), keyFrames, AlphaFunction(AlphaFunction::SIN) ); |
| 209 | + animation.AnimateBetween( Property( mRenderer2, fadeColorIndex2 ), keyFrames2, AlphaFunction(AlphaFunctionSineX2) ); | ||
| 203 | animation.SetLooping(true); | 210 | animation.SetLooping(true); |
| 204 | animation.Play(); | 211 | animation.Play(); |
| 205 | 212 | ||
| 206 | stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; | 213 | stage.SetBackgroundColor(Vector4(0.0f, 0.2f, 0.2f, 1.0f));; |
| 207 | } | 214 | } |
| 208 | 215 | ||
| 216 | + BufferImage CreateBufferImage() | ||
| 217 | + { | ||
| 218 | + BufferImage image = BufferImage::New( 200, 200, Pixel::RGB888 ); | ||
| 219 | + PixelBuffer* pixelBuffer = image.GetBuffer(); | ||
| 220 | + unsigned int stride = image.GetBufferStride(); | ||
| 221 | + for( unsigned int x=0; x<200; x++ ) | ||
| 222 | + { | ||
| 223 | + for( unsigned int y=0; y<200; y++ ) | ||
| 224 | + { | ||
| 225 | + PixelBuffer* pixel = pixelBuffer + y*stride + x*3; | ||
| 226 | + if( ((int)(x/20.0f))%2 + ((int)(y/20.0f)%2) == 1 ) | ||
| 227 | + { | ||
| 228 | + pixel[0]=255; | ||
| 229 | + pixel[1]=0; | ||
| 230 | + pixel[2]=0; | ||
| 231 | + pixel[3]=255; | ||
| 232 | + } | ||
| 233 | + else | ||
| 234 | + { | ||
| 235 | + pixel[0]=0; | ||
| 236 | + pixel[1]=0; | ||
| 237 | + pixel[2]=255; | ||
| 238 | + pixel[3]=255; | ||
| 239 | + } | ||
| 240 | + } | ||
| 241 | + } | ||
| 242 | + image.Update(); | ||
| 243 | + return image; | ||
| 244 | + } | ||
| 245 | + | ||
| 209 | /** | 246 | /** |
| 210 | * Invoked whenever the quit button is clicked | 247 | * Invoked whenever the quit button is clicked |
| 211 | * @param[in] button the quit button | 248 | * @param[in] button the quit button |