forked from oj002/SimpleSFMLEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
AnimatedSprite added and first Shader tested
- Loading branch information
Showing
20 changed files
with
202 additions
and
143 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
#shader vertex | ||
#version 330 core | ||
|
||
layout(location = 0) in vec4 position; | ||
|
||
void main() | ||
{ | ||
gl_Position = position; | ||
} | ||
// transform the vertex position | ||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; | ||
|
||
// transform the texture coordinates | ||
gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; | ||
|
||
#shader fragment | ||
#version 330 core | ||
// forward the vertex color | ||
gl_FrontColor = gl_Color; | ||
} | ||
|
||
layout(location = 0) out vec4 color; | ||
#shader fragment | ||
uniform sampler2D texture; | ||
uniform float pixel_threshold; | ||
|
||
void main() | ||
{ | ||
color = vec4(0.2, 0.3, 0.8, 1.0); | ||
} | ||
float factor = 1.0 / (pixel_threshold + 0.001); | ||
vec2 pos = floor(gl_TexCoord[0].xy * factor + 0.5) / factor; | ||
gl_FragColor = texture2D(texture, pos) * gl_Color; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#pragma once | ||
#include <SFML/Graphics.hpp> | ||
#include <string> | ||
#include <map> | ||
#include <vector> | ||
|
||
namespace sse | ||
{ | ||
class AnimatedSprite : public sf::Sprite | ||
{ | ||
public: | ||
struct Frame | ||
{ | ||
Frame(sf::Texture& texture, float delay) | ||
: m_texture(&texture) | ||
, m_delay(delay) | ||
{ } | ||
sf::Texture* m_texture; | ||
float m_delay; | ||
}; | ||
|
||
std::vector<AnimatedSprite::Frame>& operator[](std::string s) | ||
{ | ||
return m_animations[s]; | ||
} | ||
//void AddAnimation(std::string name); | ||
|
||
void SetActiveAnimation(std::string str) | ||
{ | ||
m_currentAnimation = str; | ||
} | ||
|
||
void Update() | ||
{ | ||
setTexture(*m_animations[m_currentAnimation][m_frameCounter].m_texture); | ||
if (m_currentAnimation != "") | ||
{ | ||
if (m_currentAnimation.find(m_currentAnimation) != m_currentAnimation.back()) | ||
{ | ||
if (m_clock.getElapsedTime().asSeconds() >= m_animations[m_currentAnimation][m_frameCounter].m_delay) | ||
{ | ||
|
||
if (m_animations[m_currentAnimation].size() - 1 > m_frameCounter) | ||
{ | ||
m_frameCounter++; | ||
} | ||
else | ||
{ | ||
m_frameCounter = 0; | ||
} | ||
|
||
setTexture(*m_animations[m_currentAnimation][m_frameCounter].m_texture); | ||
m_clock.restart(); | ||
} | ||
} | ||
} | ||
} | ||
|
||
private: | ||
std::map<std::string, std::vector<AnimatedSprite::Frame> > m_animations; | ||
size_t m_frameCounter = 0; | ||
std::string m_currentAnimation = ""; | ||
sf::Clock m_clock; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
namespace sse | ||
{ | ||
|
||
void AssetManager::LoadTexture(std::string name, std::string path) | ||
{ | ||
sf::Texture tex; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.