Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kepler0

Pages: [1] 2
1
General / Re: Circe Shape only moves when variable change or key press?
« on: December 13, 2017, 07:27:02 am »
There are lots of issues I see in your code, I'll just go through a few:

  • You have 2 variables called AccelX & AccelY, first of all, assuming these are the accelerations, you want to use Ship::PlayerShip.move(Ship::AccelX, Ship::AccelY); instead of just setting the position. Secondly, use sf::Vector's, you're going to find yourself using the sf::Vector constructor with the X and Y for SFML function arguments, which isn't very human readable.
  • Re-organize your classes. In my 3 years of C++, I've never seen a file called "Main.h". You got the .cpp for implementation and .h for declaration down, you just need to start splitting the files up accordingly, for example, your Window class should probably be in Window.h & Window.cpp.
  • Member functions, Object-orientation, Static variables, you seem very confused about these three.
     Remove the static parts from your Ship class and put those stray functions which affect ship movement inside the Ship class, in fact, I would just make a single update function inside the Ship class and put the stuff from Movement() and RotationMovement()
     in there.

I know this isn't codereview, and I know if I didn't say this now, someone else definitely would've, and Arcade already sort of has, but there you go. Object-orientation would be the biggest factor.

2
General / Re: texture.update not working correctly
« on: December 09, 2017, 11:18:50 am »
Textures[0].update(CurrentApp->GetWindow());
inside BackgroundBlur::Tick is capturing what's on the screen, which would be blurred, so it would be re-applying the blur, (which it indeed does). I don't want to blur my entire scene, some things will be in front of the blur, some things behind, I just want the blur to affect anything behind it. Updating the texture only once does work, but if anything changes behind the blur, it won't be shown.

3
General / Re: texture.update not working correctly
« on: December 09, 2017, 09:27:48 am »
:/ Not entirely, since the texture is updating every tick, it'll be copying the blurred frame and blurring it, so the blur will keep layering and the window will always show the start frame. I could fire update once and destroy it whenever I don't need the blur, however I want moving things under the blur to still be moving on the window, even if blurred. Any ideas?

4
General / texture.update not working correctly
« on: December 09, 2017, 06:56:35 am »
I'm trying to make a UI blur using a fragment shader. The current route I'm taking is a sf::Sprite with a constantly updating sf::Texture, then the sf::Sprite is drawn with the shader, but instead the screen is just stuck on a single frame when using the shader.

The constructor:
BackgroundBlur::BackgroundBlur(sf::Vector2f _Position, sf::Vector2f _Size, float _Strength)
        : UIElement(_Position, true)
{
        sf::Texture _Texture;

        Textures.push_back(_Texture);

        sf::Sprite _Sprite;
        _Sprite.setTexture(Textures[0]);
        _Sprite.setTextureRect(sf::IntRect(_Position.x, _Position.y, _Size.x, _Size.y));

        Sprites.push_back(_Sprite);

        Blur.loadFromFile("Resource/Data/Shaders/Blur.frag", sf::Shader::Fragment);

        Blur.setUniform("blur_radius", sf::Glsl::Vec2(Strength, Strength));
        Blur.setUniform("texture", Textures[0]);
}

The sf::Texture is created here:
void BackgroundBlur::BeginPlay()
{
        Textures[0].create
        (
                CurrentApp->GetWindow().getSize().x,
                CurrentApp->GetWindow().getSize().y
        );
}

And the problem resides here, not updating, it works, but no blur:
void BackgroundBlur::Tick(float _DeltaTime)
{
        Textures[0].update(CurrentApp->GetWindow());
}

This is the draw function, if I remove the sf::Shader from the draw arguments, it works again, but there isn't blur:
void BackgroundBlur::Draw(sf::RenderTarget & _Target, sf::RenderStates _States) const
{
        _Target.draw(Sprites[0], &Blur);
}

I've tried adding
Blur.setUniform("texture", Textures[0]);
to the Tick function, however it seems to do nothing.

Also, the fragment shader I am using is
uniform sampler2D texture;
uniform vec2 blur_radius;

