First result
This commit is contained in:
parent
9096f79f5a
commit
93e171ec5b
8
assets/color-shader.fragment
Executable file
8
assets/color-shader.fragment
Executable file
@ -0,0 +1,8 @@
|
||||
precision mediump float;
|
||||
|
||||
uniform vec4 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = Color;
|
||||
}
|
8
assets/color-shader.vertex
Executable file
8
assets/color-shader.vertex
Executable file
@ -0,0 +1,8 @@
|
||||
attribute vec3 vPosition;
|
||||
|
||||
uniform mat4 ProjectionMatrix;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = ProjectionMatrix * vec4(vPosition.xyz, 1.0);
|
||||
}
|
11
assets/particle-shader.fragment
Executable file
11
assets/particle-shader.fragment
Executable file
@ -0,0 +1,11 @@
|
||||
precision mediump float;
|
||||
|
||||
varying vec2 texCoord;
|
||||
|
||||
uniform sampler2D Texture;
|
||||
uniform vec4 Color;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(Texture,texCoord) * Color;
|
||||
}
|
12
assets/particle-shader.vertex
Executable file
12
assets/particle-shader.vertex
Executable file
@ -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;
|
||||
}
|
BIN
assets/spark.png
Executable file
BIN
assets/spark.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 4.2 KiB |
100
assets/sparkler.json
Executable file
100
assets/sparkler.json
Executable file
@ -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 ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
90
assets/test.json
Executable file
90
assets/test.json
Executable file
@ -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 ]
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
@ -6,5 +6,5 @@ uniform sampler2D Texture;
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_FragColor = texture2D(Texture,texCoord).rgba
|
||||
gl_FragColor = texture2D(Texture,texCoord);
|
||||
}
|
@ -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;
|
||||
}
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "include/Engine.h"
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
|
||||
TMyApplication* Application;
|
||||
|
||||
|
||||
@ -34,32 +36,53 @@ void TMyApplication::InnerInit()
|
||||
srand (static_cast<size_t>(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::InnerOnMouseDown(TMouseState& mouseState)
|
||||
{
|
||||
if (mouseState.LeftButtonPressed)
|
||||
{
|
||||
sparkler.setCoords({ (float)mouseState.X, (float)mouseState.Y, 0 });
|
||||
}
|
||||
|
||||
void TMyApplication::InnerOnTapUp(Vector2f p)
|
||||
else if (mouseState.RightButtonPressed)
|
||||
{
|
||||
if (sparkler.isSpawning())
|
||||
{
|
||||
sparkler.stopSpawn();
|
||||
}
|
||||
|
||||
void TMyApplication::InnerOnTapUpAfterMove(Vector2f p)
|
||||
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);
|
||||
}
|
@ -39,6 +39,8 @@ extern boost::signals2::signal<void()> 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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user