From 93e171ec5b5df23363d691885f94d84f920d1835 Mon Sep 17 00:00:00 2001 From: Vladislav Khorev Dev Date: Fri, 22 Dec 2017 23:35:11 +0500 Subject: [PATCH] First result --- assets/color-shader.fragment | 8 +++ assets/color-shader.vertex | 8 +++ assets/particle-shader.fragment | 11 ++++ assets/particle-shader.vertex | 12 ++++ assets/spark.png | Bin 0 -> 4304 bytes assets/sparkler.json | 100 ++++++++++++++++++++++++++++++++ assets/test.json | 90 ++++++++++++++++++++++++++++ assets/texture-shader.fragment | 2 +- assets/texture-shader.vertex | 3 +- game/main_code.cpp | 55 +++++++++++++----- game/main_code.h | 8 +-- 11 files changed, 276 insertions(+), 21 deletions(-) create mode 100755 assets/color-shader.fragment create mode 100755 assets/color-shader.vertex create mode 100755 assets/particle-shader.fragment create mode 100755 assets/particle-shader.vertex create mode 100755 assets/spark.png create mode 100755 assets/sparkler.json create mode 100755 assets/test.json 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 0000000000000000000000000000000000000000..ad4b3b155efe40927171ea370fc421c63f0068ba GIT binary patch literal 4304 zcmb7Gg;Ui3^M2DQ4F^aINFH6%afBcZ(k;g+5^}V{0U|A>lyv7&5{HB!$4PjEh#*KD zh#(yj9`WNdzrWx+v(N7AYi8$pW_M;^n_z0JcZ-sp5&(c(2KqYYH&Nq1kdxl{TA2Uh zO(2G9KF|b!=GV{hW|=oRkGsD40|1Dl1%TumT;3E#X#l{BPypCW0sxg?0KhgDpb{Gl z0F+8FZEaIiFJHKCfS0cykAb!}kKZ$2Pnh>30MN%2WCdGVerJgr?+Feo`65YZ{%Y~V zM_?*E(+T35!{#DHL?a{H%v(xG57Eiv(>EPNOq%jr>on6bSvHaJlM6|)LM+96b!U>0 z_1&k3hxpZc-<{S|6n?vB+ztd}R7qrKlNu7FjWF)VsN`?br<=jI0R#b;3qlw$vexZ# zZVD%-8y@`J7#>##70l z^2O+v7@BnxCEtqT6mYYaG%`d0lYuwL&nAISo?a?}n_-O)_X}9or*QUPcqq2)K{c5D z%)oGbC4iBE1kRZS{yF_4PxExmqr#7v@Dm^?nmY{r>NsWoHMg4sVA;E{mB#&;f-ID-L}AiFf;| z2q4O`H0&x3PjgY3zmatL>&9PB|5z~Pp8WB5WLX`A8lX$e_b(wGPnIum{=!!^YQo!||!X>o7 z0w)mjZeIy2AoLQ;a3}*h9UNyUCLqu!6iFi+(cs(wv|UK+5#oNtJ|AzN#n91FSQD}6 z6W1VUTQs<4i77RuW+_e(k4?$gHD$a=Fq(H2Nw6`7%j}&5J~4O~CL;vYg{7O6ijLTo zS6U}(jh9)UaVl<%htz`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,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);