void main() {
    vec2 textureCoordinates = gl_TexCoord[0].xy;
    vec4 color = vec4(0.0);
    color += texture2D(texture, textureCoordinates - 10.0 * blur_radius) * 0.0012;
    color += texture2D(texture, textureCoordinates - 9.0 * blur_radius) * 0.0015;
    color += texture2D(texture, textureCoordinates - 8.0 * blur_radius) * 0.0038;
    color += texture2D(texture, textureCoordinates - 7.0 * blur_radius) * 0.0087;
    color += texture2D(texture, textureCoordinates - 6.0 * blur_radius) * 0.0180;
    color += texture2D(texture, textureCoordinates - 5.0 * blur_radius) * 0.0332;
    color += texture2D(texture, textureCoordinates - 4.0 * blur_radius) * 0.0547;
    color += texture2D(texture, textureCoordinates - 3.0 * blur_radius) * 0.0807;
    color += texture2D(texture, textureCoordinates - 2.0 * blur_radius) * 0.1065;
    color += texture2D(texture, textureCoordinates - blur_radius) * 0.1258;
    color += texture2D(texture, textureCoordinates) * 0.1330;
    color += texture2D(texture, textureCoordinates + blur_radius) * 0.1258;
    color += texture2D(texture, textureCoordinates + 2.0 * blur_radius) * 0.1065;
    color += texture2D(texture, textureCoordinates + 3.0 * blur_radius) * 0.0807;
    color += texture2D(texture, textureCoordinates + 4.0 * blur_radius) * 0.0547;
    color += texture2D(texture, textureCoordinates + 5.0 * blur_radius) * 0.0332;
    color += texture2D(texture, textureCoordinates + 6.0 * blur_radius) * 0.0180;
    color += texture2D(texture, textureCoordinates - 7.0 * blur_radius) * 0.0087;
    color += texture2D(texture, textureCoordinates - 8.0 * blur_radius) * 0.0038;
    color += texture2D(texture, textureCoordinates - 9.0 * blur_radius) * 0.0015;
    color += texture2D(texture, textureCoordinates - 10.0 * blur_radius) * 0.0012;
    gl_FragColor = color;
}
, taken from https://en.sfml-dev.org/forums/index.php?topic=20155.0

EDIT: I'm so stupid, instead of
Blur.setUniform("texture", Textures[0]);
it should be
Blur.setUniform("texture", sf::Shader::CurrentTexture);

5
General / Re: How should I avoid calling draw every frame?
« on: September 09, 2017, 07:16:04 pm »
Thanks for the advice. I've already got it back up to a smooth stable framerate, but I'm still working on it to maintain an acceptable amount of detail, especially since the minimap can be zoomed in and out.

6
Graphics / Re: How Do I change background color of my window?
« on: September 09, 2017, 06:28:00 pm »
You have 16 posts and all of them are asking how to do basic things.

 :-\

7
Graphics / Re: Why does my shape does not revolve around its center.
« on: September 09, 2017, 06:25:14 pm »
The simplest way to center the origin of anything is to divide the bounds by 2, for example:
object.setOrigin(object.getGlobalBounds().width / 2, object.getGlobalBounds().height / 2);

8
General / How should I avoid calling draw every frame?
« on: September 09, 2017, 06:02:53 pm »
I've recently found out drawing 6000+ Sprites/Shapes is very heavy on performance, and I require advice on how I should begin handling this.

I intend to have an upwards of 1 million Sprites/Shapes in the future, and this can only worsen as I am actually drawing these 6000 sprites/shapes twice (one for the minimap, one for the main view). Obviously ~12000 draw calls every frame is going to slow down any computer, but I'm interested in how VertexArray handled this issue.

The first, most obvious route to take is chunking, but with the way I have things set up right now, implementing chunking would go against the framework of my program. Are there any other ways I can cut down the unnecessary draw calls per frame, or draw them in a more optimized way?

Thanks.

9
I didn't realize I had increased the scale of sf::Sprite, it was as simple as getting the position of sf::Sprite and adding the value of the sf::IntRect position multiplied by the scale, then the sf::Shape can also be sized up accordingly by getting the sf::IntRect dimensions, and once again, multiplying by scale.

10
Use the sprite (or any other sf::Transformable) transform

sprite.getTransform().transformRect()

The same works for inverse transforms

https://www.sfml-dev.org/tutorials/2.4/graphics-transform.php

I'm not sure I understand how I would apply this to my current situation?

For example:

