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.


Topics - ifinox

Pages: [1]
1
Graphics / sf::RenderTexture.clear() HUGE fps drop
« on: June 01, 2017, 10:33:41 pm »
Hello. I am coding simply roguelike and I have problem with sf::RenderTexture.
Normally I have around 600-700fps, but when I add rendertexture.clear() fps drops to 200-300fps!!
This happend despite the rendertexture size - even if i set rendertexture size to 5x5 ( create(5,5) ) or 1000x1000 there would be still 200-300fps.

Any idea how to solve that?

//edit

ThatCode:
visionMaskTexture.create(6, 6);
visionMaskTexture.clear();
visionMaskTexture.create(7, 6);
visionMaskTexture.clear();
visionMaskTexture.create(8, 6);
visionMaskTexture.clear();
make game unplayable(~10fps).
Why I have such fps drop with rendertexture?

2
Graphics / [Solved] Problem with changing size RenderTexture
« on: February 18, 2017, 10:23:41 am »
This is the code that reproduce the problem:
#include <vector>
#include <SFML/Graphics.hpp>

class UI : public sf::Drawable
{
        virtual void draw(sf::RenderTarget & target, sf::RenderStates states) const
        {
                target.draw(sprite);
        }
        sf::RenderTexture view;
        sf::Sprite sprite;
public:
        UI()
        {
        }
        void draw(const sf::Drawable & drawable)
        {
                view.draw(drawable);
        }
        void setSize(int x, int y)
        {
                view.create(x, y);
                view.clear();
        }
        void update(const std::vector<sf::RectangleShape>& squares)
        {
                for (int i = 0; i < squares.size(); i++)
                        view.draw(squares[i]);
                view.display();
                sprite.setTexture(view.getTexture());
        }
};
int main()
{
       
        sf::RectangleShape shape;
        shape.setSize(sf::Vector2f(20, 20));
        shape.setFillColor(sf::Color::White);

        int actualPosition = 0;
        std::vector <sf::RectangleShape> shapes;

        UI ui;
       
        for (int i = 0; i < 10; i++)
        {
                shape.setPosition(actualPosition, 0);
                shapes.push_back(shape);
                actualPosition += 21;
        }
        ui.setSize(21 * shapes.size(), 20);
        ui.update(shapes);

        sf::RenderWindow window(sf::VideoMode(21*shapes.size(), 20), "test");
        window.setFramerateLimit(20);
       
        while (window.isOpen())
        {
               
                sf::Event event;
                while (window.pollEvent(event))
                {
                        if (event.type == sf::Event::Closed)
                                window.close();
                        if (event.type == sf::Event::KeyReleased)
                        {
                                if (event.key.code == sf::Keyboard::Space)
                                {
                                        shape.setPosition(actualPosition, 0);
                                        shapes.push_back(shape);
                                        actualPosition += 21;
                                        ui.setSize(21 * shapes.size(), 20);
                                        ui.update(shapes);
                                       
                                }
                                if (event.key.code == sf::Keyboard::B)
                                {
                                        shapes.pop_back();
                                        actualPosition -= 21;
                                        ui.setSize(21 * shapes.size(), 20);
                                        ui.update(shapes);
                                }
                                window.create(sf::VideoMode(21 * shapes.size(), 20), "test");
                                window.setFramerateLimit(20);
                        }
                }

                window.clear();
                window.draw(ui);
                window.display();
        }

        return 0;
}
 


When we remove square from std::vector everything is good.
When we add square to std::vector everthing is good.
When we add another square that will be more than starting 10 (or any number defined before main program loop) squares, window will resize but RenderTarget will don't draw squares that is more than 10.


What am I doing wrong?

3
Window / How to check if both mouse button is pressed
« on: February 17, 2017, 12:58:15 pm »
Hello. I need to check if both lmb and rmb is pressed. How can i do that?

if (event.type == sf::Event::MouseButtonPressed)
{
        if (event.mouseButton.button == sf::Mouse::Left && event.mouseButton.button == sf::Mouse::Right)
                std::cout << "LMB+RMB\n";
        else if (event.mouseButton.button == sf::Mouse::Left)
                std::cout << "LMB\n";
        else if (event.mouseButton.button == sf::Mouse::Right)
                std::cout << "RMB\n";
}
 

That code I have now and it is obvious that not work, but how to do that properly?

4
Graphics / Weird behavior of shaders with variable index
« on: December 03, 2016, 06:20:45 pm »
Hello.
I am learning GLSL shaders and i wrote very simply light system.
When I want add all lights by using variable like this:
int var = 10;
gl_FragColor = light[0];
for(int i = 1; i<var; i++)
   gl_FragColor *= light[i]
I see graphics artifacts:


But when I  write indexes manually (i use vars because i want add lights in loop, not manually) like this:
gl_FragColor = light[0] * light[1];
Everything works fine:


Why I have artifacts?

Pages: [1]