diff --git a/assets/color-shader.fragment b/assets/color-shader.fragment new file mode 100755 index 0000000..3741a4a --- /dev/null +++ b/assets/color-shader.fragment @@ -0,0 +1,8 @@ +precision mediump float; + +uniform vec4 Color; + +void main() +{ + gl_FragColor = Color; +} \ No newline at end of file diff --git a/assets/color-shader.vertex b/assets/color-shader.vertex new file mode 100755 index 0000000..5f66f46 --- /dev/null +++ b/assets/color-shader.vertex @@ -0,0 +1,8 @@ +attribute vec3 vPosition; + +uniform mat4 ProjectionMatrix; + +void main() +{ + gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0); +} \ No newline at end of file diff --git a/assets/particle-shader.fragment b/assets/particle-shader.fragment new file mode 100755 index 0000000..47d8a90 --- /dev/null +++ b/assets/particle-shader.fragment @@ -0,0 +1,11 @@ +precision mediump float; + +varying vec2 texCoord; + +uniform sampler2D Texture; +uniform vec4 Color; + +void main() +{ + gl_FragColor = texture2D(Texture,texCoord) * Color; +} \ No newline at end of file diff --git a/assets/particle-shader.vertex b/assets/particle-shader.vertex new file mode 100755 index 0000000..db9ad25 --- /dev/null +++ b/assets/particle-shader.vertex @@ -0,0 +1,12 @@ +attribute vec3 vPosition; +attribute vec2 vTexCoord; + +varying vec2 texCoord; + +uniform mat4 ProjectionMatrix; + +void main() +{ + gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0); + texCoord = vTexCoord; +} \ No newline at end of file diff --git a/assets/spark.png b/assets/spark.png new file mode 100755 index 0000000..ad4b3b1 Binary files /dev/null and b/assets/spark.png differ diff --git a/assets/sparkler.json b/assets/sparkler.json new file mode 100755 index 0000000..e33d6ee --- /dev/null +++ b/assets/sparkler.json @@ -0,0 +1,100 @@ +{ + "name": "Sparkler - бенгальский огонь", + + "emitters": + [ + { + "name": "Spark", + + "maxParticles": 300, + "preloading": 100, + "texturePath": "spark.png", + + "hasInertion": "false", + "gravity": [0, -2, 0], + + "spawnRange_system": "PARTICLE_BIRTH", + + "spawnTotal": + { + "interpolation": "LINEAR_SPLINE", + "isLooped": "false", + "timeline": + [ + { + "t": 0.000, + "value": 0 + }, + { + "t": 0.001, + "value": 0 + }, + { + "t": 9.999, + "value": 300 + }, + { + "t": 10.000, + "value": 300 + } + ] + }, + + "spawnRange": + { + "value": [ 0, 0, 360, 180 ] + }, + + "lifeTime": + { + "min": 0.100, + "max": 1.000 + }, + + "coords_system": "PARTICLE_BIRTH", + "coords_axis_system": "PARTICLE_EFFECT", + "rotation_system": "PARTICLE_BIRTH", + + "coords": + { + "interpolation": "CUBIC_SPLINE", + "isLooped": "false", + "timeline": + [ + { + "t": 0.000, + "min": [ -1, -1, -1 ], + "max": [ 1, 1, 1 ] + }, + { + "t": 1.000, + "min": [ -2, -2, -2 ], + "max": [ 2, 2, 2 ] + } + ] + }, + + "rotation": + { + "value": [ 0, 0, 0 ] + }, + + "scale": + { + "interpolation": "DISCRETE", + "isLooped": "false", + "timeline": + [ + { + "value": [ 5, 5 ] + } + ] + }, + + "color": + { + "value": [ 1, 1, 0, 1 ] + } + } + ] +} \ No newline at end of file diff --git a/assets/test.json b/assets/test.json new file mode 100755 index 0000000..c881243 --- /dev/null +++ b/assets/test.json @@ -0,0 +1,90 @@ +{ + "name": "Sparkler - бенгальский огонь", + + "emitters": + [ + { + "name": "Spark", + + "maxParticles": 300, + "preloading": 100, + "texturePath": "spark.png", + + "hasInertion": "false", + "gravity": [0, 0, 0], + + "spawnRange_system": "PARTICLE_BIRTH", + + "spawnTotal": + { + "interpolation": "LINEAR_SPLINE", + "isLooped": "false", + "timeline": + [ + { + "t": 0, + "value": 0 + }, + { + "t": 10, + "value": 1000 + } + ] + }, + + "spawnRange": + { + "value": [ 90, 0, 0, 360 ] + }, + + "lifeTime": + { + "min": 0.1, + "max": 0.3 + }, + + "coords_system": "PARTICLE_EFFECT", + "coords_axis_system": "PARTICLE_BIRTH", + "rotation_system": "PARTICLE_EFFECT", + + "coords": + { + "interpolation": "LINEAR_SPLINE", + "isLooped": "false", + "timeline": + [ + { + "t": 0.000, + "value": [ 0, 0, 0 ] + }, + { + "t": 1.000, + "value": [ 0, 0, 400 ] + } + ] + }, + + "rotation": + { + "value": [ 0, 0, 0 ] + }, + + "scale": + { + "interpolation": "DISCRETE", + "isLooped": "false", + "timeline": + [ + { + "value": [ 20, 20 ] + } + ] + }, + + "color": + { + "value": [ 1, 1, 0, 1 ] + } + } + ] +} \ No newline at end of file diff --git a/assets/texture-shader.fragment b/assets/texture-shader.fragment index 5dc7ac8..3778d11 100755 --- a/assets/texture-shader.fragment +++ b/assets/texture-shader.fragment @@ -6,5 +6,5 @@ uniform sampler2D Texture; void main() { - gl_FragColor = texture2D(Texture,texCoord).rgba + gl_FragColor = texture2D(Texture,texCoord); } \ No newline at end of file diff --git a/assets/texture-shader.vertex b/assets/texture-shader.vertex index d927440..db9ad25 100755 --- a/assets/texture-shader.vertex +++ b/assets/texture-shader.vertex @@ -4,10 +4,9 @@ attribute vec2 vTexCoord; varying vec2 texCoord; uniform mat4 ProjectionMatrix; -uniform mat4 ModelViewMatrix; void main() { - gl_Position = ProjectionMatrix * ModelViewMatrix * vec4(vPosition.xyz, 1.0); + gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0); texCoord = vTexCoord; } \ No newline at end of file diff --git a/game/main_code.cpp b/game/main_code.cpp index a0586ec..160cdde 100644 --- a/game/main_code.cpp +++ b/game/main_code.cpp @@ -7,6 +7,8 @@ #include "include/Engine.h" +#include + TMyApplication* Application; @@ -34,32 +36,53 @@ void TMyApplication::InnerInit() srand (static_cast(time(NULL))); ResourceManager->ShaderManager.AddShader("DefaultShader", "texture-shader.vertex", "texture-shader.fragment"); - Renderer->PushShader("DefaultShader"); + ResourceManager->ShaderManager.AddShader("ColorShader", "color-shader.vertex", "color-shader.fragment"); + ResourceManager->ShaderManager.AddShader(ParticleEffect::PARTICLE_SHADER, "particle-shader.vertex", "particle-shader.fragment"); + Renderer->PushShader("ColorShader"); - ResourceManager->FrameManager.AddFrameRenderBuffer("FrameBuffer", Renderer->GetMatrixWidth(), Renderer->GetMatrixHeight()); + float width = Renderer->GetScreenWidth(); + float height = Renderer->GetScreenHeight(); Renderer->SetOrthoProjection(); - + Renderer->PushProjectionMatrix(width, height, -1, 1); + //Renderer->SetFullScreenViewport(); + + boost::property_tree::ptree JSONsource; + boost::property_tree::json_parser::read_json(ST::PathToResources + "test.json", JSONsource); + + sparkler.parse(JSONsource); // parse JSON + + sparkler.load(); // load textures + + sparkler.setCoords({ width / 2, height / 2, 0 }); } void TMyApplication::InnerDeinit() { } -void TMyApplication::InnerOnTapDown(Vector2f p) -{ -} - -void TMyApplication::InnerOnTapUp(Vector2f p) -{ -} - -void TMyApplication::InnerOnTapUpAfterMove(Vector2f p) +void TMyApplication::InnerOnMouseDown(TMouseState& mouseState) { + if (mouseState.LeftButtonPressed) + { + sparkler.setCoords({ (float)mouseState.X, (float)mouseState.Y, 0 }); + } + else if (mouseState.RightButtonPressed) + { + if (sparkler.isSpawning()) + { + sparkler.stopSpawn(); + } + else + { + sparkler.startSpawn(); + } + } } void TMyApplication::InnerOnMove(Vector2f p, Vector2f shift) { + sparkler.setCoords({ p[0], p[1], 0 }); } void TMyApplication::InnerDraw() @@ -69,10 +92,16 @@ void TMyApplication::InnerDraw() glClearColor(0, 0, 0, 0); glClear(GL_COLOR_BUFFER_BIT); - + sparkler.draw(); } void TMyApplication::InnerUpdate(size_t dt) { + if (dt > 50) + { + dt = 50; + } + + sparkler.update(dt / 1000.f); } \ No newline at end of file diff --git a/game/main_code.h b/game/main_code.h index 8cbd313..f63dd5f 100644 --- a/game/main_code.h +++ b/game/main_code.h @@ -39,6 +39,8 @@ extern boost::signals2::signal OnDrawSignal; class TMyApplication : public TApplication { protected: + ParticleEffect sparkler; + public: TMyApplication() : TApplication() { } @@ -50,11 +52,7 @@ public: virtual void InnerUpdate(size_t dt); - virtual void InnerOnTapDown(Vector2f p); - - virtual void InnerOnTapUp(Vector2f p); - - virtual void InnerOnTapUpAfterMove(Vector2f p); + virtual void InnerOnMouseDown(TMouseState& mouseState); virtual void InnerOnMove(Vector2f p, Vector2f shift);