sf::Sprite sprite;
sf::IntRect rect(3, 11, 3, 6);
sf::RectangleShape shape;

// I want shape to be in the same place as the textureRect (this is just for debugging):
sprite.setTextureRect(rect);

// How would I know where the above appears in world space? Ignoring the fact of textureRect affecting origin
shape.setPosition(??, ??);

// I can't put (3, 11), because shape isn't supposed to be relative to sprite!

 

11
Hello,

So, I have a simple problem (or at least it seems). Let's say I have a sf::Sprite, and a sf::IntRect. The sf::IntRect covers a certain region of the sf::Sprite, and is relative to the sf::Sprite, but that's in local space of the sf::Sprite, what would I do if I wanted to find out where this sf::IntRect was in global space? I think I'm missing something big here.

12
General / Re: linking sfml again again again
« on: April 25, 2017, 02:27:18 pm »

13
General / Re: Erasing AnimatedSprite from vector triggers crash
« on: April 25, 2017, 11:47:06 am »
Thank you for not just plainly posting the answer, but instead walking through the steps. However, this requires me to go through each time I reference enemies in main.cpp and change it to a unique_ptr. Also the .at() function now only accepts a size_t instead of an integer, but after reading upon unique_ptr, it seems very clever.

14
General / Re: Erasing AnimatedSprite from vector triggers crash
« on: April 25, 2017, 09:40:45 am »
I don't understand some of the keywords mentioned, but the only time I use the Animation, is to add frames, and set it as the animation for the AnimatedSprite. I'm not exactly sure what goes on in Animation.cpp/AnimatedSprite.cpp, but I think I have somewhat of an idea of what is going on.

15
General / Re: Erasing AnimatedSprite from vector triggers crash
« on: April 25, 2017, 07:12:39 am »
Enemy.h

class Enemy {
public:

        Enemy(sf::Texture &spritesheet) {
                enemy.setScale(2.5, 2.5);

                enemy.setFrameTime(sf::seconds(0.1));
                enemy.setLooped(true);

                moveAnimation.setSpriteSheet(spritesheet);
                moveAnimation.addFrame(sf::IntRect(0, 0, 32, 32));
                moveAnimation.addFrame(sf::IntRect(32, 0, 32, 32));
                moveAnimation.addFrame(sf::IntRect(64, 0, 32, 32));
               
                shouldDraw = true;

                health = 7;
        }

        void draw(sf::RenderWindow &window) {
                if (shouldDraw == true) {
                        window.draw(enemy);
                };
        }

        sf::Vector2f getPosition() {
                return enemy.getPosition();
        }

        void moveToPlayer(AnimatedSprite player, float speed, sf::Time frameTime) {
                sf::Vector2f direction = player.getPosition() - enemy.getPosition();
                float magnitude = sqrt((direction.x * direction.x) + (direction.y * direction.y));
                sf::Vector2f unitVector(direction.x / magnitude, direction.y / magnitude);

                enemy.move(unitVector * speed * frameTime.asSeconds());
        }

        void setColor(sf::Color color) {
                enemy.setColor(color);
        }

        void setHealth(int setHealth) {
                health = setHealth;
        }

        void update(sf::Time deltaTime, AnimatedSprite player, sf::Vector2f movement, gamemode &c, std::vector<Enemy> enemies) {
                if (shouldDraw == true) {
                        enemy.update(deltaTime);
                        enemy.play(moveAnimation);
                }
                else {};

                if (enemy.getGlobalBounds().contains(player.getPosition()) && shouldDraw == true) {
                        c = death;
                }
                else {
                       
                };

                if (health <= 0) {
                        enemy.stop();
                        shouldDraw = false;
                };
        }

        void stopAnimation() {
                enemy.stop();
        }

        sf::FloatRect getGlobalBounds() {
                return enemy.getGlobalBounds();
        }

        bool getShouldDraw() {
                return shouldDraw;
        }

        void minusHealth() {
                health--;
        }

        void setShouldDraw(bool sd) {
                shouldDraw = sd;
        }

        void setPosition(sf::Vector2f pos) {
                enemy.setPosition(pos);
        }

private:
        AnimatedSprite enemy;
        bool shouldDraw;
        int health;
        Animation moveAnimation;
};

Pages: [1] 2
anything